From: Heikki Linnakangas Date: Mon, 12 May 2014 13:02:06 +0000 (+0300) Subject: Get rid of the separate TransactionIdAsyncCommitTree function X-Git-Url: http://git.postgresql.org/gitweb/-?a=commitdiff_plain;h=8c0d41ff79728393a52e0ecffcec6aa2e275b73a;p=users%2Fheikki%2Fpostgres.git Get rid of the separate TransactionIdAsyncCommitTree function --- diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c index a14b5ce587..11ca7173a9 100644 --- a/src/backend/access/transam/transam.c +++ b/src/backend/access/transam/transam.c @@ -79,6 +79,11 @@ TransactionIdGetCommitLSN(TransactionId transactionId) { XactLockTableWait(transactionId, NULL, NULL, XLTW_None); commitlsn = CLogGetCommitLSN(transactionId); + + /* + * FIXME: It's possible that the backend crashed and left the + * clog in COMMITTING state. + */ Assert(!COMMITLSN_IS_COMMITTING(commitlsn)); } @@ -105,7 +110,6 @@ TransactionIdGetCommitLSN(TransactionId transactionId) * a specified transaction id. * * TransactionIdCommitTree - * TransactionIdAsyncCommitTree * TransactionIdAbortTree * ======== * these functions set the transaction status of the specified @@ -252,19 +256,6 @@ TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId *xids, XLogR TransactionIdSetCommitLSN(xid, nxids, xids, lsn); } -/* - * TransactionIdAsyncCommitTree - * Same as above, but for async commits. The commit record LSN is needed. - * - * XXX: there is no difference ATM - */ -void -TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId *xids, - XLogRecPtr lsn) -{ - TransactionIdSetCommitLSN(xid, nxids, xids, lsn); -} - /* * TransactionIdAbortTree * Marks the given transaction and children as aborted. diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 76e33e1fbc..95f5953070 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -263,7 +263,7 @@ static void CleanupTransaction(void); static void CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType); static void CommitTransaction(void); -static TransactionId RecordTransactionAbort(bool isSubXact); +static void RecordTransactionAbort(bool isSubXact); static void StartTransaction(void); static void StartSubTransaction(void); @@ -906,16 +906,12 @@ AtSubStart_ResourceOwner(void) /* * RecordTransactionCommit - * - * Returns latest XID among xact and its children, or InvalidTransactionId - * if the xact has no XID. (We compute that here just because it's easier.) */ -static TransactionId +static void RecordTransactionCommit(void) { TransactionId xid = GetTopTransactionIdIfAny(); bool markXidCommitted = TransactionIdIsValid(xid); - TransactionId latestXid = InvalidTransactionId; int nrels; RelFileNode *rels; int nchildren; @@ -1119,12 +1115,6 @@ RecordTransactionCommit(void) forceSyncCommit || nrels > 0) { XLogFlush(XactLastRecEnd); - - /* - * Now we may update the CLOG, if we wrote a COMMIT record above - */ - if (markXidCommitted) - TransactionIdCommitTree(xid, nchildren, children, XactLastRecEnd); } else { @@ -1140,16 +1130,14 @@ RecordTransactionCommit(void) * flush this commit. */ XLogSetAsyncXactLSN(XactLastRecEnd); - - /* - * We must not immediately update the CLOG, since we didn't flush the - * XLOG. Instead, we store the LSN up to which the XLOG must be - * flushed before the CLOG may be updated. - */ - if (markXidCommitted) - TransactionIdAsyncCommitTree(xid, nchildren, children, XactLastRecEnd); } + /* + * Now we may update the CLOG, if we wrote a COMMIT record above + */ + if (markXidCommitted) + TransactionIdCommitTree(xid, nchildren, children, XactLastRecEnd); + /* * If we entered a commit critical section, leave it now, and let * checkpoints proceed. @@ -1160,9 +1148,6 @@ RecordTransactionCommit(void) END_CRIT_SECTION(); } - /* Compute latestXid while we have the child XIDs handy */ - latestXid = TransactionIdLatest(xid, nchildren, children); - /* * Wait for synchronous replication, if required. * @@ -1179,8 +1164,6 @@ cleanup: /* Clean up local data */ if (rels) pfree(rels); - - return latestXid; } @@ -1348,15 +1331,11 @@ AtSubCommit_childXids(void) /* * RecordTransactionAbort - * - * Returns latest XID among xact and its children, or InvalidTransactionId - * if the xact has no XID. (We compute that here just because it's easier.) */ -static TransactionId +static void RecordTransactionAbort(bool isSubXact) { TransactionId xid = GetCurrentTransactionIdIfAny(); - TransactionId latestXid; int nrels; RelFileNode *rels; int nchildren; @@ -1376,7 +1355,7 @@ RecordTransactionAbort(bool isSubXact) /* Reset XactLastRecEnd until the next transaction writes something */ if (!isSubXact) XactLastRecEnd = 0; - return InvalidTransactionId; + return; } /* @@ -1460,9 +1439,6 @@ RecordTransactionAbort(bool isSubXact) END_CRIT_SECTION(); - /* Compute latestXid while we have the child XIDs handy */ - latestXid = TransactionIdLatest(xid, nchildren, children); - /* Reset XactLastRecEnd until the next transaction writes something */ if (!isSubXact) XactLastRecEnd = 0; @@ -1470,8 +1446,6 @@ RecordTransactionAbort(bool isSubXact) /* And clean up local data */ if (rels) pfree(rels); - - return latestXid; } /* @@ -1856,7 +1830,7 @@ CommitTransaction(void) /* * Here is where we really truly commit. */ - (void) RecordTransactionCommit(); + RecordTransactionCommit(); TRACE_POSTGRESQL_TRANSACTION_COMMIT(MyProc->lxid); @@ -4628,15 +4602,16 @@ xact_redo_commit_internal(TransactionId xid, XLogRecPtr lsn, RecordKnownAssignedTransactionIds(max_xid); /* - * Mark the transaction committed in pg_clog. We use async commit - * protocol during recovery to provide information on database - * consistency for when users try to set hint bits. It is important + * Mark the transaction committed in pg_clog. Note that this is + * analogous to an asynchronous commit, as we haven't updated + * minRecoveryPoint to the commit record yet. It is important * that we do not set hint bits until the minRecoveryPoint is past * this commit record. This ensures that if we crash we don't see hint * bits set on changes made by transactions that haven't yet * recovered. It's unlikely but it's good to be safe. */ - TransactionIdAsyncCommitTree(xid, nsubxacts, sub_xids, lsn); + TransactionIdSetCommitting(xid, nsubxacts, sub_xids); + TransactionIdCommitTree(xid, nsubxacts, sub_xids, lsn); /* * Send any cache invalidations attached to the commit. We must diff --git a/src/include/access/transam.h b/src/include/access/transam.h index e66da46fca..9748ea734d 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -178,7 +178,6 @@ extern void TransactionIdSetCommitting(TransactionId xid, int nsubxids, TransactionId *subxids); extern void TransactionIdAbort(TransactionId transactionId); extern void TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId *xids, XLogRecPtr lsn); -extern void TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId *xids, XLogRecPtr lsn); extern void TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId *xids); extern bool TransactionIdPrecedes(TransactionId id1, TransactionId id2); extern bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2);