Обсуждение: XACT_EVENT for 'commit prepared'

Поиск
Список
Период
Сортировка

XACT_EVENT for 'commit prepared'

От
Xiaoran Wang
Дата:
Hi hackers, 

I found that in enum XactEvent, there is  'XACT_EVENT_PREPARE'  for 'prepare transaction', but there is no event for 'commit prepared' or 'rollback prepared'.

For the following SQL:
------------------------------------------------
begin;
create table test(a int);
PREPARE TRANSACTION 'foo';
rollback prepared 'foo';
-------------------------------------------------
When executing ' rollback prepared 'foo'; ', I expected to get 'XACT_EVENT_ABORT', but actually, 
the event type is 'XACT_EVENT_COMMIT'. 

I think XACT_EVENT_COMMIT_PREPARED and XACT_EVENT_ROLLBACK_PREPARED can be added in function 'FinishPreparedTransaction'

I'm confused why there are no related events for them. 

Re: XACT_EVENT for 'commit prepared'

От
Tom Lane
Дата:
Xiaoran Wang <fanfuxiaoran@gmail.com> writes:
> I found that in enum XactEvent, there is  'XACT_EVENT_PREPARE'  for
> 'prepare transaction', but there is no event for 'commit prepared' or
> 'rollback prepared'.

On the whole, it seems like a good idea to me that those commands
don't invoke event triggers.  It is a core principle of 2PC that
if 'prepare' succeeded, 'commit prepared' must not fail.  Invoking a
trigger during the second step would add failure cases and I'm not
sure what value it has.

            regards, tom lane



Re: XACT_EVENT for 'commit prepared'

От
Andres Freund
Дата:
Hi,

On 2024-06-07 11:19:40 -0400, Tom Lane wrote:
> Xiaoran Wang <fanfuxiaoran@gmail.com> writes:
> > I found that in enum XactEvent, there is  'XACT_EVENT_PREPARE'  for
> > 'prepare transaction', but there is no event for 'commit prepared' or
> > 'rollback prepared'.
> 
> On the whole, it seems like a good idea to me that those commands
> don't invoke event triggers.  It is a core principle of 2PC that
> if 'prepare' succeeded, 'commit prepared' must not fail.  Invoking a
> trigger during the second step would add failure cases and I'm not
> sure what value it has.

Event triggers? Isn't this about RegisterXactCallback?

XACT_EVENT_COMMIT is called after the commit record has been flushed and the
procarray has been modified. Thus a failure in the hook has somewhat limited
consequences. I'd assume XACT_EVENT_COMMIT_PREPARED would do something
similar.

I suspect the reason we don't callback for 2pc commit/rollback prepared is
simpl: The code for doing a 2pc commit prepared lives in twophase.c, not
xact.c...

Greetings,

Andres Freund