Re: repeated decoding of prepared transactions

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Ajin Cherian <itsajin(at)gmail(dot)com>
Cc: Markus Wanner <markus(dot)wanner(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: repeated decoding of prepared transactions
Date: 2021-02-20 09:28:05
Message-ID: CAA4eK1Kr34_TiREr57Wpd=3=03x=1n55DAjwJPGpHAEc4dWfUQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Feb 20, 2021 at 9:46 AM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
> On Fri, Feb 19, 2021 at 8:21 AM Ajin Cherian <itsajin(at)gmail(dot)com> wrote:
> >
> > Based on this suggestion, I have created a patch on HEAD which now
> > does not allow repeated decoding
> > of prepared transactions. For this, the code now enforces
> > full_snapshot if two-phase decoding is enabled.
> > Do have a look at the patch and see if you have any comments.
> >
>
> Few minor comments:
> ===================
> 1.
> .git/rebase-apply/patch:135: trailing whitespace.
> * We need to mark the transaction as prepared, so that we
> don't resend it on
> warning: 1 line adds whitespace errors.
>
> Whitespace issue.
>
> 2.
> /*
> + * Set snapshot type
> + */
> +void
> +SetSnapBuildType(SnapBuild *builder, bool need_full_snapshot)
>
> There is no caller which passes the second parameter as false, so why
> have it? Can't we have a function with SetSnapBuildFullSnapshot or
> something like that?
>
> 3.
> @@ -431,6 +431,10 @@ CreateInitDecodingContext(const char *plugin,
> startup_cb_wrapper(ctx, &ctx->options, true);
> MemoryContextSwitchTo(old_context);
>
> + /* If two-phase is on, then only full snapshot can be used */
> + if (ctx->twophase)
> + SetSnapBuildType(ctx->snapshot_builder, true);
> +
> ctx->reorder->output_rewrites = ctx->options.receive_rewrites;
>
> return ctx;
> @@ -534,6 +538,10 @@ CreateDecodingContext(XLogRecPtr start_lsn,
>
> ctx->reorder->output_rewrites = ctx->options.receive_rewrites;
>
> + /* If two-phase is on, then only full snapshot can be used */
> + if (ctx->twophase)
> + SetSnapBuildType(ctx->snapshot_builder, true);
>
> I think it is better to add a detailed comment on why we are doing
> this? You can write the comment in one of the places.
>

Few more comments:
==================
1. I think you need to update the examples in the docs as well [1].
2. Also the text in the description of begin_prepare_cb [2] needs some
adjustment. We can say something on lines that if users want they can
check if the same GID exists and then they can either error out or
take appropriate action based on their need.

[1] - https://www.postgresql.org/docs/devel/logicaldecoding-example.html
[2] - https://www.postgresql.org/docs/devel/logicaldecoding-output-plugin.html

--
With Regards,
Amit Kapila.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2021-02-20 10:33:22 Re: [PATCH] pg_hba.conf error messages for logical replication connections
Previous Message Michael J. Baars 2021-02-20 09:27:20 computing dT from an interval