summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartinko2012-12-18 14:55:10 +0000
committermartinko2012-12-18 14:55:10 +0000
commit21d3b39d371f2956a3cfa234bf73980503df4d97 (patch)
treea59c6be9f3a8f81e3b626e6526ccd803c9762400
parent364ade97bc8be670dd0c506fbd723e2bf0ad5b97 (diff)
post merge clean up
-rw-r--r--python/a0
-rw-r--r--python/londiste/setup.py13
-rw-r--r--sql/londiste/functions/londiste.create_trigger.sql25
-rw-r--r--sql/londiste/functions/londiste.local_add_table.sql12
-rw-r--r--sql/londiste/functions/londiste.local_change_handler.sql34
5 files changed, 33 insertions, 51 deletions
diff --git a/python/a b/python/a
deleted file mode 100644
index e69de29b..00000000
--- a/python/a
+++ /dev/null
diff --git a/python/londiste/setup.py b/python/londiste/setup.py
index 0df9c9db..0cc4401e 100644
--- a/python/londiste/setup.py
+++ b/python/londiste/setup.py
@@ -78,7 +78,6 @@ class LondisteSetup(CascadeAdmin):
help="max number of parallel copy processes")
p.add_option("--dest-table",
help="add: name for actual table")
-
return p
def extra_init(self, node_type, node_db, provider_db):
@@ -173,7 +172,6 @@ class LondisteSetup(CascadeAdmin):
if self.options.wait_sync:
self.wait_for_sync(dst_db)
-
def add_table(self, src_db, dst_db, tbl, create_flags, src_tbls):
# use full names
tbl = skytools.fq_name(tbl)
@@ -256,13 +254,12 @@ class LondisteSetup(CascadeAdmin):
tgargs.append('no_merge')
if self.options.expect_sync:
tgargs.append('expect_sync')
-
return tgargs
def build_handler(self, tbl, tgargs, dest_table=None):
- """Build handler and push int into tgargs"""
+ """Build handler and return handler string"""
hstr = londiste.handler.create_handler_string(
- self.options.handler, self.options.handler_arg)
+ self.options.handler, self.options.handler_arg)
p = londiste.handler.build_handler(tbl, hstr, dest_table)
p.add(tgargs)
return hstr
@@ -307,7 +304,7 @@ class LondisteSetup(CascadeAdmin):
self.exec_cmd_many(db, q, [self.set_name], args)
def cmd_change_handler(self, tbl):
- """Change handler (table_attrs) of the replicated table"""
+ """Change handler (table_attrs) of the replicated table."""
self.load_local_info()
@@ -350,7 +347,6 @@ class LondisteSetup(CascadeAdmin):
self.exec_cmd(curs, q, args)
db.commit()
-
def cmd_add_seq(self, *args):
"""Attach seqs(s) to local node."""
dst_db = self.get_database('db')
@@ -434,7 +430,7 @@ class LondisteSetup(CascadeAdmin):
self.exec_cmd_many(db, q, [self.set_name], args)
def cmd_resync(self, *args):
- """Reload data from provider node.."""
+ """Reload data from provider node."""
db = self.get_database('db')
args = self.expand_arg_list(db, 'r', True, args)
q = "select * from londiste.local_set_table_state(%s, %s, null, null)"
@@ -720,4 +716,3 @@ class LondisteSetup(CascadeAdmin):
tinfo[2] += 1
if not bak and ev.ev_type == 'D':
tinfo[3] = NO_ROLLBACK
-
diff --git a/sql/londiste/functions/londiste.create_trigger.sql b/sql/londiste/functions/londiste.create_trigger.sql
index c888cedd..affa69c7 100644
--- a/sql/londiste/functions/londiste.create_trigger.sql
+++ b/sql/londiste/functions/londiste.create_trigger.sql
@@ -10,19 +10,19 @@ create or replace function londiste.create_trigger(
as $$
------------------------------------------------------------------------
-- Function: londiste.create_trigger(5)
---
+--
-- Create or replace londiste trigger(s)
---
+--
-- Parameters:
-- i_queue_name - queue name
-- i_table_name - table name
-- i_trg_args - args to trigger
-- i_dest_table - actual name of destination table (NULL if same as src)
-- i_node_type - l3 node type
---
+--
-- Trigger args:
-- See documentation for pgq triggers.
---
+--
-- Trigger creation flags (default: AIUDL):
-- I - ON INSERT
-- U - ON UPDATE
@@ -32,12 +32,12 @@ as $$
-- B - BEFORE
-- A - AFTER
-- S - SKIP
---
+--
-- Returns:
-- 200 - Ok
-- 201 - Trigger not created
-- 405 - Multiple SKIP triggers
---
+--
------------------------------------------------------------------------
declare
trigger_name text;
@@ -53,6 +53,7 @@ declare
arg text;
i integer;
_extra_args text[] := '{}';
+ -- skip trigger
_skip_prefix text := 'zzz_';
_skip_trg_count integer;
_skip_trg_name text;
@@ -67,6 +68,7 @@ declare
_no_triggers boolean := false;
_got_extra1 boolean := false;
begin
+ -- parse trigger args
if array_lower(i_trg_args, 1) is not null then
for i in array_lower(i_trg_args, 1) .. array_upper(i_trg_args, 1) loop
arg := i_trg_args[i];
@@ -100,7 +102,7 @@ begin
arg := 'ev_extra1=' || quote_literal(i_table_name);
_args := array_append(_args, quote_literal(arg));
end if;
-
+
trigger_name := '_londiste_' || i_queue_name;
lg_func := 'pgq.logutriga';
lg_event := '';
@@ -178,7 +180,7 @@ begin
end if;
-- create Ins/Upd/Del trigger if it does not exists already
- select t.tgargs
+ select t.tgargs
from pg_catalog.pg_trigger t
where t.tgrelid = londiste.find_table_oid(i_dest_table)
and t.tgname = trigger_name
@@ -190,14 +192,14 @@ begin
_new_tgargs := _new_tgargs || E'\\000'::bytea || decode(lg_args[i], 'escape');
end loop;
- if _old_tgargs IS DISTINCT FROM _new_tgargs then
+ if _old_tgargs is distinct from _new_tgargs then
sql := 'drop trigger if exists ' || quote_ident(trigger_name)
|| ' on ' || londiste.quote_fqname(i_dest_table);
execute sql;
end if;
end if;
- if not found or _old_tgargs IS DISTINCT FROM _new_tgargs then
+ if not found or _old_tgargs is distinct from _new_tgargs then
if _no_triggers then
select 201, 'Trigger not created'
into ret_code, ret_note;
@@ -205,7 +207,7 @@ begin
end if;
-- finalize event
- lg_event := substr(lg_event, 4);
+ lg_event := substr(lg_event, 4); -- remove ' or '
if lg_event = '' then
lg_event := 'insert or update or delete';
end if;
@@ -242,4 +244,3 @@ begin
return;
end;
$$ language plpgsql;
-
diff --git a/sql/londiste/functions/londiste.local_add_table.sql b/sql/londiste/functions/londiste.local_add_table.sql
index ea8f1edf..1ca34193 100644
--- a/sql/londiste/functions/londiste.local_add_table.sql
+++ b/sql/londiste/functions/londiste.local_add_table.sql
@@ -68,7 +68,6 @@ declare
_combined_queue text;
_combined_table text;
_table_attrs text := i_table_attrs;
- -- skip trigger
-- check local tables from all sources
_queue_name text;
_local boolean;
@@ -177,7 +176,7 @@ begin
end if;
if tbl.local then
- if tbl.table_attrs IS DISTINCT FROM _table_attrs then
+ if tbl.table_attrs is distinct from _table_attrs then
select 410, 'Table ' || _desc || ' already added, but with different args: ' || coalesce(tbl.table_attrs, '') into ret_code, ret_note;
else
select 200, 'Table already added: ' || _desc into ret_code, ret_note;
@@ -285,13 +284,10 @@ begin
return;
end if;
-
-- Check that no trigger exists on the target table that will get fired
- -- before londiste one (this could have londiste replicate data
- -- out-of-order
+ -- before londiste one (this could have londiste replicate data out-of-order)
--
- -- Don't report all the trigger names, 8.3 does not have array_accum
- -- available
+ -- Don't report all the trigger names, 8.3 does not have array_accum available.
show server_version_num into pgversion;
if pgversion >= 90000 then
@@ -394,5 +390,3 @@ begin
return;
end;
$$ language plpgsql strict;
-
-
diff --git a/sql/londiste/functions/londiste.local_change_handler.sql b/sql/londiste/functions/londiste.local_change_handler.sql
index bdffd2d0..5bb27c84 100644
--- a/sql/londiste/functions/londiste.local_change_handler.sql
+++ b/sql/londiste/functions/londiste.local_change_handler.sql
@@ -2,13 +2,13 @@ create or replace function londiste.local_change_handler(
in i_queue_name text,
in i_table_name text,
in i_trg_args text[],
- in i_table_attrs text,
+ in i_table_attrs text,
out ret_code int4,
out ret_note text)
as $$
----------------------------------------------------------------------------------------------------
-- Function: londiste.local_change_handler(4)
---
+--
-- Change handler and rebuild trigger if needed
--
-- Parameters:
@@ -16,12 +16,12 @@ as $$
-- i_table_name - table name
-- i_trg_args - args to trigger
-- i_table_attrs - args to python handler
---
+--
-- Returns:
-- 200 - OK
-- 400 - No such set
-- 404 - Table not found
---
+--
----------------------------------------------------------------------------------------------------
declare
_dest_table text;
@@ -34,29 +34,23 @@ begin
select 400, 'No such set: ' || i_queue_name into ret_code, ret_note;
return;
end if;
-
- -- get destination table name for use in trigger creation
- select coalesce(ti.dest_table, i_table_name)
- from londiste.table_info ti
- where queue_name = i_queue_name
- and table_name = i_table_name
- and local
- into _dest_table;
-
- if not found then
- select 404, 'no such local table: ' || i_table_name
- into ret_code, ret_note;
- end if;
-- update table_attrs with new handler info
select f.ret_code, f.ret_note
from londiste.local_set_table_attrs(i_queue_name, i_table_name, i_table_attrs) f
into ret_code, ret_note;
-
if ret_code <> 200 then
return;
end if;
+ -- get destination table name for use in trigger creation
+ select coalesce(ti.dest_table, i_table_name)
+ from londiste.table_info ti
+ where queue_name = i_queue_name
+ and table_name = i_table_name
+ and local
+ into _dest_table;
+
-- replace the trigger if needed
select f.ret_code, f.ret_note
from londiste.create_trigger(i_queue_name, i_table_name, i_trg_args, _dest_table, _node.node_type) f
@@ -67,7 +61,7 @@ begin
else
_desc := i_table_name || '(' || _dest_table || ')';
end if;
-
+
if ret_code > 299 then
ret_note := 'Trigger creation failed for table ' || _desc || ': ' || ret_note;
return;
@@ -79,8 +73,6 @@ begin
select 200, 'Handler changed for table: ' || _desc
into ret_code, ret_note;
-
return;
end;
$$ language plpgsql;
-