bug 313 - don't error out in applying EXECUTE SCRIPT sequence updates
authorSteve Singer <ssinger@ca.afilias.info>
Wed, 4 Sep 2013 19:53:31 +0000 (15:53 -0400)
committerSteve Singer <ssinger@ca.afilias.info>
Wed, 4 Sep 2013 19:53:31 +0000 (15:53 -0400)
Since bug 304 was fixed we have been including the list of replicated
sequences and current values in the arguments on sl_log_script rows.
If some sequences are replicated to some nodes but not others then the
execute script will fail to apply on the nodes that don't have those
sequences.

This patch ignores missing sequences during an execute script
instead of erroring out.

src/backend/slony1_funcs.c
src/backend/slony1_funcs.sql
src/slon/remote_worker.c

index 5b28790158c0f1b1ac54f9c2261873896a8de5b6..506b6f90ec5d3b64fd294c5d437e972f5ba6a3c5 100644 (file)
@@ -1091,7 +1091,7 @@ versionFunc(logApply)(PG_FUNCTION_ARGS)
                        argtypes[2] = INT8OID;
 
                        snprintf(query,1023,"select %s.sequenceSetValue($1,"    \
-                                        "$2,NULL,$3); ",tg->tg_trigger->tgargs[0]);                    
+                                        "$2,NULL,$3,true); ",tg->tg_trigger->tgargs[0]);                       
                        plan = SPI_prepare(query,3,argtypes);
                        if ( plan == NULL )
                        {
index 68a010752964d90e3fec6b18ab36e3be0da67903..5b3c4b4750d3e1b6db8c4187052c0e95ad54670d 100644 (file)
@@ -3355,11 +3355,13 @@ set.';
 -- ----------------------------------------------------------------------
 -- FUNCTION sequenceSetValue (seq_id, seq_origin, ev_seqno, last_value)
 -- ----------------------------------------------------------------------
-create or replace function @NAMESPACE@.sequenceSetValue(p_seq_id int4, p_seq_origin int4, p_ev_seqno int8, p_last_value int8) returns int4
+create or replace function @NAMESPACE@.sequenceSetValue(p_seq_id int4, p_seq_origin int4, p_ev_seqno int8, p_last_value int8,p_ignore_missing bool) returns int4
 as $$
 declare
        v_fqname                        text;
+       v_found                         integer;
 begin
+
        -- ----
        -- Get the sequences fully qualified name
        -- ----
@@ -3371,6 +3373,9 @@ begin
                        and SQ.seq_reloid = PGC.oid
                        and PGC.relnamespace = PGN.oid;
        if not found then
+               if p_ignore_missing then
+                       return null;
+                end if;
                raise exception 'Slony-I: sequenceSetValue(): sequence % not found', p_seq_id;
        end if;
 
@@ -3388,8 +3393,8 @@ begin
        return p_seq_id;
 end;
 $$ language plpgsql;
-comment on function @NAMESPACE@.sequenceSetValue(p_seq_id int4, p_seq_origin int4, p_ev_seqno int8, p_last_value int8) is
-'sequenceSetValue (seq_id, seq_origin, ev_seqno, last_value)
+comment on function @NAMESPACE@.sequenceSetValue(p_seq_id int4, p_seq_origin int4, p_ev_seqno int8, p_last_value int8,p_ignore_missing bool) is
+'sequenceSetValue (seq_id, seq_origin, ev_seqno, last_value,ignore_missing)
 Set sequence seq_id to have new value last_value.
 ';
 
index 3ba86e5df0ae186f2f673a3cc8c73c9df9e44e1f..6f9abba88ddbbbce9574742b535c2fee8c8391e8 100644 (file)
@@ -4377,7 +4377,7 @@ sync_event(SlonNode * node, SlonConn * local_conn,
                        char       *seq_relname = PQgetvalue(res1, tupno1, 3);
 
                        (void) slon_mkquery(&query,
-                                                        "select %s.sequenceSetValue(%s,%d,'%s','%s'); ",
+                                                        "select %s.sequenceSetValue(%s,%d,'%s','%s',false); ",
                                                                rtcfg_namespace,
                                                   seql_seqid, node->no_id, seqbuf, seql_last_value);
                        start_monitored_event(&pm);