Re: [HACKERS] logical decoding of two-phase transactions

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, Ajin Cherian <itsajin(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] logical decoding of two-phase transactions
Date: 2020-11-10 13:35:59
Message-ID: CAA4eK1+i5pFpUNrPuiirBo_gtJuZ9buP4wm2orVmxrDFvyCFwA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 9, 2020 at 1:38 PM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> I've looked at the patches and done some tests. Here is my comment and
> question I realized during testing and reviewing.
>
> +static void
> +DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf,
> + xl_xact_parsed_prepare *parsed)
> +{
> + XLogRecPtr origin_lsn = parsed->origin_lsn;
> + TimestampTz commit_time = parsed->origin_timestamp;
>
> static void
> DecodeAbort(LogicalDecodingContext *ctx, XLogRecordBuffer *buf,
> - xl_xact_parsed_abort *parsed, TransactionId xid)
> + xl_xact_parsed_abort *parsed, TransactionId xid, bool prepared)
> {
> int i;
> + XLogRecPtr origin_lsn = InvalidXLogRecPtr;
> + TimestampTz commit_time = 0;
> + XLogRecPtr origin_id = XLogRecGetOrigin(buf->record);
>
> - for (i = 0; i < parsed->nsubxacts; i++)
> + if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
> {
> - ReorderBufferAbort(ctx->reorder, parsed->subxacts[i],
> - buf->record->EndRecPtr);
> + origin_lsn = parsed->origin_lsn;
> + commit_time = parsed->origin_timestamp;
> }
>
> In the above two changes, parsed->origin_timestamp is used as
> commit_time. But in DecodeCommit() we use parsed->xact_time instead.
> Therefore it a transaction didn't have replorigin_session_origin the
> timestamp of logical decoding out generated by test_decoding with
> 'include-timestamp' option is invalid. Is it intentional?
>

Changed as discussed.

> ---
> + if (is_commit)
> + txn->txn_flags |= RBTXN_COMMIT_PREPARED;
> + else
> + txn->txn_flags |= RBTXN_ROLLBACK_PREPARED;
> +
> + if (rbtxn_commit_prepared(txn))
> + rb->commit_prepared(rb, txn, commit_lsn);
> + else if (rbtxn_rollback_prepared(txn))
> + rb->rollback_prepared(rb, txn, commit_lsn);
>
> RBTXN_COMMIT_PREPARED and RBTXN_ROLLBACK_PREPARED are used only here
> and it seems to me that it's not necessarily necessary.
>

These are used in v18-0005-Support-2PC-txn-pgoutput. So, I don't think
we can directly remove them.

> ---
> + /*
> + * If this is COMMIT_PREPARED and the output plugin supports
> + * two-phase commits then set the prepared flag to true.
> + */
> + prepared = ((info == XLOG_XACT_COMMIT_PREPARED) &&
> ctx->twophase) ? true : false;
>
> We can write instead:
>
> prepared = ((info == XLOG_XACT_COMMIT_PREPARED) && ctx->twophase);
>
>
> + /*
> + * If this is ABORT_PREPARED and the output plugin supports
> + * two-phase commits then set the prepared flag to true.
> + */
> + prepared = ((info == XLOG_XACT_ABORT_PREPARED) &&
> ctx->twophase) ? true : false;
>
> The same is true here.
>

I have changed this code so that we can determine if the transaction
is already decoded at prepare time before calling
DecodeCommit/DecodeAbort, so these checks are gone now and I think
that makes the code look a bit cleaner.

Apart from this, I have changed v19-0001-Support-2PC-txn-base such
that it displays xid and gid consistently in all APIs. In
v19-0002-Support-2PC-txn-backend, apart from fixing the above
comments, I have rearranged the code in DecodeCommit/Abort/Prepare so
that it does only the required things (like in DecodeCommit was still
processing subtxns even when it has to just perform FinishPrepared,
also the stats were not updated properly which I have fixed.) and
added/edited the comments. Apart from 0001 and 0002, I have not
changed anything in the remaining patches.

--
With Regards,
Amit Kapila.

Attachment Content-Type Size
v19-0001-Support-2PC-txn-base.patch application/octet-stream 39.2 KB
v19-0002-Support-2PC-txn-backend.patch application/octet-stream 30.1 KB
v19-0003-Support-2PC-test-cases-for-test_decoding.patch application/octet-stream 33.3 KB
v19-0004-Support-2PC-txn-spoolfile.patch application/octet-stream 3.9 KB
v19-0005-Support-2PC-txn-pgoutput.patch application/octet-stream 21.4 KB
v19-0006-Support-2PC-txn-subscriber-tests.patch application/octet-stream 34.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2020-11-10 13:42:46 Re: Parallel copy
Previous Message Bharath Rupireddy 2020-11-10 13:11:12 Re: Use standard SIGHUP and SIGTERM handlers in autoprewarm module