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

Commit 41ef3d1

Browse files
author
Commitfest Bot
committed
[CF 5611] v7 - SQL function which allows to distinguish a server being in point in time recovery mode and an ordinary replica
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5611 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/743b8aa9c532ae604a948cf9d6192839@postgrespro.ru Author(s): Mikhail Litsarev
2 parents 43b8e6c + e55fd6e commit 41ef3d1

File tree

10 files changed

+215
-139
lines changed

10 files changed

+215
-139
lines changed

src/backend/access/transam/timeline.c

Lines changed: 3 additions & 3 deletions
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

Lines changed: 13 additions & 13 deletions
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

Lines changed: 2 additions & 2 deletions
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;

src/backend/access/transam/xlogfuncs.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "storage/fd.h"
3131
#include "storage/latch.h"
3232
#include "storage/standby.h"
33+
#include "utils/array.h"
3334
#include "utils/builtins.h"
3435
#include "utils/memutils.h"
3536
#include "utils/pg_lsn.h"
@@ -748,3 +749,33 @@ pg_promote(PG_FUNCTION_ARGS)
748749
wait_seconds)));
749750
PG_RETURN_BOOL(false);
750751
}
752+
753+
Datum
754+
pg_get_recovery_flags(PG_FUNCTION_ARGS)
755+
{
756+
/*
757+
* Currently supported number of recovery flags is equal to two:
758+
* {SX_PROMOTE_IS_TRIGGERED, SX_STANDBY_MODE_REQUESTED}.
759+
* The SX_STANDBY_MODE_REQUESTED is valid only in the startup process.
760+
*/
761+
#define MAX_RECOVERY_FLAGS 2
762+
763+
bits32 recovery_flags;
764+
int cnt = 0;
765+
Datum flags[MAX_RECOVERY_FLAGS];
766+
ArrayType *txt_arr;
767+
768+
recovery_flags = GetXLogRecoveryFlags();
769+
770+
if (recovery_flags & SX_PROMOTE_IS_TRIGGERED)
771+
flags[cnt++] = CStringGetTextDatum("PROMOTE_IS_TRIGGERED");
772+
773+
if (recovery_flags & SX_STANDBY_MODE_REQUESTED)
774+
flags[cnt++] = CStringGetTextDatum("STANDBY_MODE_REQUESTED");
775+
776+
Assert(cnt <= MAX_RECOVERY_FLAGS);
777+
778+
/* Returns bit array as Datum */
779+
txt_arr = construct_array_builtin(flags, cnt, TEXTOID);
780+
PG_RETURN_ARRAYTYPE_P(txt_arr);
781+
}

0 commit comments

Comments
 (0)