From a6824291a1b4c13fe880953fd963ef485d071149 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Fri, 11 Apr 2008 13:41:34 +0000 Subject: [PATCH] send events --- sql/londiste/expected/londiste_provider.out | 2 +- .../functions/londiste.node_add_table.sql | 10 +++++-- .../functions/londiste.node_notify_change.sql | 19 ------------- .../functions/londiste.node_remove_table.sql | 7 +++-- .../functions/londiste.root_notify_change.sql | 28 +++++++++++++++++++ sql/londiste/structure/functions.sql | 2 +- 6 files changed, 42 insertions(+), 26 deletions(-) delete mode 100644 sql/londiste/functions/londiste.node_notify_change.sql create mode 100644 sql/londiste/functions/londiste.root_notify_change.sql diff --git a/sql/londiste/expected/londiste_provider.out b/sql/londiste/expected/londiste_provider.out index 2fe6c83b..7829fa7d 100644 --- a/sql/londiste/expected/londiste_provider.out +++ b/sql/londiste/expected/londiste_provider.out @@ -44,7 +44,7 @@ select * from londiste.node_add_table('aset', 'public.testdata'); select * from londiste.node_get_table_list('aset'); table_name | merge_state | custom_snapshot | skip_truncate -----------------+-------------+-----------------+--------------- - public.testdata | | | + public.testdata | ok | | (1 row) select * from londiste.node_remove_table('aset', 'public.testdata'); diff --git a/sql/londiste/functions/londiste.node_add_table.sql b/sql/londiste/functions/londiste.node_add_table.sql index d3b3d82f..a2cebe05 100644 --- a/sql/londiste/functions/londiste.node_add_table.sql +++ b/sql/londiste/functions/londiste.node_add_table.sql @@ -5,7 +5,7 @@ create or replace function londiste.node_add_table( out ret_desc text) as $$ -- ---------------------------------------------------------------------- --- Function: londiste.node_add_table(x) +-- Function: londiste.node_add_table(2) -- -- Register table on Londiste node. -- @@ -16,6 +16,7 @@ as $$ declare col_types text; fq_table_name text; + new_state text; begin fq_table_name := londiste.make_fqname(i_table_name); col_types := londiste.find_column_types(fq_table_name); @@ -42,16 +43,19 @@ begin if ret_code <> 200 then return; end if; + new_state := 'ok'; + perform londiste.root_notify_change(i_set_name, 'add-table', fq_table_name); else perform 1 from londiste.set_table where set_name = i_set_name and table_name = fq_table_name; if not found then select 400, 'Table not registered in set: ' || fq_table_name into ret_code, ret_desc; return; end if; + new_state := NULL; end if; - insert into londiste.node_table (set_name, table_name) - values (i_set_name, fq_table_name); + insert into londiste.node_table (set_name, table_name, merge_state) + values (i_set_name, fq_table_name, new_state); for ret_code, ret_desc in select f.ret_code, f.ret_desc diff --git a/sql/londiste/functions/londiste.node_notify_change.sql b/sql/londiste/functions/londiste.node_notify_change.sql deleted file mode 100644 index 85df7d3b..00000000 --- a/sql/londiste/functions/londiste.node_notify_change.sql +++ /dev/null @@ -1,19 +0,0 @@ - -create or replace function londiste.node_send_event(i_set_name text, i_ev_type text, i_ev_data text) -returns integer as $$ -declare - que text; -begin - select s.queue_name into que - from pgq_set s - where s.set_name = i_set_name; - if not found then - raise exception 'Unknown set: %', i_set_name; - end if; - - perform pgq.insert_event(que, i_ev_data, i_ev_data); - - return 1; -end; -$$ language plpgsql; - diff --git a/sql/londiste/functions/londiste.node_remove_table.sql b/sql/londiste/functions/londiste.node_remove_table.sql index b4875b12..93b7d21b 100644 --- a/sql/londiste/functions/londiste.node_remove_table.sql +++ b/sql/londiste/functions/londiste.node_remove_table.sql @@ -26,8 +26,11 @@ begin return; end if; - -- perform londiste.provider_notify_change(i_queue_name); - -- triggers + if pgq_set.is_root(i_set_name) then + perform londiste.set_remove_table(i_set_name, fq_table_name); + perform londiste.root_notify_change(i_set_name, 'remove-table', fq_table_name); + end if; + select 200, 'Table removed: ' || fq_table_name into ret_code, ret_desc; return; end; diff --git a/sql/londiste/functions/londiste.root_notify_change.sql b/sql/londiste/functions/londiste.root_notify_change.sql new file mode 100644 index 00000000..0f79cc22 --- /dev/null +++ b/sql/londiste/functions/londiste.root_notify_change.sql @@ -0,0 +1,28 @@ + +create or replace function londiste.root_notify_change(i_set_name text, i_ev_type text, i_ev_data text) +returns integer as $$ +-- ---------------------------------------------------------------------- +-- Function: londiste.root_notify_change(3) +-- +-- Send event about change in root downstream. +-- ---------------------------------------------------------------------- +declare + que text; + ntype text; +begin + select s.queue_name, s.node_type into que, ntype + from pgq_set.set_info s + where s.set_name = i_set_name; + if not found then + raise exception 'Unknown set: %', i_set_name; + end if; + if ntype <> 'root' then + raise exception 'only root node can send events'; + end if; + + perform pgq.insert_event(que, i_ev_data, i_ev_data); + + return 1; +end; +$$ language plpgsql; + diff --git a/sql/londiste/structure/functions.sql b/sql/londiste/structure/functions.sql index bb2d8bb0..e40330ad 100644 --- a/sql/londiste/structure/functions.sql +++ b/sql/londiste/structure/functions.sql @@ -24,7 +24,7 @@ \i functions/londiste.node_prepare_triggers.sql \i functions/londiste.node_refresh_triggers.sql \i functions/londiste.node_disable_triggers.sql --- \i functions/londiste.node_notify_change.sql +\i functions/londiste.root_notify_change.sql -- Group: Utility functions \i functions/londiste.find_column_types.sql -- 2.39.5