Skip to content

Commit caa0c6c

Browse files
committed
Fix initial sync of slot parent directory when restoring status
At the beginning of recovery, information from replication slots is recovered from disk to memory. In order to ensure the durability of the information, the status file as well as its parent directory are synced. It happens that the sync on the parent directory was done directly using the status file path, which is logically incorrect, and the current code has been doing a sync on the same object twice in a row. Reported-by: Konstantin Knizhnik Diagnosed-by: Konstantin Knizhnik Author: Michael Paquier Discussion: https://postgr.es/m/9eb1a6d5-b66f-2640-598d-c5ea46b8f68a@postgrespro.ru Backpatch-through: 9.4-
1 parent 4299c32 commit caa0c6c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/backend/replication/slot.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ RestoreSlotFromDisk(const char *name)
13521352
{
13531353
ReplicationSlotOnDisk cp;
13541354
int i;
1355+
char slotdir[MAXPGPATH + 12];
13551356
char path[MAXPGPATH + 22];
13561357
int fd;
13571358
bool restored = false;
@@ -1361,13 +1362,14 @@ RestoreSlotFromDisk(const char *name)
13611362
/* no need to lock here, no concurrent access allowed yet */
13621363

13631364
/* delete temp file if it exists */
1364-
sprintf(path, "pg_replslot/%s/state.tmp", name);
1365+
sprintf(slotdir, "pg_replslot/%s", name);
1366+
sprintf(path, "%s/state.tmp", slotdir);
13651367
if (unlink(path) < 0 && errno != ENOENT)
13661368
ereport(PANIC,
13671369
(errcode_for_file_access(),
13681370
errmsg("could not remove file \"%s\": %m", path)));
13691371

1370-
sprintf(path, "pg_replslot/%s/state", name);
1372+
sprintf(path, "%s/state", slotdir);
13711373

13721374
elog(DEBUG1, "restoring replication slot from \"%s\"", path);
13731375

@@ -1402,7 +1404,7 @@ RestoreSlotFromDisk(const char *name)
14021404

14031405
/* Also sync the parent directory */
14041406
START_CRIT_SECTION();
1405-
fsync_fname(path, true);
1407+
fsync_fname(slotdir, true);
14061408
END_CRIT_SECTION();
14071409

14081410
/* read part of statefile that's guaranteed to be version independent */
@@ -1491,13 +1493,11 @@ RestoreSlotFromDisk(const char *name)
14911493
*/
14921494
if (cp.slotdata.persistency != RS_PERSISTENT)
14931495
{
1494-
sprintf(path, "pg_replslot/%s", name);
1495-
1496-
if (!rmtree(path, true))
1496+
if (!rmtree(slotdir, true))
14971497
{
14981498
ereport(WARNING,
14991499
(errcode_for_file_access(),
1500-
errmsg("could not remove directory \"%s\"", path)));
1500+
errmsg("could not remove directory \"%s\"", slotdir)));
15011501
}
15021502
fsync_fname("pg_replslot", true);
15031503
return;

0 commit comments

Comments
 (0)