Skip to content

Commit 2f6e15a

Browse files
committed
Revert refactoring of restore command code to shell_restore.c
This reverts commits 24c35ec and 57169ad. PreRestoreCommand() and PostRestoreCommand() need to be put closer to the system() call calling a restore_command, as they enable in_restore_command for the startup process which would in turn trigger an immediate proc_exit() in the SIGTERM handler. Perhaps we could get rid of this behavior entirely, but 24c35ec has made the window where the flag is enabled much larger than it was, and any Postgres-like actions (palloc, etc.) taken by code paths while the flag is enabled could lead to more severe issues in the shutdown processing. Note that curculio has showed that there are much more problems in this area, unrelated to this change, actually, hence the issues related to that had better be addressed first. Keeping the code of HEAD in line with the stable branches should make that a bit easier. Per discussion with Andres Freund and Nathan Bossart. Discussion: https://postgr.es/m/Y979NR3U5VnWrTwB@paquier.xyz
1 parent b2d0e13 commit 2f6e15a

File tree

12 files changed

+215
-219
lines changed

12 files changed

+215
-219
lines changed

src/backend/access/transam/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ OBJS = \
1919
multixact.o \
2020
parallel.o \
2121
rmgr.o \
22-
shell_restore.o \
2322
slru.o \
2423
subtrans.o \
2524
timeline.o \

src/backend/access/transam/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ backend_sources += files(
77
'multixact.c',
88
'parallel.c',
99
'rmgr.c',
10-
'shell_restore.c',
1110
'slru.c',
1211
'subtrans.c',
1312
'timeline.c',

src/backend/access/transam/shell_restore.c

Lines changed: 0 additions & 171 deletions
This file was deleted.

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,6 @@ static char *GetXLogBuffer(XLogRecPtr ptr, TimeLineID tli);
692692
static XLogRecPtr XLogBytePosToRecPtr(uint64 bytepos);
693693
static XLogRecPtr XLogBytePosToEndRecPtr(uint64 bytepos);
694694
static uint64 XLogRecPtrToBytePos(XLogRecPtr ptr);
695-
static void GetOldestRestartPointFileName(char *fname);
696695

697696
static void WALInsertLockAcquire(void);
698697
static void WALInsertLockAcquireExclusive(void);
@@ -4890,12 +4889,10 @@ CleanupAfterArchiveRecovery(TimeLineID EndOfLogTLI, XLogRecPtr EndOfLog,
48904889
* Execute the recovery_end_command, if any.
48914890
*/
48924891
if (recoveryEndCommand && strcmp(recoveryEndCommand, "") != 0)
4893-
{
4894-
char lastRestartPointFname[MAXFNAMELEN];
4895-
4896-
GetOldestRestartPointFileName(lastRestartPointFname);
4897-
shell_recovery_end(lastRestartPointFname);
4898-
}
4892+
ExecuteRecoveryCommand(recoveryEndCommand,
4893+
"recovery_end_command",
4894+
true,
4895+
WAIT_EVENT_RECOVERY_END_COMMAND);
48994896

49004897
/*
49014898
* We switched to a new timeline. Clean up segments on the old timeline.
@@ -7312,12 +7309,10 @@ CreateRestartPoint(int flags)
73127309
* Finally, execute archive_cleanup_command, if any.
73137310
*/
73147311
if (archiveCleanupCommand && strcmp(archiveCleanupCommand, "") != 0)
7315-
{
7316-
char lastRestartPointFname[MAXFNAMELEN];
7317-
7318-
GetOldestRestartPointFileName(lastRestartPointFname);
7319-
shell_archive_cleanup(lastRestartPointFname);
7320-
}
7312+
ExecuteRecoveryCommand(archiveCleanupCommand,
7313+
"archive_cleanup_command",
7314+
false,
7315+
WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND);
73217316

73227317
return true;
73237318
}
@@ -8894,22 +8889,6 @@ GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
88948889
LWLockRelease(ControlFileLock);
88958890
}
88968891

8897-
/*
8898-
* Returns the WAL file name for the last checkpoint or restartpoint. This is
8899-
* the oldest WAL file that we still need if we have to restart recovery.
8900-
*/
8901-
static void
8902-
GetOldestRestartPointFileName(char *fname)
8903-
{
8904-
XLogRecPtr restartRedoPtr;
8905-
TimeLineID restartTli;
8906-
XLogSegNo restartSegNo;
8907-
8908-
GetOldestRestartPoint(&restartRedoPtr, &restartTli);
8909-
XLByteToSeg(restartRedoPtr, restartSegNo, wal_segment_size);
8910-
XLogFileName(fname, restartTli, restartSegNo, wal_segment_size);
8911-
}
8912-
89138892
/* Thin wrapper around ShutdownWalRcv(). */
89148893
void
89158894
XLogShutdownWalRcv(void)

0 commit comments

Comments
 (0)