Clean up MultiXactIdExpand's API by separating out the case where we

are creating a new MultiXactId from two regular XIDs.  The original
coding was unnecessarily complicated and didn't save any code anyway.
This commit is contained in:
Tom Lane 2005-05-03 19:42:41 +00:00
parent 893b57c871
commit 126eaef651
3 changed files with 48 additions and 43 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.189 2005/04/30 19:03:32 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.190 2005/05/03 19:42:40 tgl Exp $
*
*
* INTERFACE ROUTINES
@ -2137,7 +2137,7 @@ l3:
* If the XMAX is already a MultiXactId, then we need to
* expand it to include our own TransactionId.
*/
xid = MultiXactIdExpand(xmax, true, xid);
xid = MultiXactIdExpand((MultiXactId) xmax, xid);
new_infomask |= HEAP_XMAX_IS_MULTI;
}
else if (TransactionIdIsInProgress(xmax))
@ -2165,7 +2165,7 @@ l3:
* create a new MultiXactId that includes both the old
* locker and our own TransactionId.
*/
xid = MultiXactIdExpand(xmax, false, xid);
xid = MultiXactIdCreate(xmax, xid);
new_infomask |= HEAP_XMAX_IS_MULTI;
}
}

View File

@ -31,7 +31,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.1 2005/04/28 21:47:10 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.2 2005/05/03 19:42:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -217,20 +217,46 @@ static void ExtendMultiXactMember(uint32 offset);
static void TruncateMultiXact(void);
/*
* MultiXactIdCreate
* Construct a MultiXactId representing two TransactionIds.
*
* The two XIDs must be different.
*
* NB - we don't worry about our local MultiXactId cache here, because that
* is handled by the lower-level routines.
*/
MultiXactId
MultiXactIdCreate(TransactionId xid1, TransactionId xid2)
{
MultiXactId newMulti;
TransactionId xids[2];
AssertArg(TransactionIdIsValid(xid1));
AssertArg(TransactionIdIsValid(xid2));
Assert(!TransactionIdEquals(xid1, xid2));
/*
* Note: unlike MultiXactIdExpand, we don't bother to check that both
* XIDs are still running. In typical usage, xid2 will be our own XID
* and the caller just did a check on xid1, so it'd be wasted effort.
*/
xids[0] = xid1;
xids[1] = xid2;
newMulti = CreateMultiXactId(2, xids);
debug_elog5(DEBUG2, "Create: returning %u for %u, %u",
newMulti, xid1, xid2);
return newMulti;
}
/*
* MultiXactIdExpand
* Add a TransactionId to a possibly-already-existing MultiXactId.
*
* We abuse the notation for the first argument: if "isMulti" is true, then
* it's really a MultiXactId; else it's a TransactionId. We are already
* storing MultiXactId in HeapTupleHeader's xmax so assuming the datatypes
* are equivalent is necessary anyway.
*
* If isMulti is true, then get the members of the passed MultiXactId, add
* the passed TransactionId, and create a new MultiXactId. If isMulti is
* false, then take the two TransactionIds and create a new MultiXactId with
* them. The caller must ensure that the multi and xid are different
* in the latter case.
* Add a TransactionId to a pre-existing MultiXactId.
*
* If the TransactionId is already a member of the passed MultiXactId,
* just return it as-is.
@ -243,7 +269,7 @@ static void TruncateMultiXact(void);
* is handled by the lower-level routines.
*/
MultiXactId
MultiXactIdExpand(MultiXactId multi, bool isMulti, TransactionId xid)
MultiXactIdExpand(MultiXactId multi, TransactionId xid)
{
MultiXactId newMulti;
TransactionId *members;
@ -255,30 +281,9 @@ MultiXactIdExpand(MultiXactId multi, bool isMulti, TransactionId xid)
AssertArg(MultiXactIdIsValid(multi));
AssertArg(TransactionIdIsValid(xid));
debug_elog5(DEBUG2, "Expand: received %s %u, xid %u",
isMulti ? "MultiXactId" : "TransactionId",
debug_elog4(DEBUG2, "Expand: received multi %u, xid %u",
multi, xid);
if (!isMulti)
{
/*
* The first argument is a TransactionId, not a MultiXactId.
*/
TransactionId xids[2];
Assert(!TransactionIdEquals(multi, xid));
xids[0] = multi;
xids[1] = xid;
newMulti = CreateMultiXactId(2, xids);
debug_elog5(DEBUG2, "Expand: returning %u two-elem %u/%u",
newMulti, multi, xid);
return newMulti;
}
nmembers = GetMultiXactIdMembers(multi, &members);
if (nmembers < 0)

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/access/multixact.h,v 1.1 2005/04/28 21:47:17 tgl Exp $
* $PostgreSQL: pgsql/src/include/access/multixact.h,v 1.2 2005/05/03 19:42:41 tgl Exp $
*/
#ifndef MULTIXACT_H
#define MULTIXACT_H
@ -16,10 +16,10 @@
#define MultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId)
extern void MultiXactIdWait(MultiXactId multi);
extern MultiXactId MultiXactIdExpand(MultiXactId multi, bool isMulti,
TransactionId xid);
extern MultiXactId MultiXactIdCreate(TransactionId xid1, TransactionId xid2);
extern MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid);
extern bool MultiXactIdIsRunning(MultiXactId multi);
extern void MultiXactIdWait(MultiXactId multi);
extern void MultiXactIdSetOldestMember(void);
extern void AtEOXact_MultiXact(void);