no-merge argument
authorEgon Valdmees <egon.valdmees@skype.net>
Tue, 19 Jul 2011 10:32:34 +0000 (13:32 +0300)
committerEgon Valdmees <egon.valdmees@skype.net>
Sun, 7 Aug 2011 18:50:11 +0000 (18:50 +0000)
when using it table is not merged from source queues

python/londiste.py
python/londiste/setup.py
sql/londiste/functions/londiste.get_table_list.sql
sql/londiste/functions/londiste.local_add_table.sql

index bd456137a3cf760885d77f1599cfdde0eb0d5df7..778b9f78b28858c8ea48f166642be55ed2015e39 100755 (executable)
@@ -130,6 +130,8 @@ class Londiste(skytools.DBScript):
                 help = "add: set WHERE expression for copy")
         g.add_option("--merge-all", action="store_true",
                 help="merge tables from all source queues", default=False)
+        g.add_option("--no-merge", action="store_true",
+                help="don't merge tables from source queues", default=False)
 
         p.add_option_group(g)
 
index e9ef4102368876aa6a0a4c4506e856c2259aecce..d7423406033050be9ad9923a5996e0ea0814cc3f 100644 (file)
@@ -67,6 +67,8 @@ class LondisteSetup(CascadeAdmin):
                     help="add: Argument to custom handler")
         p.add_option("--merge-all", action="store_true",
                     help="merge tables from all source queues", default=False)
+        p.add_option("--no-merge", action="store_true",
+                    help="don't merge tables from source queues", default=False)
         return p
 
     def extra_init(self, node_type, node_db, provider_db):
@@ -167,6 +169,8 @@ class LondisteSetup(CascadeAdmin):
             tgargs.append('no_triggers')
         if self.options.merge_all:
             tgargs.append('merge_all')
+        if self.options.no_merge:
+            tgargs.append('no_merge')
 
         attrs = {}
         if self.options.handler:
index bc031ccec5ba46a1784ca19952d3a4d36ca5ee1b..2f526eebfce6e0c8f27b6dbae94b9e1fb1ade392 100644 (file)
@@ -52,7 +52,8 @@ begin
             join pgq_node.node_info n on (n.queue_name = t.queue_name)
             left join pgq_node.node_info n2 on (n2.combined_queue = n.combined_queue or
                 (n2.combined_queue is null and n.combined_queue is null))
-            left join londiste.table_info t2 on (t2.table_name = t.table_name and t2.queue_name = n2.queue_name)
+            left join londiste.table_info t2 on (t2.table_name = t.table_name and
+                t2.queue_name = n2.queue_name and (t2.merge_state is null or t2.merge_state != 'ok'))
             where t.queue_name = i_queue_name
             group by t.nr, t.table_name, t.local, t.merge_state, t.custom_snapshot, t.table_attrs, t.dropped_ddl
             order by t.nr, t.table_name
index ba3e31c5269a0abfa9e79a9d7c8f0c936243a17e..3bfcfebfc048cf449150f7a2170beef708b7264f 100644 (file)
@@ -23,8 +23,9 @@ as $$
 --      skip_truncate   - set 'skip_truncate' table attribute
 --      expect_sync     - set table state to 'ok'
 --      tgflags=X       - trigger creation flags
---      merge_all       - merge table from all sources. required for 
+--      merge_all       - merge table from all sources. required for
 --                        multi-source table
+--      no_merge        - do not merge tables from different sources
 --      skip            - create skip trigger. same as S flag
 --      virtual_table   - skips structure check and trigger creation
 --
@@ -82,6 +83,7 @@ declare
     -- argument flags
     _expect_sync boolean := false;
     _merge_all boolean := false;
+    _no_merge boolean := false;
     _skip_truncate boolean := false;
     _no_triggers boolean := false;
     _skip boolean := false;
@@ -109,6 +111,8 @@ begin
                 _no_triggers := true;
             elsif arg = 'merge_all' then
                 _merge_all = true;
+            elsif arg = 'no_merge' then
+                _no_merge = true;
             elsif lower(arg) = 'skip' then
                 _skip := true;
             elsif arg = 'virtual_table' then
@@ -122,6 +126,12 @@ begin
         end loop;
     end if;
 
+    if _merge_all and _no_merge then
+        select 405, 'Cannot use merge-all and no-merge together'
+        into ret_code, ret_note;
+        return;
+    end if;
+
     fq_table_name := londiste.make_fqname(i_table_name);
 
     -------- TABLE STRUCTURE CHECK
@@ -208,7 +218,7 @@ begin
     end if;
 
     -- merge all table sources on leaf
-    if _node.node_type = 'leaf' then
+    if _node.node_type = 'leaf' and not _no_merge then
         for _queue_name, _local in
             select t2.queue_name, t2.local
             from londiste.table_info t
@@ -223,7 +233,7 @@ begin
             -- if table from some other source is already marked as local,
             -- raise error
             if _local then
-                select 406, 'found local table '|| fq_table_name
+                select 405, 'Found local table '|| fq_table_name
                         || ' in queue ' || _queue_name
                         || ', use remove-table first to remove all previous '
                         || 'table subscriptions'
@@ -231,14 +241,14 @@ begin
                 return;
             end if;
 
-            -- when table comes from multiple sources, merge_all switch is
-            -- required
-            if not _merge_all then
-                select 405, 'multiple source tables '|| fq_table_name
-                        || ' found, use merge_all'
-                into ret_code, ret_note;
-                return;
-            end if;
+           -- when table comes from multiple sources, merge_all switch is
+           -- required
+           if not _merge_all then
+               select 405, 'Found multiple sources for table '|| fq_table_name
+                       || ', use merge-all or no-merge to continue'
+               into ret_code, ret_note;
+               return;
+           end if;
 
             update londiste.table_info
                set local = true,