Skip to content

Commit e7c9b0e

Browse files
Sasha Krassovskytristan957
authored andcommitted
Add custom xlogreader callbacks to walsender (v15) (#405)
* Add hooks for custom xlogreader in walsender * Make WalSndWaitForWal not static * Spaces to tab
1 parent fa8f7d2 commit e7c9b0e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/backend/replication/walsender.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ int wal_sender_timeout = 60 * 1000; /* maximum time to send one WAL
126126
* data message */
127127
bool log_replication_commands = false;
128128

129+
void (*WalSender_Custom_XLogReaderRoutines)(XLogReaderRoutine *xlr);
129130
/*
130131
* State for WalSndWakeupRequest
131132
*/
@@ -258,7 +259,7 @@ static void WalSndPrepareWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, Tran
258259
static void WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, bool last_write);
259260
static void WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
260261
bool skipped_xact);
261-
static XLogRecPtr WalSndWaitForWal(XLogRecPtr loc);
262+
XLogRecPtr WalSndWaitForWal(XLogRecPtr loc);
262263
static bool TransactionIdInRecentPast(TransactionId xid, uint32 epoch);
263264

264265
static void WalSndSegmentOpen(XLogReaderState *state, XLogSegNo nextSegNo,
@@ -1261,6 +1262,7 @@ StartLogicalReplication(StartReplicationCmd *cmd)
12611262
{
12621263
StringInfoData buf;
12631264
QueryCompletion qc;
1265+
XLogReaderRoutine xlr;
12641266

12651267
/* make sure that our requirements are still fulfilled */
12661268
CheckLogicalDecodingRequirements();
@@ -1288,6 +1290,12 @@ StartLogicalReplication(StartReplicationCmd *cmd)
12881290
got_STOPPING = true;
12891291
}
12901292

1293+
xlr.page_read = logical_read_xlog_page;
1294+
xlr.segment_open = WalSndSegmentOpen;
1295+
xlr.segment_close = wal_segment_close;
1296+
if (WalSender_Custom_XLogReaderRoutines != NULL)
1297+
WalSender_Custom_XLogReaderRoutines(&xlr);
1298+
12911299
/*
12921300
* Create our decoding context, making it start at the previously ack'ed
12931301
* position.
@@ -1296,10 +1304,7 @@ StartLogicalReplication(StartReplicationCmd *cmd)
12961304
* are reported early.
12971305
*/
12981306
logical_decoding_ctx =
1299-
CreateDecodingContext(cmd->startpoint, cmd->options, false,
1300-
XL_ROUTINE(.page_read = logical_read_xlog_page,
1301-
.segment_open = WalSndSegmentOpen,
1302-
.segment_close = wal_segment_close),
1307+
CreateDecodingContext(cmd->startpoint, cmd->options, false, &xlr,
13031308
WalSndPrepareWrite, WalSndWriteData,
13041309
WalSndUpdateProgress);
13051310
xlogreader = logical_decoding_ctx->reader;
@@ -1547,7 +1552,7 @@ WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId
15471552
* if we detect a shutdown request (either from postmaster or client)
15481553
* we will return early, so caller must always check.
15491554
*/
1550-
static XLogRecPtr
1555+
XLogRecPtr
15511556
WalSndWaitForWal(XLogRecPtr loc)
15521557
{
15531558
int wakeEvents;

src/include/replication/walsender.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ extern PGDLLIMPORT int max_wal_senders;
3636
extern PGDLLIMPORT int wal_sender_timeout;
3737
extern PGDLLIMPORT bool log_replication_commands;
3838

39+
struct XLogReaderRoutine;
40+
extern PGDLLIMPORT void (*WalSender_Custom_XLogReaderRoutines)(struct XLogReaderRoutine *xlr);
41+
3942
extern void InitWalSender(void);
4043
extern bool exec_replication_command(const char *query_string);
4144
extern void WalSndErrorCleanup(void);

0 commit comments

Comments
 (0)