sequence_clean_elog.txt

text/plain

Filename: sequence_clean_elog.txt
Type: text/plain
Part: 0
Message: Re: logical decoding and replication of sequences, take 2
diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c
index 73e38cafd8..8e2ebbd8e0 100644
--- a/src/backend/replication/logical/decode.c
+++ b/src/backend/replication/logical/decode.c
@@ -1543,10 +1543,15 @@ smgr_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 	elog(LOG, "XXX: smgr_decode. snapshot is %s", SnapBuildIdentify(builder));
 
 	/*
-	 * If we don't have snapshot or we are just fast-forwarding, there is no
-	 * point in decoding relfilenode information.
+	 * If we are not building snapshot yet or we are just fast-forwarding, there
+	 * is no point in decoding relfilenode information.  If the sequence
+	 * associated with relfilenode here is changed in the same transaction but
+	 * after snapshot was built, the relfilenode needs to be present in the
+	 * sequence hash table so that the change can be deemed as transactional.
+	 * Otherwise it will not be queued. Hence we process this change even before
+	 * we have built snapshot.
 	 */
-	if (SnapBuildCurrentState(builder) < SNAPBUILD_FULL_SNAPSHOT ||
+	if (SnapBuildCurrentState(builder) < SNAPBUILD_BUILDING_SNAPSHOT ||
 		ctx->fast_forward)
 	{
 		elog(LOG, "XXX: skipped");
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index f7d9a26cfc..25a742fef0 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -1078,6 +1078,8 @@ ReorderBufferSequenceCleanup(ReorderBuffer *rb, ReorderBufferTXN *txn)
 						HASH_REMOVE, NULL) == NULL)
 			elog(ERROR, "hash table corrupted");
 	}
+
+	elog(LOG, "sequence cleanup called on transaction %d", txn->xid);
 }
 
 /*