From 126eaef651ec96a48b18a111aa888b9be46e16fa Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 3 May 2005 19:42:41 +0000 Subject: [PATCH] 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. --- src/backend/access/heap/heapam.c | 6 +- src/backend/access/transam/multixact.c | 77 ++++++++++++++------------ src/include/access/multixact.h | 8 +-- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 06b1fdb644..60f744001f 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -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; } } diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index de1a88205f..628107634b 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -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) diff --git a/src/include/access/multixact.h b/src/include/access/multixact.h index 1eafddbe83..65d19704c4 100644 --- a/src/include/access/multixact.h +++ b/src/include/access/multixact.h @@ -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);