On Sun, Oct 22, 2017 at 9:23 PM, Eric Ridge <eeb...@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

Reply via email to