Skip to content

Commit 58bd6a6

Browse files
Vitaly DavydovCommitfest Bot
Vitaly Davydov
authored and
Commitfest Bot
committed
Remove redundant ReplicationSlotsComputeRequiredLSN calls
The function ReplicationSlotsComputeRequiredLSN is used to calculate the oldest slots' required LSN. It is called every time when restart_lsn value of any slot is changed (for example, when a slot is advancing). The slot's oldest required LSN is used to remote old WAL segments in two places - when checkpoint or restart point is created (CreateCheckPoint, CreateRestartPoint functions). Old WAL segments seems to be truncated in these two functions only. The idea of the patch is to call ReplicationSlotsComputeRequiredLSN in CreateCheckPoint or CreateRestartPoint functions only, before call of RemoveOldXlogFiles function where old WAL segments are removed. There is no obvious need to recalculate oldest required LSN every time when a slot's restart_lsn is changed. The value of the oldest required lsn can affect on slot invalidation. The function InvalidateObsoleteReplicationSlots with non zero second parameter (oldestSegno) is called in CreateCheckPoint, CreateRestartPoint functions only where slot invalidation occurs with reason RS_INVAL_WAL_REMOVED. Once we update the oldest slots' required lsn in the beginning of these functions, the proposed patch should not break the behaviour of slot invalidation function in this case.
1 parent 5ee12b0 commit 58bd6a6

File tree

6 files changed

+4
-13
lines changed

6 files changed

+4
-13
lines changed

src/backend/access/transam/xlog.c

+4
Original file line numberDiff line numberDiff line change
@@ -7320,6 +7320,7 @@ CreateCheckPoint(int flags)
73207320
/*
73217321
* Get the current minimum LSN to be used later in WAL segments cleanup.
73227322
*/
7323+
ReplicationSlotsComputeRequiredLSN();
73237324
slotsMinReqLSN = XLogGetReplicationSlotMinimumLSN();
73247325

73257326
/*
@@ -7519,6 +7520,7 @@ CreateCheckPoint(int flags)
75197520
_logSegNo, InvalidOid,
75207521
InvalidTransactionId))
75217522
{
7523+
ReplicationSlotsComputeRequiredLSN();
75227524
slotsMinReqLSN = XLogGetReplicationSlotMinimumLSN();
75237525
CheckPointReplicationSlots(shutdown);
75247526

@@ -7888,6 +7890,7 @@ CreateRestartPoint(int flags)
78887890
/*
78897891
* Get the current minimum LSN to be used later in WAL segments cleanup.
78907892
*/
7893+
ReplicationSlotsComputeRequiredLSN();
78917894
slotsMinReqLSN = XLogGetReplicationSlotMinimumLSN();
78927895

78937896
if (log_checkpoints)
@@ -7983,6 +7986,7 @@ CreateRestartPoint(int flags)
79837986
_logSegNo, InvalidOid,
79847987
InvalidTransactionId))
79857988
{
7989+
ReplicationSlotsComputeRequiredLSN();
79867990
slotsMinReqLSN = XLogGetReplicationSlotMinimumLSN();
79877991
CheckPointReplicationSlots(flags & CHECKPOINT_IS_SHUTDOWN);
79887992

src/backend/replication/logical/logical.c

-1
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,6 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
19051905
SpinLockRelease(&MyReplicationSlot->mutex);
19061906

19071907
ReplicationSlotsComputeRequiredXmin(false);
1908-
ReplicationSlotsComputeRequiredLSN();
19091908
}
19101909
}
19111910
else

src/backend/replication/logical/slotsync.c

-4
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ update_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid,
335335
SpinLockRelease(&slot->mutex);
336336

337337
ReplicationSlotsComputeRequiredXmin(false);
338-
ReplicationSlotsComputeRequiredLSN();
339338
}
340339

341340
return updated_config || updated_xmin_or_lsn;
@@ -502,9 +501,6 @@ reserve_wal_for_local_slot(XLogRecPtr restart_lsn)
502501
slot->data.restart_lsn = restart_lsn;
503502
SpinLockRelease(&slot->mutex);
504503

505-
/* Prevent WAL removal as fast as possible */
506-
ReplicationSlotsComputeRequiredLSN();
507-
508504
XLByteToSeg(slot->data.restart_lsn, segno, wal_segment_size);
509505

510506
/*

src/backend/replication/slot.c

-5
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,6 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
10081008
* limits.
10091009
*/
10101010
ReplicationSlotsComputeRequiredXmin(false);
1011-
ReplicationSlotsComputeRequiredLSN();
10121011

10131012
/*
10141013
* If removing the directory fails, the worst thing that will happen is
@@ -1494,9 +1493,6 @@ ReplicationSlotReserveWal(void)
14941493
slot->data.restart_lsn = restart_lsn;
14951494
SpinLockRelease(&slot->mutex);
14961495

1497-
/* prevent WAL removal as fast as possible */
1498-
ReplicationSlotsComputeRequiredLSN();
1499-
15001496
/*
15011497
* If all required WAL is still there, great, otherwise retry. The
15021498
* slot should prevent further removal of WAL, unless there's a
@@ -2014,7 +2010,6 @@ InvalidateObsoleteReplicationSlots(uint32 possible_causes,
20142010
if (invalidated)
20152011
{
20162012
ReplicationSlotsComputeRequiredXmin(false);
2017-
ReplicationSlotsComputeRequiredLSN();
20182013
}
20192014

20202015
return invalidated;

src/backend/replication/slotfuncs.c

-2
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ pg_replication_slot_advance(PG_FUNCTION_ARGS)
583583
* advancing potentially done.
584584
*/
585585
ReplicationSlotsComputeRequiredXmin(false);
586-
ReplicationSlotsComputeRequiredLSN();
587586

588587
ReplicationSlotRelease();
589588

@@ -819,7 +818,6 @@ copy_replication_slot(FunctionCallInfo fcinfo, bool logical_slot)
819818

820819
ReplicationSlotMarkDirty();
821820
ReplicationSlotsComputeRequiredXmin(false);
822-
ReplicationSlotsComputeRequiredLSN();
823821
ReplicationSlotSave();
824822

825823
#ifdef USE_ASSERT_CHECKING

src/backend/replication/walsender.c

-1
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,6 @@ PhysicalConfirmReceivedLocation(XLogRecPtr lsn)
23842384
if (changed)
23852385
{
23862386
ReplicationSlotMarkDirty();
2387-
ReplicationSlotsComputeRequiredLSN();
23882387
PhysicalWakeupLogicalWalSnd();
23892388
}
23902389

0 commit comments

Comments
 (0)