summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Kreen2010-10-13 13:58:53 +0000
committerMarko Kreen2010-10-13 13:58:53 +0000
commitee48978f8e7396f8587855d75bd7610ea3fbb322 (patch)
tree89301c64571eee99607b24275c711082c77ca8d5
parent988e351c8cda62608a74d837166c977185297bf7 (diff)
londiste: trigger-cleanup trigger on londiste.table_info
-rw-r--r--sql/londiste/Makefile2
-rw-r--r--sql/londiste/expected/londiste_provider.out13
-rw-r--r--sql/londiste/functions/londiste.drop_table_triggers.sql39
-rw-r--r--sql/londiste/functions/londiste.local_remove_table.sql18
-rw-r--r--sql/londiste/functions/londiste.table_info_trigger.sql17
-rw-r--r--sql/londiste/sql/londiste_install.sql4
-rw-r--r--sql/londiste/sql/londiste_provider.sql3
-rw-r--r--sql/londiste/structure/functions.sql2
-rw-r--r--sql/londiste/structure/triggers.sql4
9 files changed, 81 insertions, 21 deletions
diff --git a/sql/londiste/Makefile b/sql/londiste/Makefile
index 5295e10d..6d6d0c03 100644
--- a/sql/londiste/Makefile
+++ b/sql/londiste/Makefile
@@ -1,7 +1,7 @@
DATA_built = londiste.sql londiste.upgrade.sql
-SQLS = structure/tables.sql structure/grants.sql structure/functions.sql
+SQLS = structure/tables.sql structure/grants.sql structure/functions.sql structure/triggers.sql
FUNCS = $(shell sed -e 's/^[^\\].*//' -e 's/\\i //' $(SQLS))
SRCS = $(SQLS) $(FUNCS)
diff --git a/sql/londiste/expected/londiste_provider.out b/sql/londiste/expected/londiste_provider.out
index 877618dd..46eea29a 100644
--- a/sql/londiste/expected/londiste_provider.out
+++ b/sql/londiste/expected/londiste_provider.out
@@ -122,3 +122,16 @@ select ev_id, ev_type, ev_data, ev_extra1, ev_extra4 from pgq.event_template whe
6 | R | | public.trg_test |
(2 rows)
+select tgname from pg_trigger where tgrelid = 'public.trg_test'::regclass order by 1;
+ tgname
+-------------------------
+ _londiste_aset
+ _londiste_aset_truncate
+(2 rows)
+
+delete from londiste.table_info where table_name = 'public.trg_test';
+select tgname from pg_trigger where tgrelid = 'public.trg_test'::regclass order by 1;
+ tgname
+--------
+(0 rows)
+
diff --git a/sql/londiste/functions/londiste.drop_table_triggers.sql b/sql/londiste/functions/londiste.drop_table_triggers.sql
new file mode 100644
index 00000000..2ab0c9c6
--- /dev/null
+++ b/sql/londiste/functions/londiste.drop_table_triggers.sql
@@ -0,0 +1,39 @@
+
+create or replace function londiste.drop_table_triggers(
+ in i_queue_name text, in i_table_name text)
+returns void as $$
+-- ----------------------------------------------------------------------
+-- Function: londiste.drop_table_triggers(2)
+--
+-- Remove Londiste triggers from table.
+--
+-- Parameters:
+-- i_queue_name - set name
+-- i_table_name - table name
+--
+-- Returns:
+-- 200 - OK
+-- 404 - Table not found
+-- ----------------------------------------------------------------------
+declare
+ logtrg_name text;
+ b_queue_name bytea;
+begin
+ -- cast to bytea
+ b_queue_name := replace(i_queue_name, E'\\', E'\\\\')::bytea;
+
+ -- drop all replication triggers that target our queue.
+ -- by checking trigger func and queue name there is not
+ -- dependency on naming standard or side-storage.
+ for logtrg_name in
+ select tgname from pg_catalog.pg_trigger
+ where tgrelid = londiste.find_table_oid(i_table_name)
+ and tgfoid in ('pgq.sqltriga'::regproc::oid, 'pgq.logutriga'::regproc::oid)
+ and substring(tgargs for (position(E'\\000'::bytea in tgargs) - 1)) = b_queue_name
+ loop
+ execute 'drop trigger ' || quote_ident(logtrg_name)
+ || ' on ' || londiste.quote_fqname(i_table_name);
+ end loop;
+end;
+$$ language plpgsql strict;
+
diff --git a/sql/londiste/functions/londiste.local_remove_table.sql b/sql/londiste/functions/londiste.local_remove_table.sql
index d70dceda..097e0b6f 100644
--- a/sql/londiste/functions/londiste.local_remove_table.sql
+++ b/sql/londiste/functions/londiste.local_remove_table.sql
@@ -18,9 +18,7 @@ as $$
-- ----------------------------------------------------------------------
declare
fq_table_name text;
- logtrg_name text;
tbl record;
- b_queue_name bytea;
begin
fq_table_name := londiste.make_fqname(i_table_name);
@@ -34,21 +32,7 @@ begin
end if;
if tbl.local then
- -- cast to bytea
- b_queue_name := replace(i_queue_name, E'\\', E'\\\\')::bytea;
-
- -- drop all replication triggers that target our queue.
- -- by checking trigger func and queue name there is not
- -- dependency on naming standard or side-storage.
- for logtrg_name in
- select tgname from pg_catalog.pg_trigger
- where tgrelid = londiste.find_table_oid(fq_table_name)
- and tgfoid in ('pgq.sqltriga'::regproc::oid, 'pgq.logutriga'::regproc::oid)
- and substring(tgargs for (position(E'\\000'::bytea in tgargs) - 1)) = b_queue_name
- loop
- execute 'drop trigger ' || quote_ident(logtrg_name)
- || ' on ' || londiste.quote_fqname(fq_table_name);
- end loop;
+ perform londiste.drop_table_triggers(i_queue_name, fq_table_name);
-- reset data
update londiste.table_info
diff --git a/sql/londiste/functions/londiste.table_info_trigger.sql b/sql/londiste/functions/londiste.table_info_trigger.sql
new file mode 100644
index 00000000..1a225209
--- /dev/null
+++ b/sql/londiste/functions/londiste.table_info_trigger.sql
@@ -0,0 +1,17 @@
+
+create or replace function londiste.table_info_trigger()
+returns trigger as $$
+-- ----------------------------------------------------------------------
+-- Function: londiste.table_info_trigger(0)
+--
+-- Trigger on londiste.table_info. Cleans triggers from tables
+-- when table is removed from londiste.table_info.
+-- ----------------------------------------------------------------------
+begin
+ if TG_OP = 'DELETE' then
+ perform londiste.drop_table_triggers(OLD.queue_name, OLD.table_name);
+ end if;
+ return null;
+end;
+$$ language plpgsql;
+
diff --git a/sql/londiste/sql/londiste_install.sql b/sql/londiste/sql/londiste_install.sql
index e88c50ac..3621a393 100644
--- a/sql/londiste/sql/londiste_install.sql
+++ b/sql/londiste/sql/londiste_install.sql
@@ -10,9 +10,7 @@ create language plpgsql;
\i ../pgq/pgq.sql
\i ../pgq_node/pgq_node.sql
--- install directly from source files
-\i structure/tables.sql
-\i structure/functions.sql
+\i londiste.sql
\set ECHO all
diff --git a/sql/londiste/sql/londiste_provider.sql b/sql/londiste/sql/londiste_provider.sql
index 63a62f84..2209f8b6 100644
--- a/sql/londiste/sql/londiste_provider.sql
+++ b/sql/londiste/sql/londiste_provider.sql
@@ -45,4 +45,7 @@ insert into trg_test values (1, 'data');
truncate trg_test;
select ev_id, ev_type, ev_data, ev_extra1, ev_extra4 from pgq.event_template where ev_extra1 = 'public.trg_test';
+select tgname from pg_trigger where tgrelid = 'public.trg_test'::regclass order by 1;
+delete from londiste.table_info where table_name = 'public.trg_test';
+select tgname from pg_trigger where tgrelid = 'public.trg_test'::regclass order by 1;
diff --git a/sql/londiste/structure/functions.sql b/sql/londiste/structure/functions.sql
index 2914721e..a8320f09 100644
--- a/sql/londiste/structure/functions.sql
+++ b/sql/londiste/structure/functions.sql
@@ -38,4 +38,6 @@
\i functions/londiste.quote_fqname.sql
\i functions/londiste.make_fqname.sql
\i functions/londiste.split_fqname.sql
+\i functions/londiste.table_info_trigger.sql
+\i functions/londiste.drop_table_triggers.sql
diff --git a/sql/londiste/structure/triggers.sql b/sql/londiste/structure/triggers.sql
new file mode 100644
index 00000000..ad75359d
--- /dev/null
+++ b/sql/londiste/structure/triggers.sql
@@ -0,0 +1,4 @@
+
+create trigger table_info_trigger_sync after delete on londiste.table_info
+for each row execute procedure londiste.table_info_trigger();
+