Re: Transactions involving multiple postgres foreign servers, take 2

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Masahiko Sawada <masahiko(dot)sawada(at)2ndquadrant(dot)com>
Cc: Muhammad Usama <m(dot)usama(at)gmail(dot)com>, amul sul <sulamul(at)gmail(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Ildar Musin <ildar(at)adjust(dot)com>, Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, Chris Travers <chris(dot)travers(at)adjust(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, "Tsunakawa, Takayuki" <tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com>
Subject: Re: Transactions involving multiple postgres foreign servers, take 2
Date: 2020-06-11 13:21:12
Message-ID: CAA4eK1L+=xqJPgA7vGkyDuUZubgXLaUV+0uBS4CTzYM5vr7fhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 5, 2020 at 3:16 PM Masahiko Sawada
<masahiko(dot)sawada(at)2ndquadrant(dot)com> wrote:
>
> On Thu, 4 Jun 2020 at 12:46, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> >
> >
> > + <para>
> > + This parameter can be changed at any time; the behavior for any one
> > + transaction is determined by the setting in effect when it commits.
> > + </para>
> >
> > This is written w.r.t foreign_twophase_commit. If one changes this
> > between prepare and commit, will it have any impact?
>
> Since the distributed transaction commit automatically uses 2pc when
> executing COMMIT, it's not possible to change foreign_twophase_commit
> between prepare and commit. So I'd like to explain the case where a
> user executes PREPARE and then COMMIT PREPARED while changing
> foreign_twophase_commit.
>
> PREPARE can run only when foreign_twophase_commit is 'required' (or
> 'prefer') and all foreign servers involved with the transaction
> support 2pc. We prepare all foreign transactions no matter what the
> number of servers and modified or not. If either
> foreign_twophase_commit is 'disabled' or the transaction modifies data
> on a foreign server that doesn't support 2pc, it raises an error. At
> COMMIT (or ROLLBACK) PREPARED, similarly foreign_twophase_commit needs
> to be set to 'required'. It raises an error if the distributed
> transaction has a foreign transaction and foreign_twophase_commit is
> 'disabled'.
>

So, IIUC, it will raise an error if foreign_twophase_commit is
'disabled' (or one of the foreign server involved doesn't support 2PC)
and the error can be raised both when user issues PREPARE or COMMIT
(or ROLLBACK) PREPARED. If so, isn't it strange that we raise such an
error after PREPARE? What kind of use-case required this?

>
> >
> > 4.
> > + <entry><structfield>in_doubt</structfield></entry>
> > + <entry><type>boolean</type></entry>
> > + <entry></entry>
> > + <entry>
> > + If <literal>true</literal> this foreign transaction is
> > in-doubt status and
> > + needs to be resolved by calling <function>pg_resolve_fdwxact</function>
> > + function.
> > + </entry>
> >
> > It would be better if you can add an additional sentence to say when
> > and or how can foreign transactions reach in-doubt state.
> >

+ If <literal>true</literal> this foreign transaction is in-doubt status.
+ A foreign transaction becomes in-doubt status when user canceled the
+ query during transaction commit or the server crashed during transaction
+ commit.

Can we reword the second sentence as: "A foreign transaction can have
this status when the user has cancelled the statement or the server
crashes during transaction commit."? I have another question about
this field, why can't it be one of the status ('preparing',
'prepared', 'committing', 'aborting', 'in-doubt') rather than having a
separate field? Also, isn't it more suitable to name 'status' field
as 'state' because these appear to be more like different states of
transaction?

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2020-06-11 13:28:56 Re: Windows regress fails (latest HEAD)
Previous Message Andrew Dunstan 2020-06-11 13:01:52 Re: Windows regress fails (latest HEAD)