]> granicus.if.org Git - postgresql/commitdiff
Clean up MultiXactIdExpand's API by separating out the case where we
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 May 2005 19:42:41 +0000 (19:42 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 May 2005 19:42:41 +0000 (19:42 +0000)
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
src/backend/access/transam/multixact.c
src/include/access/multixact.h

index 06b1fdb644072512e47c34154ea7cfa7ec32ed77..60f744001fd34fa2c9a94a5e25ba5783b749f773 100644 (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;
                                }
                        }
index de1a88205f1d90685072f88f38104bd92e830fd2..628107634b8f71ab668e9a5c08702cb9b0bd3c56 100644 (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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -218,19 +218,45 @@ static void TruncateMultiXact(void);
 
 
 /*
- * MultiXactIdExpand
- *             Add a TransactionId to a possibly-already-existing MultiXactId.
+ * MultiXactIdCreate
+ *             Construct a MultiXactId representing two TransactionIds.
  *
- * 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.
+ * The two XIDs must be different.
  *
- * 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.
+ * 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 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)
index 1eafddbe8325c14dfe40ad5878546fc5c2449c2d..65d19704c404bb0f9e1d1f71ddbde8df8fa21339 100644 (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
 
 #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);