Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

transam.c File Reference

#include "postgres.h"
#include "access/clog.h"
#include "access/subtrans.h"
#include "access/transam.h"
#include "utils/snapmgr.h"
Include dependency graph for transam.c:

Go to the source code of this file.

Functions

static XidStatus TransactionLogFetch (TransactionId transactionId)
bool TransactionIdDidCommit (TransactionId transactionId)
bool TransactionIdDidAbort (TransactionId transactionId)
bool TransactionIdIsKnownCompleted (TransactionId transactionId)
void TransactionIdCommitTree (TransactionId xid, int nxids, TransactionId *xids)
void TransactionIdAsyncCommitTree (TransactionId xid, int nxids, TransactionId *xids, XLogRecPtr lsn)
void TransactionIdAbortTree (TransactionId xid, int nxids, TransactionId *xids)
bool TransactionIdPrecedes (TransactionId id1, TransactionId id2)
bool TransactionIdPrecedesOrEquals (TransactionId id1, TransactionId id2)
bool TransactionIdFollows (TransactionId id1, TransactionId id2)
bool TransactionIdFollowsOrEquals (TransactionId id1, TransactionId id2)
TransactionId TransactionIdLatest (TransactionId mainxid, int nxids, const TransactionId *xids)
XLogRecPtr TransactionIdGetCommitLSN (TransactionId xid)

Variables

static TransactionId cachedFetchXid = InvalidTransactionId
static XidStatus cachedFetchXidStatus
static XLogRecPtr cachedCommitLSN

Function Documentation

void TransactionIdAbortTree ( TransactionId  xid,
int  nxids,
TransactionId xids 
)
void TransactionIdAsyncCommitTree ( TransactionId  xid,
int  nxids,
TransactionId xids,
XLogRecPtr  lsn 
)
void TransactionIdCommitTree ( TransactionId  xid,
int  nxids,
TransactionId xids 
)
bool TransactionIdDidAbort ( TransactionId  transactionId  ) 

Definition at line 181 of file transam.c.

References elog, SubTransGetParent(), TRANSACTION_STATUS_ABORTED, TRANSACTION_STATUS_SUB_COMMITTED, TransactionIdDidAbort(), TransactionIdIsValid, TransactionIdPrecedes(), TransactionLogFetch(), TransactionXmin, and WARNING.

Referenced by asyncQueueProcessPageEntries(), compute_new_xmax_infomask(), heap_lock_updated_tuple_rec(), heap_update(), MultiXactIdGetUpdateXid(), ProcArrayApplyRecoveryInfo(), RecoverPreparedTransactions(), StandbyAcquireAccessExclusiveLock(), StandbyRecoverPreparedTransactions(), TransactionIdDidAbort(), and TransactionIdIsInProgress().

{
    XidStatus   xidstatus;

    xidstatus = TransactionLogFetch(transactionId);

    /*
     * If it's marked aborted, it's aborted.
     */
    if (xidstatus == TRANSACTION_STATUS_ABORTED)
        return true;

    /*
     * If it's marked subcommitted, we have to check the parent recursively.
     * However, if it's older than TransactionXmin, we can't look at
     * pg_subtrans; instead assume that the parent crashed without cleaning up
     * its children.
     */
    if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
    {
        TransactionId parentXid;

        if (TransactionIdPrecedes(transactionId, TransactionXmin))
            return true;
        parentXid = SubTransGetParent(transactionId);
        if (!TransactionIdIsValid(parentXid))
        {
            /* see notes in TransactionIdDidCommit */
            elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
                 transactionId);
            return true;
        }
        return TransactionIdDidAbort(parentXid);
    }

    /*
     * It's not aborted.
     */
    return false;
}

bool TransactionIdDidCommit ( TransactionId  transactionId  ) 

Definition at line 125 of file transam.c.

References elog, SubTransGetParent(), TRANSACTION_STATUS_COMMITTED, TRANSACTION_STATUS_SUB_COMMITTED, TransactionIdDidCommit(), TransactionIdIsValid, TransactionIdPrecedes(), TransactionLogFetch(), TransactionXmin, and WARNING.

