Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d8030c6

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 25fb6ba commit d8030c6

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
@@ -1151,6 +1151,7 @@ RestoreSlotFromDisk(const char *name)
11511151
{
11521152
ReplicationSlotOnDisk cp;
11531153
int i;
1154+
char slotdir[MAXPGPATH + 12];
11541155
char path[MAXPGPATH + 22];
11551156
int fd;
11561157
bool restored = false;
@@ -1160,13 +1161,14 @@ RestoreSlotFromDisk(const char *name)
11601161
/* no need to lock here, no concurrent access allowed yet */
11611162

11621163
/* delete temp file if it exists */
1163-
sprintf(path, "pg_replslot/%s/state.tmp", name);
1164+
sprintf(slotdir, "pg_replslot/%s", name);
1165+
sprintf(path, "%s/state.tmp", slotdir);
11641166
if (unlink(path) < 0 && errno != ENOENT)
11651167
ereport(PANIC,
11661168
(errcode_for_file_access(),
11671169
errmsg("could not remove file \"%s\": %m", path)));
11681170

1169-
sprintf(path, "pg_replslot/%s/state", name);
1171+
sprintf(path, "%s/state", slotdir);
11701172

11711173
elog(DEBUG1, "restoring replication slot from \"%s\"", path);
11721174

@@ -1199,7 +1201,7 @@ RestoreSlotFromDisk(const char *name)
11991201

12001202
/* Also sync the parent directory */
12011203
START_CRIT_SECTION();
1202-
fsync_fname(path, true);
1204+
fsync_fname(slotdir, true);
12031205
END_CRIT_SECTION();
12041206

12051207
/* read part of statefile that's guaranteed to be version independent */
@@ -1274,13 +1276,11 @@ RestoreSlotFromDisk(const char *name)
12741276
*/
12751277
if (cp.slotdata.persistency != RS_PERSISTENT)
12761278
{
1277-
sprintf(path, "pg_replslot/%s", name);
1278-
1279-
if (!rmtree(path, true))
1279+
if (!rmtree(slotdir, true))
12801280
{
12811281
ereport(WARNING,
12821282
(errcode_for_file_access(),
1283-
errmsg("could not remove directory \"%s\"", path)));
1283+
errmsg("could not remove directory \"%s\"", slotdir)));
12841284
}
12851285
fsync_fname("pg_replslot", true);
12861286
return;

0 commit comments

Comments
 (0)