bdr: Fix init_replica bug introduced by per-db workers in shmem
authorCraig Ringer <craig@2ndquadrant.com>
Thu, 15 May 2014 17:49:12 +0000 (01:49 +0800)
committerAndres Freund <andres@anarazel.de>
Thu, 3 Jul 2014 15:55:37 +0000 (17:55 +0200)
Two arrays that previously always had the same offsets for any given
connection no longer do after per-db workers were introduced. This
exposed a previous bug in init_replica where mapping between the two
arrays was not properly done.

contrib/bdr/bdr_init_replica.c

index 59343a42bf0f0c2315711ca3b64a6a37e6bdc17d..d9b0cb7d89b8f957146949b237604335a564dc4c 100644 (file)
@@ -773,7 +773,6 @@ bdr_init_replica(Name dbname)
        /* Cleanup done and nothing more to do */
        return;
 
-
    init_replica_config = bdr_connection_configs
        [init_replica_worker->worker_data.apply_worker.connection_config_idx];
    elog(DEBUG2, "bdr %s: bdr_init_replica init from connection %s",
@@ -874,6 +873,10 @@ bdr_init_replica(Name dbname)
        status = bdr_set_remote_status(nonrepl_init_conn, dbname,
                                       'i', status);
 
+       /*
+        * A list of all connections to make slots for, as indexes into
+        * BdrWorkerCtl.
+        */
        my_conn_idxs = (int*)palloc(sizeof(Size) * bdr_max_workers);
 
        /* Collect a list of connections to make slots for. */
@@ -937,7 +940,7 @@ bdr_init_replica(Name dbname)
            /* Always throws rather than returning failure */
            Assert(conn);
 
-           if (&BdrWorkerCtl->slots[off] == init_replica_worker)
+           if (w == init_replica_worker)
            {
                /*
                 * We need to keep the snapshot ID returned by CREATE SLOT so