Referenced by asyncQueueProcessPageEntries(), compute_new_xmax_infomask(), heap_lock_updated_tuple_rec(), HeapTupleHeaderAdvanceLatestRemovedXid(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesNow(), HeapTupleSatisfiesSelf(), HeapTupleSatisfiesToast(), HeapTupleSatisfiesUpdate(), HeapTupleSatisfiesVacuum(), MultiXactIdExpand(), ProcArrayApplyRecoveryInfo(), RecordTransactionAbort(), RecordTransactionAbortPrepared(), RecoverPreparedTransactions(), StandbyAcquireAccessExclusiveLock(), StandbyRecoverPreparedTransactions(), TransactionIdDidCommit(), and UpdateXmaxHintBits().

{
    XidStatus   xidstatus;

    xidstatus = TransactionLogFetch(transactionId);

    /*
     * If it's marked committed, it's committed.
     */
    if (xidstatus == TRANSACTION_STATUS_COMMITTED)
        return true;

    /*
     * If it's marked subcommitted, we have to check the parent recursively.
     * However, if it's older than TransactionXmin, we can't look at
     * pg_subtrans; instead assume that the parent crashed without cleaning up
     * its children.
     *
     * Originally we Assert'ed that the result of SubTransGetParent was not
     * zero. However with the introduction of prepared transactions, there can
     * be a window just after database startup where we do not have complete
     * knowledge in pg_subtrans of the transactions after TransactionXmin.
     * StartupSUBTRANS() has ensured that any missing information will be
     * zeroed.  Since this case should not happen under normal conditions, it
     * seems reasonable to emit a WARNING for it.
     */
    if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
    {
        TransactionId parentXid;

        if (TransactionIdPrecedes(transactionId, TransactionXmin))
            return false;
        parentXid = SubTransGetParent(transactionId);
        if (!TransactionIdIsValid(parentXid))
        {
            elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
                 transactionId);
            return false;
        }
        return TransactionIdDidCommit(parentXid);
    }

    /*
     * It's not committed.
     */
    return false;
}

bool TransactionIdFollows ( TransactionId  id1,
TransactionId  id2 
)
bool TransactionIdFollowsOrEquals ( TransactionId  id1,
TransactionId  id2 
)
XLogRecPtr TransactionIdGetCommitLSN ( TransactionId  xid  ) 

Definition at line 402 of file transam.c.

References cachedCommitLSN, cachedFetchXid, TransactionIdEquals, TransactionIdGetStatus(), and TransactionIdIsNormal.

Referenced by SetHintBits().

{
    XLogRecPtr  result;

    /*
     * Currently, all uses of this function are for xids that were just
     * reported to be committed by TransactionLogFetch, so we expect that
     * checking TransactionLogFetch's cache will usually succeed and avoid an
     * extra trip to shared memory.
     */
    if (TransactionIdEquals(xid, cachedFetchXid))
        return cachedCommitLSN;

    /* Special XIDs are always known committed */
    if (!TransactionIdIsNormal(xid))
        return InvalidXLogRecPtr;

    /*
     * Get the transaction status.
     */
    (void) TransactionIdGetStatus(xid, &result);

    return result;
}

bool TransactionIdIsKnownCompleted ( TransactionId  transactionId  ) 

Definition at line 238 of file transam.c.

References cachedFetchXid, and TransactionIdEquals.

Referenced by TransactionIdIsInProgress().

{
    if (TransactionIdEquals(transactionId, cachedFetchXid))
    {
        /* If it's in the cache at all, it must be completed. */
        return true;
    }

    return false;
}

TransactionId TransactionIdLatest ( TransactionId  mainxid,
int  nxids,
const TransactionId xids 
)

Definition at line 365 of file transam.c.

References TransactionIdPrecedes().

Referenced by FinishPreparedTransaction(), ProcArrayApplyXidAssignment(), RecordTransactionAbort(), RecordTransactionCommit(), xact_redo_abort(), and xact_redo_commit_internal().

{
    TransactionId result;

    /*
     * In practice it is highly likely that the xids[] array is sorted, and so
     * we could save some cycles by just taking the last child XID, but this
     * probably isn't so performance-critical that it's worth depending on
     * that assumption.  But just to show we're not totally stupid, scan the
     * array back-to-front to avoid useless assignments.
     */
    result = mainxid;
    while (--nxids >= 0)
    {
        if (TransactionIdPrecedes(result, xids[nxids]))
            result = xids[nxids];
    }
    return result;
}

bool TransactionIdPrecedes ( TransactionId  id1,
TransactionId  id2 
)

Definition at line 300 of file transam.c.

References TransactionIdIsNormal.

