Skip to content

Commit edb7a69

Browse files
committed
Add RecoveryStopsHook for extensions to handle custom WAL records
1 parent 00aff1d commit edb7a69

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/backend/access/transam/xlogrecovery.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,9 @@ recoveryStopsBefore(XLogReaderState *record)
26202620
/* Otherwise we only consider stopping before COMMIT or ABORT records. */
26212621
if (XLogRecGetRmid(record) != RM_XACT_ID)
26222622
return false;
2623+
/* Check RecoveryStopsHook for custom records */
2624+
else if (RmgrIdIsCustom(XLogRecGetRmid(record)) && (RecoveryStopsHook != NULL))
2625+
return RecoveryStopsHook(record, true);
26232626

26242627
xact_info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
26252628

@@ -2787,6 +2790,9 @@ recoveryStopsAfter(XLogReaderState *record)
27872790

27882791
if (rmid != RM_XACT_ID)
27892792
return false;
2793+
/* Check RecoveryStopsHook for custom records */
2794+
else if (RmgrIdIsCustom(XLogRecGetRmid(record)) && (RecoveryStopsHook != NULL))
2795+
return RecoveryStopsHook(record, false);
27902796

27912797
xact_info = info & XLOG_XACT_OPMASK;
27922798

@@ -4556,6 +4562,8 @@ GetXLogReplayRecPtr(TimeLineID *replayTLI)
45564562

45574563
GetReplayXlogPtrHookType GetReplayXlogPtrHook = NULL;
45584564

4565+
RecoveryStopsHookType RecoveryStopsHook = NULL;
4566+
45594567
/*
45604568
* Get effective latest redo apply position.
45614569
*

src/include/access/xlogrecovery.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ typedef enum RecoveryPauseState
5050

5151
typedef XLogRecPtr (*GetReplayXlogPtrHookType) (void);
5252

53+
typedef bool (*RecoveryStopsHookType) (XLogReaderState *record, bool isBefore);
54+
5355
/* User-settable GUC parameters */
5456
extern PGDLLIMPORT bool recoveryTargetInclusive;
5557
extern PGDLLIMPORT int recoveryTargetAction;
@@ -81,6 +83,12 @@ extern PGDLLIMPORT bool StandbyMode;
8183
/* Hook for extensions to tune replay xlog pointer */
8284
extern PGDLLIMPORT GetReplayXlogPtrHookType GetReplayXlogPtrHook;
8385

86+
/*
87+
* Hook for extensions to be able to decides to stop applying the WAL files
88+
* based on custom WAL records.
89+
*/
90+
extern PGDLLIMPORT RecoveryStopsHookType RecoveryStopsHook;
91+
8492
extern Size XLogRecoveryShmemSize(void);
8593
extern void XLogRecoveryShmemInit(void);
8694

0 commit comments

Comments
 (0)