londiste.global_add_table: automatically add table to combined node
authorMarko Kreen <markokr@gmail.com>
Fri, 25 Nov 2011 13:35:56 +0000 (15:35 +0200)
committerMarko Kreen <markokr@gmail.com>
Fri, 25 Nov 2011 13:35:56 +0000 (15:35 +0200)
sql/londiste/functions/londiste.global_add_table.sql
sql/londiste/functions/londiste.local_add_table.sql

index b3aebfc5946568fbcd1d8169d673c50b4616495d..388017c8da9fa4af695f8da9cce11a74bf0e260a 100644 (file)
@@ -23,12 +23,16 @@ as $$
 -- ----------------------------------------------------------------------
 declare
     fq_table_name text;
+    _cqueue text;
 begin
     fq_table_name := londiste.make_fqname(i_table_name);
 
-    perform 1 from pgq_node.node_info where queue_name = i_queue_name;
+    select combined_queue into _cqueue
+        from pgq_node.node_info
+        where queue_name = i_queue_name
+        for update;
     if not found then
-        select 400, 'No such set: ' || i_queue_name into ret_code, ret_note;
+        select 400, 'No such queue: ' || i_queue_name into ret_code, ret_note;
         return;
     end if;
 
@@ -42,8 +46,13 @@ begin
         values (i_queue_name, fq_table_name);
     select 200, 'Table added: ' || i_table_name
         into ret_code, ret_note;
-    return;
 
+    -- let the combined node know about it too
+    if _cqueue is not null then
+        perform londiste.global_add_table(_cqueue, i_table_name);
+    end if;
+
+    return;
 exception
     -- seems the row was added from parallel connection (setup vs. replay)
     when unique_violation then
index f69ca568c6782cb4655c0e679b6d6335d738fea6..27a7c54473f9772c5915a06d90b1a8e0c4965671 100644 (file)
@@ -298,7 +298,7 @@ begin
             join pgq_node.node_info n2
                 on (n2.queue_name = n1.combined_queue)
             left join londiste.table_info t
-                on (t.queue_name = n2.queue_name and t.table_name = fq_table_name)
+                on (t.queue_name = n2.queue_name and t.table_name = fq_table_name and t.local)
             where n1.queue_name = i_queue_name and n2.node_type = 'root'
             into _combined_queue, _combined_table;
         if found and _combined_table is null then