Skip to content

Commit 3936d57

Browse files
Mikhail LitsarevCommitfest Bot
Mikhail Litsarev
authored and
Commitfest Bot
committed
Replace recovery boolean flags with a bits32 set.
Move local booleans ArchiveRecoveryRequested, InArchiveRecovery, StandbyModeRequested, StandbyMode, LocalHotStandbyActive, LocalPromoteIsTriggered into localRecoveryFlags bitset. Move SharedHotStandbyActive, SharedPromoteIsTriggered members of XLogRecoveryCtlData into sharedRecoveryFlags bitset. Refactor the code according to the changes.
1 parent 43b8e6c commit 3936d57

File tree

8 files changed

+162
-139
lines changed

8 files changed

+162
-139
lines changed

src/backend/access/transam/timeline.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ readTimeLineHistory(TimeLineID targetTLI)
9393
return list_make1(entry);
9494
}
9595

96-
if (ArchiveRecoveryRequested)
96+
if (ArchiveRecoveryRequested())
9797
{
9898
TLHistoryFileName(histfname, targetTLI);
9999
fromArchive =
@@ -229,7 +229,7 @@ existsTimeLineHistory(TimeLineID probeTLI)
229229
if (probeTLI == 1)
230230
return false;
231231

232-
if (ArchiveRecoveryRequested)
232+
if (ArchiveRecoveryRequested())
233233
{
234234
TLHistoryFileName(histfname, probeTLI);
235235
RestoreArchivedFile(path, histfname, "RECOVERYHISTORY", 0, false);
@@ -331,7 +331,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
331331
/*
332332
* If a history file exists for the parent, copy it verbatim
333333
*/
334-
if (ArchiveRecoveryRequested)
334+
if (ArchiveRecoveryRequested())
335335
{
336336
TLHistoryFileName(histfname, parentTLI);
337337
RestoreArchivedFile(path, histfname, "RECOVERYHISTORY", 0, false);

src/backend/access/transam/xlog.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -5573,7 +5573,7 @@ CheckRequiredParameterValues(void)
55735573
* For archive recovery, the WAL must be generated with at least 'replica'
55745574
* wal_level.
55755575
*/
5576-
if (ArchiveRecoveryRequested && ControlFile->wal_level == WAL_LEVEL_MINIMAL)
5576+
if (ArchiveRecoveryRequested() && ControlFile->wal_level == WAL_LEVEL_MINIMAL)
55775577
{
55785578
ereport(FATAL,
55795579
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
@@ -5586,7 +5586,7 @@ CheckRequiredParameterValues(void)
55865586
* For Hot Standby, the WAL must be generated with 'replica' mode, and we
55875587
* must have at least as many backend slots as the primary.
55885588
*/
5589-
if (ArchiveRecoveryRequested && EnableHotStandby)
5589+
if (ArchiveRecoveryRequested() && EnableHotStandby)
55905590
{
55915591
/* We ignore autovacuum_worker_slots when we make this test. */
55925592
RecoveryRequiresIntParameter("max_connections",
@@ -5746,8 +5746,8 @@ StartupXLOG(void)
57465746
*
57475747
* InitWalRecovery analyzes the control file and the backup label file, if
57485748
* any. It updates the in-memory ControlFile buffer according to the
5749-
* starting checkpoint, and sets InRecovery and ArchiveRecoveryRequested.
5750-
* It also applies the tablespace map file, if any.
5749+
* starting checkpoint, and sets SX_ARCHIVE_RECOVERY_REQUESTED and
5750+
* InRecovery. It also applies the tablespace map file, if any.
57515751
*/
57525752
InitWalRecovery(ControlFile, &wasShutdown,
57535753
&haveBackupLabel, &haveTblspcMap);
@@ -5879,7 +5879,7 @@ StartupXLOG(void)
58795879
{
58805880
/* Initialize state for RecoveryInProgress() */
58815881
SpinLockAcquire(&XLogCtl->info_lck);
5882-
if (InArchiveRecovery)
5882+
if (InArchiveRecovery())
58835883
XLogCtl->SharedRecoveryState = RECOVERY_STATE_ARCHIVE;
58845884
else
58855885
XLogCtl->SharedRecoveryState = RECOVERY_STATE_CRASH;
@@ -5932,7 +5932,7 @@ StartupXLOG(void)
59325932
* startup process to think that there are still invalid page
59335933
* references when checking for data consistency.
59345934
*/
5935-
if (InArchiveRecovery)
5935+
if (InArchiveRecovery())
59365936
{
59375937
LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
59385938
LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI;
@@ -5966,7 +5966,7 @@ StartupXLOG(void)
59665966
* control file and we've established a recovery snapshot from a
59675967
* running-xacts WAL record.
59685968
*/
5969-
if (ArchiveRecoveryRequested && EnableHotStandby)
5969+
if (ArchiveRecoveryRequested() && EnableHotStandby)
59705970
{
59715971
TransactionId *xids;
59725972
int nxids;
@@ -6079,7 +6079,7 @@ StartupXLOG(void)
60796079
* recover from an online backup but never called pg_backup_stop(), or
60806080
* you didn't archive all the WAL needed.
60816081
*/
6082-
if (ArchiveRecoveryRequested || ControlFile->backupEndRequired)
6082+
if (ArchiveRecoveryRequested() || ControlFile->backupEndRequired)
60836083
{
60846084
if (!XLogRecPtrIsInvalid(ControlFile->backupStartPoint) || ControlFile->backupEndRequired)
60856085
ereport(FATAL,
@@ -6131,7 +6131,7 @@ StartupXLOG(void)
61316131
* In a normal crash recovery, we can just extend the timeline we were in.
61326132
*/
61336133
newTLI = endOfRecoveryInfo->lastRecTLI;
6134-
if (ArchiveRecoveryRequested)
6134+
if (ArchiveRecoveryRequested())
61356135
{
61366136
newTLI = findNewestTimeLine(recoveryTargetTLI) + 1;
61376137
ereport(LOG,
@@ -6327,7 +6327,7 @@ StartupXLOG(void)
63276327
XLogReportParameters();
63286328

63296329
/* If this is archive recovery, perform post-recovery cleanup actions. */
6330-
if (ArchiveRecoveryRequested)
6330+
if (ArchiveRecoveryRequested())
63316331
CleanupAfterArchiveRecovery(EndOfLogTLI, EndOfLog, newTLI);
63326332

63336333
/*
@@ -6486,7 +6486,7 @@ PerformRecoveryXLogAction(void)
64866486
* of a full checkpoint. A checkpoint is requested later, after we're
64876487
* fully out of recovery mode and already accepting queries.
64886488
*/
6489-
if (ArchiveRecoveryRequested && IsUnderPostmaster &&
6489+
if (ArchiveRecoveryRequested() && IsUnderPostmaster &&
64906490
PromoteIsTriggered())
64916491
{
64926492
promoted = true;
@@ -8480,7 +8480,7 @@ xlog_redo(XLogReaderState *record)
84808480
* record, the backup was canceled and the end-of-backup record will
84818481
* never arrive.
84828482
*/
8483-
if (ArchiveRecoveryRequested &&
8483+
if (ArchiveRecoveryRequested() &&
84848484
!XLogRecPtrIsInvalid(ControlFile->backupStartPoint) &&
84858485
XLogRecPtrIsInvalid(ControlFile->backupEndPoint))
84868486
ereport(PANIC,
@@ -8721,7 +8721,7 @@ xlog_redo(XLogReaderState *record)
87218721
* local copies cannot be updated as long as crash recovery is
87228722
* happening and we expect all the WAL to be replayed.
87238723
*/
8724-
if (InArchiveRecovery)
8724+
if (InArchiveRecovery())
87258725
{
87268726
LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
87278727
LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI;

src/backend/access/transam/xlogarchive.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ RestoreArchivedFile(char *path, const char *xlogfname,
6868
* Ignore restore_command when not in archive recovery (meaning we are in
6969
* crash recovery).
7070
*/
71-
if (!ArchiveRecoveryRequested)
71+
if (!ArchiveRecoveryRequested())
7272
goto not_available;
7373

7474
/* In standby mode, restore_command might not be supplied */
@@ -205,7 +205,7 @@ RestoreArchivedFile(char *path, const char *xlogfname,
205205
* incorrectly conclude we've reached the end of WAL and we're
206206
* done recovering ...
207207
*/
208-
if (StandbyMode && stat_buf.st_size < expectedSize)
208+
if (InStandbyMode() && stat_buf.st_size < expectedSize)
209209
elevel = DEBUG1;
210210
else
211211
elevel = FATAL;

0 commit comments

Comments
 (0)