Re: [HACKERS] How to determine that a TransactionId is really aborted? - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] How to determine that a TransactionId is really aborted?
Date
Msg-id CA+Tgmob9Ox142oDkhro6y+XRV_2ejBPe6OxFC6AiOuiYn__d2w@mail.gmail.com
Whole thread Raw
In response to [HACKERS] How to determine that a TransactionId is really aborted?  (Eric Ridge <eebbrr@gmail.com>)
List pgsql-hackers
On Sun, Oct 22, 2017 at 9:23 PM, Eric Ridge <eebbrr@gmail.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


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] Refactor handling of database attributes betweenpg_dump and pg_dumpall
Next
From: David Rowley
Date:
Subject: Re: [HACKERS] Removing [Merge]Append nodes which contain a single subpath