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

From: Ajin Cherian <itsajin(at)gmail(dot)com>
To: vignesh C <vignesh21(at)gmail(dot)com>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] logical decoding of two-phase transactions
Date: 2021-05-28 03:44:12
Message-ID: CAFPTHDasWT=OuhSpz_swhoXxQi4uk4saGre+kNQd1airmXw-Hw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, May 26, 2021 at 6:53 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
>
> On Tue, May 25, 2021 at 8:54 AM Ajin Cherian <itsajin(at)gmail(dot)com> wrote:
> >
> > On Fri, May 21, 2021 at 6:43 PM Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
> >
> > > Fixed in v77-0001, v77-0002
> >
> > Attaching a new patch-set that rebases the patch, addresses review
> > comments from Peter as well as a test failure reported by Tang. I've
> > also added some new test case into patch-2 authored by Tang.
>
> Thanks for the updated patch, few comments:
> 1) Should "The end LSN of the prepare." be changed to "end LSN of the
> prepare transaction."?

No, this is the end LSN of the prepare. The prepare consists of multiple LSNs.

> 2) Should the ";" be "," here?
> +++ b/doc/src/sgml/catalogs.sgml
> @@ -7639,6 +7639,18 @@ SCRAM-SHA-256$<replaceable>&lt;iteration
> count&gt;</replaceable>:<replaceable>&l
>
> <row>
> <entry role="catalog_table_entry"><para role="column_definition">
> + <structfield>subtwophasestate</structfield> <type>char</type>
> + </para>
> + <para>
> + State code:
> + <literal>d</literal> = two_phase mode was not requested, so is disabled;
> + <literal>p</literal> = two_phase mode was requested, but is
> pending enablement;
> + <literal>e</literal> = two_phase mode was requested, and is enabled.
> + </para></entry>

no, I think the ";" is correct here, connecting multiple parts of the sentence.

>
> 3) Should end_lsn be commit_end_lsn?
> + prepare_data->commit_end_lsn = pq_getmsgint64(in);
> + if (prepare_data->commit_end_lsn == InvalidXLogRecPtr)
> elog(ERROR, "end_lsn is not set in commit prepared message");
> + prepare_data->prepare_time = pq_getmsgint64(in);

Changed this.

>
> 4) This change is not required
>
> diff --git a/src/include/replication/pgoutput.h
> b/src/include/replication/pgoutput.h
> index 0dc460f..93c6731 100644
> --- a/src/include/replication/pgoutput.h
> +++ b/src/include/replication/pgoutput.h
> @@ -29,5 +29,4 @@ typedef struct PGOutputData
> bool messages;
> bool two_phase;
> } PGOutputData;
> -

removed.

> #endif /* PGOUTPUT_H */
>
> 5) Will the worker receive commit prepared/rollback prepared as we
> have skip logic to skip commit prepared / commit rollback in
> pgoutput_rollback_prepared_txn and pgoutput_commit_prepared_txn:
>
> + * It is possible that we haven't received the prepare because
> + * the transaction did not have any changes relevant to this
> + * subscription and was essentially an empty prepare. In which case,
> + * the walsender is optimized to drop the empty transaction and the
> + * accompanying prepare. Silently ignore if we don't find the prepared
> + * transaction.
> */
> - replorigin_session_origin_lsn = prepare_data.end_lsn;
> - replorigin_session_origin_timestamp = prepare_data.commit_time;
> + if (LookupGXact(gid, prepare_data.prepare_end_lsn,
> + prepare_data.prepare_time))
> + {
>
Commit prepared will be skipped if it happens in the same walsender's
lifetime. But if the walsender restarts it no longer
knows about the skipped prepare. In this case walsender will not skip
the commit prepared. Hence, the logic for handling
stray commit prepared in the apply worker.

> 6) I'm not sure if we could add some tests for skip empty prepare
> transactions, if possible add few tests.

I've added a test case using pg_logical_slot_peek_binary_changes() for
empty prepares
have a look.

>
> 7) We could add some debug level log messages for the transaction that
> will be skipped.

If this is for the test, I was able to add a test without debug messages.

regards,
Ajin Cherian
Fujitsu Australia

Attachment Content-Type Size
v80-0001-Add-support-for-prepared-transactions-to-built-i.patch application/octet-stream 146.1 KB
v80-0003-Skip-empty-transactions-for-logical-replication.patch application/octet-stream 26.6 KB
v80-0002-Add-prepare-API-support-for-streaming-transactio.patch application/octet-stream 57.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ajin Cherian 2021-05-28 04:40:54 Re: [HACKERS] logical decoding of two-phase transactions
Previous Message Paul Guo 2021-05-28 03:43:09 Re: sync request forward function ForwardSyncRequest() might hang for some time in a corner case?