master_v9_amit.diff.patch
application/octet-stream
Filename: master_v9_amit.diff.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
Series: patch v9
| File | + | − |
|---|---|---|
| src/backend/replication/logical/snapbuild.c | 16 | 13 |
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index ab6bae3b6e..ca56f7bfe3 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -247,15 +247,18 @@ struct SnapBuild
* and were running when the snapshot was serialized.
*
* We normally rely on HEAP2_NEW_CID and XLOG_XACT_INVALIDATIONS records to
- * know if the transaction has changed the catalog. But it could happen that
- * the logical decoding decodes only the commit record of the transaction.
- * This array stores the transactions that have modified catalogs and were
- * running when serializing a snapshot, and this array is used to add such
- * transactions to the snapshot.
+ * know if the transaction has changed the catalog. But it could happen
+ * that the logical decoding decodes only the commit record of the
+ * transaction after restoring the previously serialized snapshot in which
+ * case we will miss adding the xid to the snapshot and end up looking at
+ * the catalogs with the wrong snapshot.
*
- * This array is set once when restoring the snapshot, we remove xids from
- * this array when they become old enough to matter, and then it eventually
- * becomes empty.
+ * Now to avoid the above problem, we serialize the transactions that had
+ * modified the catalogs and are still running at the time of snapshot
+ * serialization. We fill this array while restoring the snapshot and then
+ * refer it while decoding commit to ensure if the xact has modified the
+ * catalog. We remove xids from this array when they become old enough to
+ * matter, and then it eventually becomes empty.
*/
struct
{
@@ -924,9 +927,9 @@ SnapBuildAddCommittedTxn(SnapBuild *builder, TransactionId xid)
* the ->committed or ->catchange array, respectively. The committed xids will
* get checked via the clog machinery.
*
- * We can ideally remove the transaction
- * from catchange array once it is finished (committed/aborted) but that could
- * be costly as we need to maintain the xids order in the array.
+ * We can ideally remove the transaction from catchange array once it is
+ * finished (committed/aborted) but that could be costly as we need to maintain
+ * the xids order in the array.
*/
static void
SnapBuildPurgeOlderTxn(SnapBuild *builder)
@@ -1171,8 +1174,8 @@ SnapBuildXidHasCatalogChanges(SnapBuild *builder, TransactionId xid,
return true;
/*
- * If the commit record of the transaction does not have invalidation
- * messages, it did not change catalogs for sure.
+ * The transactions that have changed catalogs must have invalidation
+ * info.
*/
if (!(xinfo & XACT_XINFO_HAS_INVALS))
return false;