1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

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
This commit is contained in:
Michael Paquier
2023-02-06 08:28:42 +09:00
parent b2d0e13a0a
commit 2f6e15ac93
12 changed files with 215 additions and 219 deletions

View File

@@ -692,7 +692,6 @@ static char *GetXLogBuffer(XLogRecPtr ptr, TimeLineID tli);
static XLogRecPtr XLogBytePosToRecPtr(uint64 bytepos);
static XLogRecPtr XLogBytePosToEndRecPtr(uint64 bytepos);
static uint64 XLogRecPtrToBytePos(XLogRecPtr ptr);
static void GetOldestRestartPointFileName(char *fname);
static void WALInsertLockAcquire(void);
static void WALInsertLockAcquireExclusive(void);
@@ -4890,12 +4889,10 @@ CleanupAfterArchiveRecovery(TimeLineID EndOfLogTLI, XLogRecPtr EndOfLog,
* Execute the recovery_end_command, if any.
*/
if (recoveryEndCommand && strcmp(recoveryEndCommand, "") != 0)
{
char lastRestartPointFname[MAXFNAMELEN];
GetOldestRestartPointFileName(lastRestartPointFname);
shell_recovery_end(lastRestartPointFname);
}
ExecuteRecoveryCommand(recoveryEndCommand,
"recovery_end_command",
true,
WAIT_EVENT_RECOVERY_END_COMMAND);
/*
* We switched to a new timeline. Clean up segments on the old timeline.
@@ -7312,12 +7309,10 @@ CreateRestartPoint(int flags)
* Finally, execute archive_cleanup_command, if any.
*/
if (archiveCleanupCommand && strcmp(archiveCleanupCommand, "") != 0)
{
char lastRestartPointFname[MAXFNAMELEN];
GetOldestRestartPointFileName(lastRestartPointFname);
shell_archive_cleanup(lastRestartPointFname);
}
ExecuteRecoveryCommand(archiveCleanupCommand,
"archive_cleanup_command",
false,
WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND);
return true;
}
@@ -8894,22 +8889,6 @@ GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
LWLockRelease(ControlFileLock);
}
/*
* Returns the WAL file name for the last checkpoint or restartpoint. This is
* the oldest WAL file that we still need if we have to restart recovery.
*/
static void
GetOldestRestartPointFileName(char *fname)
{
XLogRecPtr restartRedoPtr;
TimeLineID restartTli;
XLogSegNo restartSegNo;
GetOldestRestartPoint(&restartRedoPtr, &restartTli);
XLByteToSeg(restartRedoPtr, restartSegNo, wal_segment_size);
XLogFileName(fname, restartTli, restartSegNo, wal_segment_size);
}
/* Thin wrapper around ShutdownWalRcv(). */
void
XLogShutdownWalRcv(void)