Remove unnecessary segment number calculation after wal_removed invalidation of replication slots

Started by Bharath Rupireddyalmost 2 years ago1 messages
#1Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
1 attachment(s)

Hi,

It looks like there's an unnecessary segment number calculation after
InvalidateObsoleteReplicationSlots in CreateCheckPoint and
CreateRestartPoint. Since none of RedoRecPtr, _logSegNo and
wal_segment_size are changed by the slot invalidation code [1]Assertions like the following won't fail with make check-world proving InvalidateObsoleteReplicationSlots doesn't change them at all., the
recalculation of
_logSegNo with XLByteToSeg seems unnecessary.

I've attached a patch to fix this.

[1]: Assertions like the following won't fail with make check-world proving InvalidateObsoleteReplicationSlots doesn't change them at all.
proving InvalidateObsoleteReplicationSlots doesn't change them at all.

XLByteToSeg(RedoRecPtr, _logSegNo, wal_segment_size);
KeepLogSeg(recptr, &_logSegNo);
+ _logSegNo_saved = _logSegNo;
+ RedoRecPtr_saved = RedoRecPtr;
if (InvalidateObsoleteReplicationSlots(RS_INVAL_WAL_REMOVED,

_logSegNo, InvalidOid,

            InvalidTransactionId))
        {
+               Assert(_logSegNo_saved == _logSegNo);
+               Assert(RedoRecPtr_saved == RedoRecPtr);

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachments:

v1-0001-Remove-unnecessary-seg-no-calculation-after-check.patchapplication/octet-stream; name=v1-0001-Remove-unnecessary-seg-no-calculation-after-check.patchDownload
From 47d0300bb595ba36d29df2f7cc11880a184228f6 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Sat, 13 Apr 2024 08:30:59 +0000
Subject: [PATCH v1] Remove unnecessary seg no calculation after check for slot
 invalidation.

---
 src/backend/access/transam/xlog.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 34a2c71812..66f491a08a 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7248,7 +7248,6 @@ CreateCheckPoint(int flags)
 		 * Some slots have been invalidated; recalculate the old-segment
 		 * horizon, starting again from RedoRecPtr.
 		 */
-		XLByteToSeg(RedoRecPtr, _logSegNo, wal_segment_size);
 		KeepLogSeg(recptr, &_logSegNo);
 	}
 	_logSegNo--;
@@ -7700,7 +7699,6 @@ CreateRestartPoint(int flags)
 		 * Some slots have been invalidated; recalculate the old-segment
 		 * horizon, starting again from RedoRecPtr.
 		 */
-		XLByteToSeg(RedoRecPtr, _logSegNo, wal_segment_size);
 		KeepLogSeg(endptr, &_logSegNo);
 	}
 	_logSegNo--;
-- 
2.34.1