Re: How to determine that a TransactionId is really aborted?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Eric Ridge <eebbrr(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to determine that a TransactionId is really aborted?
Date: 2017-10-26 11:14:33
Message-ID: CA+Tgmob9Ox142oDkhro6y+XRV_2ejBPe6OxFC6AiOuiYn__d2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Oct 22, 2017 at 9:23 PM, Eric Ridge <eebbrr(at)gmail(dot)com> wrote:
> When sitting inside an extension, and given an arbitrary TransactionId, how can you determine that it aborted/crashed *and* that no other active transaction thinks it is still running?
>
> I've tried to answer this question myself (against the 9.3 sources), and it seems like it's just:
>
> {
> TransactionId oldestXmin = GetOldestXmin (false, false);
> TransactionId xid = 42;
>
> if (TransactionIdPrecedes(xid, oldestXmin) &&
> !TransactionIdDidCommit(xid) &&
> !TransactionIdIsInProgress(xid)) /* not even sure this is necessary? */
> {
> /* xid is aborted/crashed and no active transaction cares */
> }
> }
>
> Can anyone confirm or deny that this is correct? I feel like it is correct, but I'm no expert.

I think TransactionIdPrecedes(xid, oldestXmin) &&
!TransactionIdDidCommit(xid) is sufficient. If the transaction ID
precedes oldestXmin, then it's either committed or aborted; no other
state is possible. If it didn't commit, it aborted, and it is right
to test that using !TransactionIdDidCommit(xid) since commits are
always recorded but aborts are only usually recorded.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2017-10-26 11:17:00 Re: Removing [Merge]Append nodes which contain a single subpath
Previous Message Robert Haas 2017-10-26 11:01:32 Re: Refactor handling of database attributes between pg_dump and pg_dumpall