logical decoding: process ASSIGNMENT during snapshot build
authorAlvaro Herrera <[email protected]>
Fri, 13 Sep 2019 19:36:28 +0000 (16:36 -0300)
committerAlvaro Herrera <[email protected]>
Fri, 13 Sep 2019 19:36:28 +0000 (16:36 -0300)
Most WAL records are ignored in early SnapBuild snapshot build phases.
But it's critical to process some of them, so that later messages have
the correct transaction state after the snapshot is completely built; in
particular, XLOG_XACT_ASSIGNMENT messages are critical in order for
sub-transactions to be correctly assigned to their parent transactions,
or at least one assert misbehaves, as reported by Ildar Musin.

Diagnosed-by: Masahiko Sawada
Author: Masahiko Sawada
Discussion: https://postgr.es/m/CAONYFtOv+Er1p3WAuwUsy1zsCFrSYvpHLhapC_fMD-zNaRWxYg@mail.gmail.com

src/backend/replication/logical/decode.c

index 457426369993e07a96516b44e35f0ef39c2121a2..d1e45d330fa9ea5f2ad586e171f822a5c77f8f26 100644 (file)
@@ -202,12 +202,15 @@ DecodeXactOp(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
    uint8       info = r->xl_info & ~XLR_INFO_MASK;
 
    /*
-    * No point in doing anything yet, data could not be decoded anyway. It's
-    * ok not to call ReorderBufferProcessXid() in that case, except in the
-    * assignment case there'll not be any later records with the same xid;
-    * and in the assignment case we'll not decode those xacts.
+    * If the snapshot isn't yet fully built, we cannot decode anything, so
+    * bail out.
+    *
+    * However, it's critical to process XLOG_XACT_ASSIGNMENT records even
+    * when the snapshot is being built: it is possible to get later records
+    * that require subxids to be properly assigned.
     */
-   if (SnapBuildCurrentState(builder) < SNAPBUILD_FULL_SNAPSHOT)
+   if (SnapBuildCurrentState(builder) < SNAPBUILD_FULL_SNAPSHOT &&
+       info != XLOG_XACT_ASSIGNMENT)
        return;
 
    switch (info)