Renaming, other consolidation.
authorRobert Haas <[email protected]>
Tue, 28 Jan 2014 15:40:02 +0000 (10:40 -0500)
committerRobert Haas <[email protected]>
Tue, 28 Jan 2014 15:40:02 +0000 (10:40 -0500)
src/backend/replication/slot.c
src/backend/storage/lmgr/proc.c

index d80eddfdac77debbc755ec627bae58fc725970d3..44c2b5a1ef7f824b651359ae9d4b03cb3e0096a2 100644 (file)
@@ -84,10 +84,9 @@ ReplicationSlot *MyReplicationSlot = NULL;
 int                    max_replication_slots = 0;      /* the maximum number of replication slots */
 
 /* internal persistency functions */
-static void RestoreSlot(const char *name);
-static void CreateSlot(ReplicationSlot *slot);
-static void SaveSlotGuts(ReplicationSlot *slot, const char *path);
-static void SaveSlot(ReplicationSlot *slot);
+static void RestoreSlotFromDisk(const char *name);
+static void CreateSlotOnDisk(ReplicationSlot *slot);
+static void SaveSlotToPath(ReplicationSlot *slot, const char *path);
 
 /*
  * Report shared-memory space needed by ReplicationSlotShmemInit.
@@ -131,11 +130,9 @@ ReplicationSlotsShmemInit(void)
 
                for (i = 0; i < max_replication_slots; i++)
                {
-                       ReplicationSlot *slot =
-                       &ReplicationSlotCtl->replication_slots[i];
-
-                       /* everything is zero initialized by the memset above */
+                       ReplicationSlot *slot = &ReplicationSlotCtl->replication_slots[i];
 
+                       /* everything else is zeroed by the memset above */
                        SpinLockInit(&slot->mutex);
                }
        }
@@ -261,7 +258,7 @@ ReplicationSlotCreate(const char *name, bool db_specific)
         * Create the slot on disk.  We haven't actually marked the slot allocated
         * yet, so no special cleanup is required if this errors out.
         */
-       CreateSlot(slot);
+       CreateSlotOnDisk(slot);
 
        /*
         * We need to briefly prevent any other backend from iterating over the
@@ -363,13 +360,6 @@ ReplicationSlotRelease(void)
                SpinLockRelease(&slot->mutex);
                MyReplicationSlot = NULL;
        }
-
-       /*
-        * XXX: There's not actually any need to save the slot to disk, it will be
-        * marked inactive after a crash/restart anyway. But we'd need to
-        * serialize all data at shutdowns or checkpoints...
-        */
-       SaveSlot(slot);
 }
 
 /*
@@ -494,14 +484,14 @@ ReplicationSlotDrop(const char *name)
  * guaranteeing the current state will survive a crash.
  */
 void
-ReplicationSlotSave()
+ReplicationSlotSave(void)
 {
        char            path[MAXPGPATH];
 
        Assert(MyReplicationSlot != NULL);
 
        sprintf(path, "pg_replslot/%s", NameStr(MyReplicationSlot->name));
-       SaveSlotGuts(MyReplicationSlot, path);
+       SaveSlotToPath(MyReplicationSlot, path);
 }
 
 /*
@@ -604,26 +594,6 @@ CheckSlotRequirements(void)
                                 errmsg("replication slot usage requires wal_level >= archive")));
 }
 
-/*
- * Make sure this backend hasn't acquired a replication slot when exiting.
- */
-void
-ReplicationSlotAtProcExit(void)
-{
-       if (MyReplicationSlot && MyReplicationSlot->active)
-       {
-               /*
-                * Acquire spinlock so other backends are guaranteed to see this in
-                * time - we cannot generally acquire the lwlock here since we might
-                * be still holding it in an error path.
-                */
-               SpinLockAcquire(&MyReplicationSlot->mutex);
-               MyReplicationSlot->active = false;
-               SpinLockRelease(&MyReplicationSlot->mutex);
-       }
-       MyReplicationSlot = NULL;
-}
-
 /*
  * Returns whether the string `str' has the postfix `end'.
  */
@@ -689,7 +659,7 @@ StartupReplicationSlots(XLogRecPtr checkPointRedo)
                }
 
                /* looks like a slot in a normal state, restore */
-               RestoreSlot(replication_de->d_name);
+               RestoreSlotFromDisk(replication_de->d_name);
        }
        FreeDir(replication_dir);
 
@@ -710,7 +680,7 @@ StartupReplicationSlots(XLogRecPtr checkPointRedo)
  * ----
  */
 static void
-CreateSlot(ReplicationSlot *slot)
+CreateSlotOnDisk(ReplicationSlot *slot)
 {
        char            tmppath[MAXPGPATH];
        char            path[MAXPGPATH];
@@ -726,7 +696,7 @@ CreateSlot(ReplicationSlot *slot)
 
        fsync_fname(tmppath, true);
 
-       SaveSlotGuts(slot, tmppath);
+       SaveSlotToPath(slot, tmppath);
 
        if (rename(tmppath, path) != 0)
        {
@@ -750,23 +720,11 @@ CreateSlot(ReplicationSlot *slot)
 
 }
 
-/*
- * Serialize the passed to disk.
- */
-static void
-SaveSlot(ReplicationSlot *slot)
-{
-       char            path[MAXPGPATH];
-
-       sprintf(path, "pg_replslot/%s", NameStr(slot->name));
-       SaveSlotGuts(slot, path);
-}
-
 /*
  * Shared functionality between saving and creating a replication slot.
  */
 static void
-SaveSlotGuts(ReplicationSlot *slot, const char *dir)
+SaveSlotToPath(ReplicationSlot *slot, const char *dir)
 {
        char            tmppath[MAXPGPATH];
        char            path[MAXPGPATH];
@@ -856,7 +814,7 @@ SaveSlotGuts(ReplicationSlot *slot, const char *dir)
  * Load a single slot from disk into memory.
  */
 static void
-RestoreSlot(const char *name)
+RestoreSlotFromDisk(const char *name)
 {
        ReplicationSlotOnDisk cp;
        int                     i;
index 8f7f6c9a9c7eed0bedcf97862abeebba3ad4bed4..45a48229a528581e22cf629b9b7f4cbbf0317e88 100644 (file)
@@ -781,7 +781,8 @@ ProcKill(int code, Datum arg)
        SyncRepCleanupAtProcExit();
 
        /* Make sure active replication slots are released */
-       ReplicationSlotAtProcExit();
+       if (MyReplicationSlot != NULL)
+               ReplicationSlotRelease();
 
 #ifdef USE_ASSERT_CHECKING
        if (assert_enabled)