bdr: Use bdr.do_not_replicate to suppress replication of pg_restore
authorCraig Ringer <craig@2ndquadrant.com>
Fri, 19 Dec 2014 08:47:13 +0000 (16:47 +0800)
committerCraig Ringer <craig@2ndquadrant.com>
Wed, 4 Feb 2015 12:24:27 +0000 (23:24 +1100)
Changes from pg_restore would have previously been replicated through
the slot from the new node back to the root node during init, because
we didn't apply them with any replicaiton origin ID.

Use the bdr.do_not_replicate GUC to set DoNotReplicateRepNodeID as the
origin, so these changes get suppressed from replication.

bdr_init_replica.c
scripts/bdr_initial_load.in

index d84a7acbb8b228373d801446a55feae678ca2d11..e9fbd0fcbc894df6dfac168e5a31fef11578fcf0 100644 (file)
@@ -519,8 +519,8 @@ bdr_exec_init_replica(BdrConnectionConfig *cfg, char *snapshot)
                        &bdr_init_replica_script_path[0]) < 0)
    {
        elog(ERROR, "bdr: failed to find " BDR_INIT_REPLICA_CMD
-            " relative to binary %s or wrong version (expected %s)",
-            my_exec_path, PG_VERSION);
+            " relative to binary %s or wrong version. Expected (PostgreSQL %s, BDR %s)",
+            my_exec_path, PG_VERSION, BDR_VERSION);
    }
 
    if (find_other_exec(my_exec_path, BDR_DUMP_CMD,
@@ -552,6 +552,17 @@ bdr_exec_init_replica(BdrConnectionConfig *cfg, char *snapshot)
                     "%s fallback_application_name='"BDR_LOCALID_FORMAT": %s: init_replica restore'",
                     cfg->replica_local_dsn, BDR_LOCALID_FORMAT_ARGS, cfg->name);
 
+   /*
+    * Suppress replication of changes applied via pg_restore back to
+    * the local node.
+    *
+    * XXX DYNCONF: This should PQconninfoParse, modify the options keyword or
+    * add it, and reconstruct the string using the functions from pg_dumpall
+    * (also to be used for init_copy). This is a hack.
+    */
+   appendStringInfoString(&local_dsn,
+                          " options='-c bdr.do_not_replicate=on -c bdr.permit_unsafe_ddl_commands=on -c bdr.skip_ddl_replication=on -c bdr.skip_ddl_locking=on'");
+
    tmpdir = palloc(strlen(bdr_temp_dump_directory)+32);
    sprintf(tmpdir, "%s/postgres-bdr-%s.%d", bdr_temp_dump_directory,
            snapshot, getpid());
index ca1e6cdde181d9c8146f60bbe6b961abd632d825..50eb1c20fc93ee002bd881861e6810c694080ab3 100644 (file)
@@ -92,7 +92,7 @@ if ! "$PGDUMP" -j $JOBS $SNAP -F d -f $TMPDIR "$SOURCE"; then
 fi
 
 errlog "Restoring dump to local DB \"$TARGET\" with $JOBS concurrent workers from \"$TMPDIR\""
-if ! PGOPTIONS="-c bdr.permit_unsafe_ddl_commands=true -c bdr.skip_ddl_replication=true" "$PGRESTORE" --exit-on-error --single-transaction -j $JOBS -F d -d "$TARGET" $TMPDIR; then
+if ! "$PGRESTORE" --exit-on-error --single-transaction -j $JOBS -F d -d "$TARGET" $TMPDIR; then
     errlog "pg_restore to "$TARGET" failed, aborting"
     exit 2
 fi