Re: Fix logical decoding not track transaction during SNAPBUILD_BUILDING_SNAPSHOT

From: Ajin Cherian <itsajin(at)gmail(dot)com>
To: cca5507 <cca5507(at)qq(dot)com>
Cc: ocean_li_996 <ocean_li_996(at)163(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix logical decoding not track transaction during SNAPBUILD_BUILDING_SNAPSHOT
Date: 2026-01-29 11:13:21
Message-ID: CAFPTHDZQJeiyNGCp51Vq3rnZt3FZ1spd+kjJgqkHDm2jCH8=mw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 29, 2026 at 5:29 PM cca5507 <cca5507(at)qq(dot)com> wrote:
>
> > Looks like the assert in ReorderBufferForget failed because
> > ninvalidations is not 0.
>
> I think it can be fixed by this:
>
> ```
> @@ -282,18 +286,24 @@ xact_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
> {
> TransactionId xid;
> xl_xact_invals *invals;
> + bool has_snapshot;
>
> xid = XLogRecGetXid(r);
> invals = (xl_xact_invals *) XLogRecGetData(r);
> + has_snapshot =
> + SnapBuildCurrentState(builder) >= SNAPBUILD_FULL_SNAPSHOT;
>
> /*
> * Execute the invalidations for xid-less transactions,
> * otherwise, accumulate them so that they can be processed at
> * the commit time.
> + *
> + * Note that we only need to do this when we are not fast-forwarding
> + * and there is a snapshot.
> */
> if (TransactionIdIsValid(xid))
> {
> - if (!ctx->fast_forward)
> + if (!ctx->fast_forward && has_snapshot)
> ReorderBufferAddInvalidations(reorder, xid,
> buf->origptr,
> invals->nmsgs,
> @@ -301,7 +311,7 @@ xact_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
> ReorderBufferXidSetCatalogChanges(ctx->reorder, xid,
> buf->origptr);
> }
> - else if (!ctx->fast_forward)
> + else if (!ctx->fast_forward && has_snapshot)
> ReorderBufferImmediateInvalidation(ctx->reorder,
> invals->nmsgs,
> invals->msgs);
> ```
>
> --

Yes, this works.

regards,
Ajin Cherian
Fujitsu Australia

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ilia Evdokimov 2026-01-29 11:14:43 Re: Hash-based MCV matching for large IN-lists
Previous Message Ashutosh Bapat 2026-01-29 11:03:00 Re: Import Statistics in postgres_fdw before resorting to sampling.