Skip to content

Commit 29d8182

Browse files
tvondraCommitfest Bot
authored and
Commitfest Bot
committed
Add injection points to test replication slot advance
New injection points: * checkpoint-before-old-wal-removal - triggered in the checkpointer process just before old WAL segments cleanup. * logical-replication-slot-advance-segment - triggered in LogicalConfirmReceivedLocation when restart_lsn was changed enough to point to a next WAL segment. Original patch by: Tomas Vondra <[email protected]> Modified by: Vitaly Davydov <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/1d12d2-67235980-35-19a406a0%4063439497
1 parent 627acc3 commit 29d8182

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/backend/access/transam/xlog.c

+4
Original file line numberDiff line numberDiff line change
@@ -7498,6 +7498,10 @@ CreateCheckPoint(int flags)
74987498
if (PriorRedoPtr != InvalidXLogRecPtr)
74997499
UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr);
75007500

7501+
#ifdef USE_INJECTION_POINTS
7502+
INJECTION_POINT("checkpoint-before-old-wal-removal");
7503+
#endif
7504+
75017505
/*
75027506
* Delete old log files, those no longer needed for last checkpoint to
75037507
* prevent the disk holding the xlog from growing full.

src/backend/replication/logical/logical.c

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "access/xact.h"
3232
#include "access/xlogutils.h"
33+
#include "access/xlog_internal.h"
3334
#include "fmgr.h"
3435
#include "miscadmin.h"
3536
#include "pgstat.h"
@@ -41,6 +42,7 @@
4142
#include "storage/proc.h"
4243
#include "storage/procarray.h"
4344
#include "utils/builtins.h"
45+
#include "utils/injection_point.h"
4446
#include "utils/inval.h"
4547
#include "utils/memutils.h"
4648

@@ -1825,9 +1827,13 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
18251827
{
18261828
bool updated_xmin = false;
18271829
bool updated_restart = false;
1830+
XLogRecPtr restart_lsn pg_attribute_unused();
18281831

18291832
SpinLockAcquire(&MyReplicationSlot->mutex);
18301833

1834+
/* remember the old restart lsn */
1835+
restart_lsn = MyReplicationSlot->data.restart_lsn;
1836+
18311837
MyReplicationSlot->data.confirmed_flush = lsn;
18321838

18331839
/* if we're past the location required for bumping xmin, do so */
@@ -1869,6 +1875,18 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
18691875
/* first write new xmin to disk, so we know what's up after a crash */
18701876
if (updated_xmin || updated_restart)
18711877
{
1878+
#ifdef USE_INJECTION_POINTS
1879+
XLogSegNo seg1,
1880+
seg2;
1881+
1882+
XLByteToSeg(restart_lsn, seg1, wal_segment_size);
1883+
XLByteToSeg(MyReplicationSlot->data.restart_lsn, seg2, wal_segment_size);
1884+
1885+
/* trigger injection point, but only if segment changes */
1886+
if (seg1 != seg2)
1887+
INJECTION_POINT("logical-replication-slot-advance-segment");
1888+
#endif
1889+
18721890
ReplicationSlotMarkDirty();
18731891
ReplicationSlotSave();
18741892
elog(DEBUG1, "updated xmin: %u restart: %u", updated_xmin, updated_restart);

0 commit comments

Comments
 (0)