Referenced by _bt_page_recyclable(), CheckForSerializableConflictOut(), CheckTargetForConflictsIn(), CLOGPagePrecedes(), convert_xid(), copy_heap_data(), do_start_worker(), ExpireTreeKnownAssignedTransactionIds(), ExportSnapshot(), get_relation_info(), GetOldestActiveTransactionId(), GetOldestXmin(), GetRunningTransactionData(), GetSnapshotData(), heap_freeze_tuple(), heap_page_is_all_visible(), heap_prune_record_prunable(), heap_tuple_needs_freeze(), HeapTupleHeaderAdvanceLatestRemovedXid(), HeapTupleIsSurelyDead(), HeapTupleSatisfiesVacuum(), KnownAssignedXidsAdd(), KnownAssignedXidsGetAndSetXmin(), KnownAssignedXidsSearch(), lazy_scan_heap(), multixact_redo(), OldSerXidAdd(), OldSerXidGetMinConflictCommitSeqNo(), OldSerXidSetActiveSerXmin(), PrescanPreparedTransactions(), ProcArrayApplyRecoveryInfo(), ProcArrayApplyXidAssignment(), ProcArrayEndTransaction(), ProcArrayRemove(), relation_needs_vacanalyze(), rewrite_heap_tuple(), SetNewSxactGlobalXmin(), SubTransGetTopmostTransaction(), SubTransPagePrecedes(), TransactionIdDidAbort(), TransactionIdDidCommit(), TransactionIdIsActive(), TransactionIdIsCurrentTransactionId(), TransactionIdIsInProgress(), TransactionIdLatest(), vac_truncate_clog(), vac_update_datfrozenxid(), vac_update_relstats(), vacuum_set_xid_limits(), vacuumRedirectAndPlaceholder(), XidCacheRemoveRunningXids(), XidInMVCCSnapshot(), XidIsConcurrent(), and xlog_redo().

{
    /*
     * If either ID is a permanent XID then we can just do unsigned
     * comparison.  If both are normal, do a modulo-2^31 comparison.
     */
    int32       diff;

    if (!TransactionIdIsNormal(id1) || !TransactionIdIsNormal(id2))
        return (id1 < id2);

    diff = (int32) (id1 - id2);
    return (diff < 0);
}

bool TransactionIdPrecedesOrEquals ( TransactionId  id1,
TransactionId  id2 
)
static XidStatus TransactionLogFetch ( TransactionId  transactionId  )  [static]

Definition at line 52 of file transam.c.

References BootstrapTransactionId, cachedCommitLSN, cachedFetchXid, cachedFetchXidStatus, FrozenTransactionId, TRANSACTION_STATUS_IN_PROGRESS, TRANSACTION_STATUS_SUB_COMMITTED, TransactionIdEquals, TransactionIdGetStatus(), and TransactionIdIsNormal.

Referenced by TransactionIdDidAbort(), and TransactionIdDidCommit().

{
    XidStatus   xidstatus;
    XLogRecPtr  xidlsn;

    /*
     * Before going to the commit log manager, check our single item cache to
     * see if we didn't just check the transaction status a moment ago.
     */
    if (TransactionIdEquals(transactionId, cachedFetchXid))
        return cachedFetchXidStatus;

    /*
     * Also, check to see if the transaction ID is a permanent one.
     */
    if (!TransactionIdIsNormal(transactionId))
    {
        if (TransactionIdEquals(transactionId, BootstrapTransactionId))
            return TRANSACTION_STATUS_COMMITTED;
        if (TransactionIdEquals(transactionId, FrozenTransactionId))
            return TRANSACTION_STATUS_COMMITTED;
        return TRANSACTION_STATUS_ABORTED;
    }

    /*
     * Get the transaction status.
     */
    xidstatus = TransactionIdGetStatus(transactionId, &xidlsn);

    /*
     * Cache it, but DO NOT cache status for unfinished or sub-committed
     * transactions!  We only cache status that is guaranteed not to change.
     */
    if (xidstatus != TRANSACTION_STATUS_IN_PROGRESS &&
        xidstatus != TRANSACTION_STATUS_SUB_COMMITTED)
    {
        cachedFetchXid = transactionId;
        cachedFetchXidStatus = xidstatus;
        cachedCommitLSN = xidlsn;
    }

    return xidstatus;
}


Variable Documentation

Definition at line 35 of file transam.c.

Referenced by TransactionIdGetCommitLSN(), and TransactionLogFetch().

TransactionId cachedFetchXid = InvalidTransactionId [static]

Definition at line 34 of file transam.c.

Referenced by TransactionLogFetch().