From 017a1fd52a125b4551a22444ae4d67889f20a0ac Mon Sep 17 00:00:00 2001
From: tomas <tomas>
Date: Mon, 11 Nov 2024 20:31:02 +0100
Subject: [PATCH 5/5] confirmed_flush asserts

---
 src/backend/replication/logical/logical.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 40ac9f43ce2..73d6149afde 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -605,7 +605,9 @@ DecodingContextFindStartpoint(LogicalDecodingContext *ctx)
 	}
 
 	SpinLockAcquire(&slot->mutex);
+	Assert(slot->data.confirmed_flush <= ctx->reader->EndRecPtr);
 	slot->data.confirmed_flush = ctx->reader->EndRecPtr;
+	Assert(slot->data.initial_consistent_point <= ctx->reader->EndRecPtr);
 	slot->data.initial_consistent_point = ctx->reader->EndRecPtr;
 	SpinLockRelease(&slot->mutex);
 }
@@ -1735,6 +1737,7 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
 
 		SpinLockAcquire(&MyReplicationSlot->mutex);
 
+		Assert(MyReplicationSlot->data.confirmed_flush <= lsn);
 		MyReplicationSlot->data.confirmed_flush = lsn;
 
 		/* if we're past the location required for bumping xmin, do so */
@@ -1802,6 +1805,7 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
 	else
 	{
 		SpinLockAcquire(&MyReplicationSlot->mutex);
+		Assert(MyReplicationSlot->data.confirmed_flush <= lsn);
 		MyReplicationSlot->data.confirmed_flush = lsn;
 		SpinLockRelease(&MyReplicationSlot->mutex);
 	}
-- 
2.39.5

