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.
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);
}
}
* 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
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);
}
/*
* 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);
}
/*
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'.
*/
}
/* looks like a slot in a normal state, restore */
- RestoreSlot(replication_de->d_name);
+ RestoreSlotFromDisk(replication_de->d_name);
}
FreeDir(replication_dir);
* ----
*/
static void
-CreateSlot(ReplicationSlot *slot)
+CreateSlotOnDisk(ReplicationSlot *slot)
{
char tmppath[MAXPGPATH];
char path[MAXPGPATH];
fsync_fname(tmppath, true);
- SaveSlotGuts(slot, tmppath);
+ SaveSlotToPath(slot, tmppath);
if (rename(tmppath, path) != 0)
{
}
-/*
- * 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];
* Load a single slot from disk into memory.
*/
static void
-RestoreSlot(const char *name)
+RestoreSlotFromDisk(const char *name)
{
ReplicationSlotOnDisk cp;
int i;