bdr: Fix bdr_connections_changed() to not register its hook multiple times.
authorAndres Freund <andres@anarazel.de>
Sun, 8 Feb 2015 17:03:19 +0000 (18:03 +0100)
committerAndres Freund <andres@anarazel.de>
Thu, 12 Feb 2015 09:16:59 +0000 (10:16 +0100)
While add it, rename xacthook_connection_added to
xacthook_connections_changed to more precisely reflect its usage.

bdr_perdb.c

index d67e0fb5e7b4dce997dcfeb2e306f3bfae1e0cd1..838ebad062bc7da11b29557e53ead924f81eca59 100644 (file)
@@ -50,7 +50,8 @@ Datum
 bdr_connections_changed(PG_FUNCTION_ARGS);
 
 /* In the commit hook, should we attempt to start a per-db worker? */
-static bool xacthook_connection_added = false;
+static bool xacthook_registered = false;
+static bool xacthook_connections_changed = false;
 
 /*
  * Scan shmem looking for a perdb worker for the named DB and
@@ -133,12 +134,12 @@ bdr_perdb_xact_callback(XactEvent event, void *arg)
    switch (event)
    {
        case XACT_EVENT_COMMIT:
-           if (xacthook_connection_added)
+           if (xacthook_connections_changed)
            {
                int slotno;
                BdrWorker *w;
 
-               xacthook_connection_added = false;
+               xacthook_connections_changed = false;
 
                LWLockAcquire(BdrWorkerCtl->lock, LW_EXCLUSIVE);
 
@@ -187,17 +188,18 @@ bdr_perdb_xact_callback(XactEvent event, void *arg)
  * running, and register a XACT_EVENT_COMMIT hook to perform the actual launch
  * when the addition of the worker commits.
  *
- * If a perdb worker is already running, notify it to check for new connections.
+ * If a perdb worker is already running, notify it to check for new
+ * connections.
  */
 Datum
 bdr_connections_changed(PG_FUNCTION_ARGS)
 {
-   /* If there's already a per-db worker for our DB we have nothing to do */
-   if (!xacthook_connection_added)
+   if (!xacthook_registered)
    {
        RegisterXactCallback(bdr_perdb_xact_callback, NULL);
-       xacthook_connection_added = true;
+       xacthook_registered = true;
    }
+   xacthook_connections_changed = true;
    PG_RETURN_VOID();
 }