add_relfilenode_before_full.txt

text/plain

Filename: add_relfilenode_before_full.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");