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

Commit 553b6ee

Browse files
Mikhail LitsarevCommitfest Bot
Mikhail Litsarev
authored and
Commitfest Bot
committed
Wrapper function to extract whole text array from recovery flags bitset.
It returns SX_PROMOTE_IS_TRIGGERED, SX_STANDBY_MODE_REQUESTED flags for recovery states.
1 parent b7a0c27 commit 553b6ee

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

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+
}

src/backend/access/transam/xlogrecovery.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,6 +4370,22 @@ StartupRequestWalReceiverRestart(void)
43704370
}
43714371
}
43724372

4373+
/*
4374+
* Return SX_PROMOTE_IS_TRIGGERED, SX_STANDBY_MODE_REQUESTED flags for
4375+
* recovery states.
4376+
*/
4377+
bits32 GetXLogRecoveryFlags(void)
4378+
{
4379+
bits32 flags = 0;
4380+
4381+
SpinLockAcquire(&XLogRecoveryCtl->info_lck);
4382+
flags = XLogRecoveryCtl->sharedRecoveryFlags;
4383+
SpinLockRelease(&XLogRecoveryCtl->info_lck);
4384+
4385+
flags |= (localRecoveryFlags & SX_STANDBY_MODE_REQUESTED);
4386+
4387+
return flags;
4388+
}
43734389

43744390
/*
43754391
* Has a standby promotion already been triggered?

src/include/access/xlogrecovery.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ extern TimestampTz GetLatestXTime(void);
172172
extern TimestampTz GetCurrentChunkReplayStartTime(void);
173173
extern XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI);
174174

175+
extern bits32 GetXLogRecoveryFlags(void);
175176
extern bool PromoteIsTriggered(void);
176177
extern bool CheckPromoteSignal(void);
177178
extern void WakeupRecovery(void);

src/include/catalog/pg_proc.dat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6714,6 +6714,11 @@
67146714
proname => 'pg_is_in_recovery', provolatile => 'v', prorettype => 'bool',
67156715
proargtypes => '', prosrc => 'pg_is_in_recovery' },
67166716

6717+
{ oid => '8439',
6718+
descr => 'return flags for recovery states',
6719+
proname => 'pg_get_recovery_flags', provolatile => 'v', prorettype => '_text',
6720+
proargtypes => '', prosrc => 'pg_get_recovery_flags' },
6721+
67176722
{ oid => '3820', descr => 'current wal flush location',
67186723
proname => 'pg_last_wal_receive_lsn', provolatile => 'v',
67196724
prorettype => 'pg_lsn', proargtypes => '',

0 commit comments

Comments
 (0)