From 2c2da13a5474a789f5a3912eac2f5386a93277af Mon Sep 17 00:00:00 2001 From: Steve Singer Date: Tue, 8 Nov 2011 13:11:37 -0500 Subject: [PATCH] Bug 248 Stop tracking the sequence name on log shipping targets. Instead include the sequence name in the log shipping files on sequence updates. This avoids the issue of us not adding new tracking table entries on an enable subscription. --- clustertest/disorder/tests/LogShipping.js | 6 +++ src/slon/remote_worker.c | 9 +++-- src/slony_logshipper/parser.y | 10 +++--- tools/slony1_dump.sh | 49 ++++++++--------------------- 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/clustertest/disorder/tests/LogShipping.js b/clustertest/disorder/tests/LogShipping.js index 9a64e83..53f6b09 100644 --- a/clustertest/disorder/tests/LogShipping.js +++ b/clustertest/disorder/tests/LogShipping.js @@ -23,6 +23,12 @@ LogShipping.prototype.getNodeCount=function() { return 4; } +LogShipping.prototype.getSyncWaitTime = function() +{ + + return 3*120; +} + LogShipping.prototype.runTest = function() { this.coordinator.log("LogShipping.prototype.runTest - begin"); this.testResults.newGroup("Log Shipping"); diff --git a/src/slon/remote_worker.c b/src/slon/remote_worker.c index 1671f3d..43bb516 100644 --- a/src/slon/remote_worker.c +++ b/src/slon/remote_worker.c @@ -4609,6 +4609,7 @@ sync_event(SlonNode *node, SlonConn *local_conn, (void) slon_mkquery(&query, "select SL.seql_seqid, max(SL.seql_last_value) " + " , SQ.seq_nspname, SQ.seq_relname " " from %s.sl_seqlog SL, " " %s.sl_sequence SQ " " where SQ.seq_id = SL.seql_seqid " @@ -4623,7 +4624,7 @@ sync_event(SlonNode *node, SlonConn *local_conn, (pset->prev == NULL) ? "" : ",", pset->set_id); slon_appendquery(&query, ") " - " group by 1; "); + " group by SL.seql_seqid,SQ.seq_nspname, SQ.seq_relname; "); start_monitored_event(&pm); res1 = PQexec(provider->conn->dbconn, dstring_data(&query)); @@ -4647,6 +4648,8 @@ sync_event(SlonNode *node, SlonConn *local_conn, { char *seql_seqid = PQgetvalue(res1, tupno1, 0); char *seql_last_value = PQgetvalue(res1, tupno1, 1); + char *seq_nspname = PQgetvalue(res1,tupno1,2); + char *seq_relname = PQgetvalue(res1,tupno1,3); (void) slon_mkquery(&query, "select %s.sequenceSetValue(%s,%d,'%s','%s'); ", @@ -4669,9 +4672,9 @@ sync_event(SlonNode *node, SlonConn *local_conn, if (archive_dir) { (void) slon_mkquery(&lsquery, - "select %s.sequenceSetValue_offline(%s,'%s');\n", + "select %s.sequenceSetValue_offline('%s','%s','%s');\n", rtcfg_namespace, - seql_seqid, seql_last_value); + seq_nspname,seq_relname, seql_last_value); rc = archive_append_ds(node, &lsquery); if (rc < 0) slon_retry(); diff --git a/src/slony_logshipper/parser.y b/src/slony_logshipper/parser.y index f324fef..52fc940 100644 --- a/src/slony_logshipper/parser.y +++ b/src/slony_logshipper/parser.y @@ -846,12 +846,12 @@ arch_finish_func : T_FINISH_FUNCTION } ; -arch_seqsetval : K_SELECT ident '.' arch_seqsetval_func '(' num ',' literal ')' ';' +arch_seqsetval : K_SELECT ident '.' arch_seqsetval_func '(' literal ',' literal ',' literal ')' ';' { SlonDString ds; dstring_init(&ds); - slon_mkquery(&ds, "select %s.%s(%d, '%s');", - $2, $4, $6, $8); + slon_mkquery(&ds, "select %s.%s('%s', '%s', '%s');", + $2, $4, $6, $8,$10); free($2); free($4); free($8); @@ -876,12 +876,12 @@ arch_seqsetval_func : T_SEQSETVAL_FUNCTION } ; -arch_pgsetval : K_SELECT ident '.' arch_pgsetval_func '(' literal ',' literal ')' ';' +arch_pgsetval : K_SELECT ident '.' arch_pgsetval_func '(' literal ',' literal ')' ';' { SlonDString ds; dstring_init(&ds); slon_mkquery(&ds, "select %s.%s('%s', '%s');", - $2, $4, $6, $8); + $2, $4, $6, $8); free($2); free($4); free($6); diff --git a/tools/slony1_dump.sh b/tools/slony1_dump.sh index 877f50c..a4d5a28 100755 --- a/tools/slony1_dump.sh +++ b/tools/slony1_dump.sh @@ -75,18 +75,6 @@ start transaction; -- ---------------------------------------------------------------------- create schema $clname; --- ---------------------------------------------------------------------- --- TABLE sl_sequence_offline --- ---------------------------------------------------------------------- -create table $clname.sl_sequence_offline ( - seq_id int4, - seq_relname name NOT NULL, - seq_nspname name NOT NULL, - - CONSTRAINT "sl_sequence-pkey" - PRIMARY KEY (seq_id) -); - -- ---------------------------------------------------------------------- -- TABLE sl_archive_tracking @@ -100,30 +88,22 @@ create table $clname.sl_archive_tracking ( -- ----------------------------------------------------------------------------- -- FUNCTION sequenceSetValue_offline (seq_id, last_value) -- ----------------------------------------------------------------------------- -create or replace function $clname.sequenceSetValue_offline(int4, int8) returns int4 +create or replace function $clname.sequenceSetValue_offline(text,text, int8) returns int4 as ' declare - p_seq_id alias for \$1; - p_last_value alias for \$2; - v_fqname text; + p_seq_nsp alias for \$1; + p_seq_name alias for \$2; + p_last_value alias for \$3; + begin - -- ---- - -- Get the sequences fully qualified name - -- ---- - select "pg_catalog".quote_ident(seq_nspname) || ''.'' || - "pg_catalog".quote_ident(seq_relname) into v_fqname - from $clname.sl_sequence_offline - where seq_id = p_seq_id; - if not found then - raise exception ''Slony-I: sequence % not found'', p_seq_id; - end if; + -- ---- -- Update it to the new value -- ---- - execute ''select setval('''''' || v_fqname || - '''''', '''''' || p_last_value || '''''')''; - return p_seq_id; + execute '' select setval(''''''|| p_seq_nsp || ''.'' || + p_seq_name || '''''', '''''' || p_last_value || '''''')''; + return 0; end; ' language plpgsql; -- --------------------------------------------------------------------------------------- @@ -190,16 +170,13 @@ echo "start transaction;" echo "set transaction isolation level serializable;" # ---- -# Fill the sl_sequence_offline table and provide initial -# values for all sequences. +# Provide initial values for all sequences. # ---- -echo "select 'copy $clname.sl_sequence_offline from stdin;';" -echo "select seq_id::text || ' ' || seq_relname || ' ' || seq_nspname from $clname.sl_sequence;" -printf "select E'\\\\\\\\.';" - for seq in $sequences ; do eval seqname=\$seqname_$seq - echo "select 'select $clname.sequenceSetValue_offline($seq, ''' || last_value::text || ''');' from $seqname;" + schema=`echo $seqname|cut -d'.' -f1` + name=`echo $seqname|cut -d'.' -f2` + echo "select E'select $clname.sequenceSetValue_offline(''$schema'',''$name'', ''' || last_value::text || E''');' from $seqname;" done # ---- -- 1.7.0.4