1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* transam.c
|
2017-05-12 17:49:56 +02:00
|
|
|
* postgres transaction (commit) log interface routines
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2018-01-03 05:30:12 +01:00
|
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/access/transam/transam.c
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
1997-09-07 07:04:48 +02:00
|
|
|
* This file contains the high level access-method interface to the
|
|
|
|
* transaction system.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-10-21 09:15:18 +02:00
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "postgres.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2001-08-25 20:52:43 +02:00
|
|
|
#include "access/clog.h"
|
2004-07-01 02:52:04 +02:00
|
|
|
#include "access/subtrans.h"
|
2000-11-21 22:16:06 +01:00
|
|
|
#include "access/transam.h"
|
2008-03-26 19:48:59 +01:00
|
|
|
#include "utils/snapmgr.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2007-08-02 00:45:09 +02:00
|
|
|
/*
|
2008-03-11 21:20:35 +01:00
|
|
|
* Single-item cache for results of TransactionLogFetch. It's worth having
|
|
|
|
* such a cache because we frequently find ourselves repeatedly checking the
|
|
|
|
* same XID, for example when scanning a table just after a bulk insert,
|
|
|
|
* update, or delete.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2004-07-01 02:52:04 +02:00
|
|
|
static TransactionId cachedFetchXid = InvalidTransactionId;
|
|
|
|
static XidStatus cachedFetchXidStatus;
|
2007-08-02 00:45:09 +02:00
|
|
|
static XLogRecPtr cachedCommitLSN;
|
|
|
|
|
2008-03-11 21:20:35 +01:00
|
|
|
/* Local functions */
|
|
|
|
static XidStatus TransactionLogFetch(TransactionId transactionId);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
2008-03-11 21:20:35 +01:00
|
|
|
* Postgres log access method interface
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2004-07-01 02:52:04 +02:00
|
|
|
* TransactionLogFetch
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
/*
|
|
|
|
* TransactionLogFetch --- fetch commit status of specified transaction id
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2004-07-01 02:52:04 +02:00
|
|
|
static XidStatus
|
|
|
|
TransactionLogFetch(TransactionId transactionId)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2004-07-01 02:52:04 +02:00
|
|
|
XidStatus xidstatus;
|
2007-08-02 00:45:09 +02:00
|
|
|
XLogRecPtr xidlsn;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* 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.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2004-07-01 02:52:04 +02:00
|
|
|
if (TransactionIdEquals(transactionId, cachedFetchXid))
|
|
|
|
return cachedFetchXidStatus;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2001-08-25 20:52:43 +02:00
|
|
|
* Also, check to see if the transaction ID is a permanent one.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2001-10-25 07:50:21 +02:00
|
|
|
if (!TransactionIdIsNormal(transactionId))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2001-08-25 20:52:43 +02:00
|
|
|
if (TransactionIdEquals(transactionId, BootstrapTransactionId))
|
2004-07-01 02:52:04 +02:00
|
|
|
return TRANSACTION_STATUS_COMMITTED;
|
2001-08-25 20:52:43 +02:00
|
|
|
if (TransactionIdEquals(transactionId, FrozenTransactionId))
|
2004-07-01 02:52:04 +02:00
|
|
|
return TRANSACTION_STATUS_COMMITTED;
|
|
|
|
return TRANSACTION_STATUS_ABORTED;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2007-08-02 00:45:09 +02:00
|
|
|
* Get the transaction status.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2007-08-02 00:45:09 +02:00
|
|
|
xidstatus = TransactionIdGetStatus(transactionId, &xidlsn);
|
2001-10-25 07:50:21 +02:00
|
|
|
|
|
|
|
/*
|
2008-03-11 21:20:35 +01:00
|
|
|
* Cache it, but DO NOT cache status for unfinished or sub-committed
|
|
|
|
* transactions! We only cache status that is guaranteed not to change.
|
2001-10-25 07:50:21 +02:00
|
|
|
*/
|
2004-07-01 02:52:04 +02:00
|
|
|
if (xidstatus != TRANSACTION_STATUS_IN_PROGRESS &&
|
|
|
|
xidstatus != TRANSACTION_STATUS_SUB_COMMITTED)
|
2001-10-25 07:50:21 +02:00
|
|
|
{
|
2007-08-02 00:45:09 +02:00
|
|
|
cachedFetchXid = transactionId;
|
2004-07-01 02:52:04 +02:00
|
|
|
cachedFetchXidStatus = xidstatus;
|
2007-08-02 00:45:09 +02:00
|
|
|
cachedCommitLSN = xidlsn;
|
2001-10-25 07:50:21 +02:00
|
|
|
}
|
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
return xidstatus;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Interface functions
|
|
|
|
*
|
2008-03-11 21:20:35 +01:00
|
|
|
* TransactionIdDidCommit
|
|
|
|
* TransactionIdDidAbort
|
1997-09-07 07:04:48 +02:00
|
|
|
* ========
|
|
|
|
* these functions test the transaction status of
|
|
|
|
* a specified transaction id.
|
|
|
|
*
|
2008-10-20 21:18:18 +02:00
|
|
|
* TransactionIdCommitTree
|
|
|
|
* TransactionIdAsyncCommitTree
|
|
|
|
* TransactionIdAbortTree
|
1997-09-07 07:04:48 +02:00
|
|
|
* ========
|
2008-10-20 21:18:18 +02:00
|
|
|
* these functions set the transaction status of the specified
|
|
|
|
* transaction tree.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2008-03-11 21:20:35 +01:00
|
|
|
* See also TransactionIdIsInProgress, which once was in this module
|
|
|
|
* but now lives in procarray.c.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* TransactionIdDidCommit
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff transaction associated with the identifier did commit.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
2017-03-23 19:08:23 +01:00
|
|
|
* Assumes transaction identifier is valid and exists in clog.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
bool /* true if given transaction committed */
|
1996-07-09 08:22:35 +02:00
|
|
|
TransactionIdDidCommit(TransactionId transactionId)
|
|
|
|
{
|
2004-07-01 02:52:04 +02:00
|
|
|
XidStatus xidstatus;
|
|
|
|
|
|
|
|
xidstatus = TransactionLogFetch(transactionId);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it's marked committed, it's committed.
|
|
|
|
*/
|
|
|
|
if (xidstatus == TRANSACTION_STATUS_COMMITTED)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* 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.
|
2005-06-18 00:32:51 +02:00
|
|
|
*
|
2005-11-22 19:17:34 +01:00
|
|
|
* 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
|
2005-10-15 04:49:52 +02:00
|
|
|
* knowledge in pg_subtrans of the transactions after TransactionXmin.
|
|
|
|
* StartupSUBTRANS() has ensured that any missing information will be
|
2014-05-06 18:12:18 +02:00
|
|
|
* zeroed. Since this case should not happen under normal conditions, it
|
2005-10-15 04:49:52 +02:00
|
|
|
* seems reasonable to emit a WARNING for it.
|
2004-07-01 02:52:04 +02:00
|
|
|
*/
|
|
|
|
if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
|
|
|
|
{
|
|
|
|
TransactionId parentXid;
|
2004-08-22 04:41:58 +02:00
|
|
|
|
2004-09-16 20:35:23 +02:00
|
|
|
if (TransactionIdPrecedes(transactionId, TransactionXmin))
|
2004-08-22 04:41:58 +02:00
|
|
|
return false;
|
2004-07-01 02:52:04 +02:00
|
|
|
parentXid = SubTransGetParent(transactionId);
|
2005-06-18 00:32:51 +02:00
|
|
|
if (!TransactionIdIsValid(parentXid))
|
|
|
|
{
|
|
|
|
elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
|
|
|
|
transactionId);
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-01 02:52:04 +02:00
|
|
|
return TransactionIdDidCommit(parentXid);
|
|
|
|
}
|
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
/*
|
2004-07-01 02:52:04 +02:00
|
|
|
* It's not committed.
|
|
|
|
*/
|
|
|
|
return false;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-25 20:52:43 +02:00
|
|
|
* TransactionIdDidAbort
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff transaction associated with the identifier did abort.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
2017-03-23 19:08:23 +01:00
|
|
|
* Assumes transaction identifier is valid and exists in clog.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
bool /* true if given transaction aborted */
|
1996-07-09 08:22:35 +02:00
|
|
|
TransactionIdDidAbort(TransactionId transactionId)
|
|
|
|
{
|
2004-07-01 02:52:04 +02:00
|
|
|
XidStatus xidstatus;
|
|
|
|
|
|
|
|
xidstatus = TransactionLogFetch(transactionId);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
/*
|
|
|
|
* If it's marked aborted, it's aborted.
|
|
|
|
*/
|
|
|
|
if (xidstatus == TRANSACTION_STATUS_ABORTED)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* 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.
|
2004-07-01 02:52:04 +02:00
|
|
|
*/
|
|
|
|
if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
|
2002-05-25 22:00:12 +02:00
|
|
|
{
|
2004-07-01 02:52:04 +02:00
|
|
|
TransactionId parentXid;
|
|
|
|
|
2004-09-16 20:35:23 +02:00
|
|
|
if (TransactionIdPrecedes(transactionId, TransactionXmin))
|
2004-08-22 04:41:58 +02:00
|
|
|
return true;
|
|
|
|
parentXid = SubTransGetParent(transactionId);
|
2005-06-18 00:32:51 +02:00
|
|
|
if (!TransactionIdIsValid(parentXid))
|
|
|
|
{
|
|
|
|
/* see notes in TransactionIdDidCommit */
|
|
|
|
elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
|
|
|
|
transactionId);
|
|
|
|
return true;
|
|
|
|
}
|
2004-08-22 04:41:58 +02:00
|
|
|
return TransactionIdDidAbort(parentXid);
|
2002-05-25 22:00:12 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
/*
|
|
|
|
* It's not aborted.
|
|
|
|
*/
|
|
|
|
return false;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2008-03-11 21:20:35 +01:00
|
|
|
/*
|
|
|
|
* TransactionIdIsKnownCompleted
|
|
|
|
* True iff transaction associated with the identifier is currently
|
|
|
|
* known to have either committed or aborted.
|
|
|
|
*
|
2017-03-17 14:46:58 +01:00
|
|
|
* This does NOT look into pg_xact but merely probes our local cache
|
2008-03-11 21:20:35 +01:00
|
|
|
* (and so it's not named TransactionIdDidComplete, which would be the
|
|
|
|
* appropriate name for a function that worked that way). The intended
|
|
|
|
* use is just to short-circuit TransactionIdIsInProgress calls when doing
|
|
|
|
* repeated tqual.c checks for the same XID. If this isn't extremely fast
|
|
|
|
* then it will be counterproductive.
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* Assumes transaction identifier is valid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2008-03-11 21:20:35 +01:00
|
|
|
bool
|
|
|
|
TransactionIdIsKnownCompleted(TransactionId transactionId)
|
|
|
|
{
|
|
|
|
if (TransactionIdEquals(transactionId, cachedFetchXid))
|
|
|
|
{
|
|
|
|
/* If it's in the cache at all, it must be completed. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
/*
|
|
|
|
* TransactionIdCommitTree
|
2008-10-20 21:18:18 +02:00
|
|
|
* Marks the given transaction and children as committed
|
2004-07-01 02:52:04 +02:00
|
|
|
*
|
2008-10-20 21:18:18 +02:00
|
|
|
* "xid" is a toplevel transaction commit, and the xids array contains its
|
|
|
|
* committed subtransactions.
|
|
|
|
*
|
|
|
|
* This commit operation is not guaranteed to be atomic, but if not, subxids
|
|
|
|
* are correctly marked subcommit first.
|
2004-07-01 02:52:04 +02:00
|
|
|
*/
|
|
|
|
void
|
2008-10-20 21:18:18 +02:00
|
|
|
TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId *xids)
|
2004-07-01 02:52:04 +02:00
|
|
|
{
|
2008-10-20 22:38:24 +02:00
|
|
|
TransactionIdSetTreeStatus(xid, nxids, xids,
|
|
|
|
TRANSACTION_STATUS_COMMITTED,
|
|
|
|
InvalidXLogRecPtr);
|
2004-07-01 02:52:04 +02:00
|
|
|
}
|
|
|
|
|
2007-08-02 00:45:09 +02:00
|
|
|
/*
|
|
|
|
* TransactionIdAsyncCommitTree
|
|
|
|
* Same as above, but for async commits. The commit record LSN is needed.
|
|
|
|
*/
|
|
|
|
void
|
2008-10-20 21:18:18 +02:00
|
|
|
TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId *xids,
|
|
|
|
XLogRecPtr lsn)
|
2007-08-02 00:45:09 +02:00
|
|
|
{
|
2008-10-20 22:38:24 +02:00
|
|
|
TransactionIdSetTreeStatus(xid, nxids, xids,
|
|
|
|
TRANSACTION_STATUS_COMMITTED, lsn);
|
2007-08-02 00:45:09 +02:00
|
|
|
}
|
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
/*
|
|
|
|
* TransactionIdAbortTree
|
2008-10-20 21:18:18 +02:00
|
|
|
* Marks the given transaction and children as aborted.
|
|
|
|
*
|
|
|
|
* "xid" is a toplevel transaction commit, and the xids array contains its
|
|
|
|
* committed subtransactions.
|
2004-07-01 02:52:04 +02:00
|
|
|
*
|
|
|
|
* We don't need to worry about the non-atomic behavior, since any onlookers
|
|
|
|
* will consider all the xacts as not-yet-committed anyway.
|
|
|
|
*/
|
|
|
|
void
|
2008-10-20 21:18:18 +02:00
|
|
|
TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId *xids)
|
2004-07-01 02:52:04 +02:00
|
|
|
{
|
2008-10-20 21:18:18 +02:00
|
|
|
TransactionIdSetTreeStatus(xid, nxids, xids,
|
|
|
|
TRANSACTION_STATUS_ABORTED, InvalidXLogRecPtr);
|
2004-07-01 02:52:04 +02:00
|
|
|
}
|
2001-08-26 18:56:03 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TransactionIdPrecedes --- is id1 logically < id2?
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
TransactionIdPrecedes(TransactionId id1, TransactionId id2)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If either ID is a permanent XID then we can just do unsigned
|
2014-05-06 18:12:18 +02:00
|
|
|
* comparison. If both are normal, do a modulo-2^32 comparison.
|
2001-08-26 18:56:03 +02:00
|
|
|
*/
|
|
|
|
int32 diff;
|
|
|
|
|
|
|
|
if (!TransactionIdIsNormal(id1) || !TransactionIdIsNormal(id2))
|
|
|
|
return (id1 < id2);
|
|
|
|
|
|
|
|
diff = (int32) (id1 - id2);
|
|
|
|
return (diff < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TransactionIdPrecedesOrEquals --- is id1 logically <= id2?
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
|
|
|
|
{
|
|
|
|
int32 diff;
|
|
|
|
|
|
|
|
if (!TransactionIdIsNormal(id1) || !TransactionIdIsNormal(id2))
|
|
|
|
return (id1 <= id2);
|
|
|
|
|
|
|
|
diff = (int32) (id1 - id2);
|
|
|
|
return (diff <= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TransactionIdFollows --- is id1 logically > id2?
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
TransactionIdFollows(TransactionId id1, TransactionId id2)
|
|
|
|
{
|
|
|
|
int32 diff;
|
|
|
|
|
|
|
|
if (!TransactionIdIsNormal(id1) || !TransactionIdIsNormal(id2))
|
|
|
|
return (id1 > id2);
|
|
|
|
|
|
|
|
diff = (int32) (id1 - id2);
|
|
|
|
return (diff > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TransactionIdFollowsOrEquals --- is id1 logically >= id2?
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
|
|
|
|
{
|
|
|
|
int32 diff;
|
|
|
|
|
|
|
|
if (!TransactionIdIsNormal(id1) || !TransactionIdIsNormal(id2))
|
|
|
|
return (id1 >= id2);
|
|
|
|
|
|
|
|
diff = (int32) (id1 - id2);
|
|
|
|
return (diff >= 0);
|
|
|
|
}
|
2007-08-02 00:45:09 +02:00
|
|
|
|
2007-09-08 22:31:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TransactionIdLatest --- get latest XID among a main xact and its children
|
|
|
|
*/
|
|
|
|
TransactionId
|
|
|
|
TransactionIdLatest(TransactionId mainxid,
|
|
|
|
int nxids, const TransactionId *xids)
|
|
|
|
{
|
2007-11-15 22:14:46 +01:00
|
|
|
TransactionId result;
|
2007-09-08 22:31:15 +02:00
|
|
|
|
|
|
|
/*
|
2007-11-15 22:14:46 +01:00
|
|
|
* 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.
|
2007-09-08 22:31:15 +02:00
|
|
|
*/
|
|
|
|
result = mainxid;
|
|
|
|
while (--nxids >= 0)
|
|
|
|
{
|
|
|
|
if (TransactionIdPrecedes(result, xids[nxids]))
|
|
|
|
result = xids[nxids];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-02 00:45:09 +02:00
|
|
|
/*
|
|
|
|
* TransactionIdGetCommitLSN
|
|
|
|
*
|
|
|
|
* This function returns an LSN that is late enough to be able
|
|
|
|
* to guarantee that if we flush up to the LSN returned then we
|
|
|
|
* will have flushed the transaction's commit record to disk.
|
|
|
|
*
|
|
|
|
* The result is not necessarily the exact LSN of the transaction's
|
|
|
|
* commit record! For example, for long-past transactions (those whose
|
|
|
|
* clog pages already migrated to disk), we'll return InvalidXLogRecPtr.
|
|
|
|
* Also, because we group transactions on the same clog page to conserve
|
|
|
|
* storage, we might return the LSN of a later transaction that falls into
|
|
|
|
* the same group.
|
|
|
|
*/
|
|
|
|
XLogRecPtr
|
|
|
|
TransactionIdGetCommitLSN(TransactionId xid)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|