Skip to content

Commit 126eaef

Browse files
committed
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.
1 parent 893b57c commit 126eaef

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
lines changed

src/backend/access/heap/heapam.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.189 2005/04/30 19:03:32 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.190 2005/05/03 19:42:40 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2137,7 +2137,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
21372137
* If the XMAX is already a MultiXactId, then we need to
21382138
* expand it to include our own TransactionId.
21392139
*/
2140-
xid = MultiXactIdExpand(xmax, true, xid);
2140+
xid = MultiXactIdExpand((MultiXactId) xmax, xid);
21412141
new_infomask |= HEAP_XMAX_IS_MULTI;
21422142
}
21432143
else if (TransactionIdIsInProgress(xmax))
@@ -2165,7 +2165,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
21652165
* create a new MultiXactId that includes both the old
21662166
* locker and our own TransactionId.
21672167
*/
2168-
xid = MultiXactIdExpand(xmax, false, xid);
2168+
xid = MultiXactIdCreate(xmax, xid);
21692169
new_infomask |= HEAP_XMAX_IS_MULTI;
21702170
}
21712171
}

src/backend/access/transam/multixact.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
3232
* Portions Copyright (c) 1994, Regents of the University of California
3333
*
34-
* $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.1 2005/04/28 21:47:10 tgl Exp $
34+
* $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.2 2005/05/03 19:42:40 tgl Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -218,19 +218,45 @@ static void TruncateMultiXact(void);
218218

219219

220220
/*
221-
* MultiXactIdExpand
222-
* Add a TransactionId to a possibly-already-existing MultiXactId.
221+
* MultiXactIdCreate
222+
* Construct a MultiXactId representing two TransactionIds.
223223
*
224-
* We abuse the notation for the first argument: if "isMulti" is true, then
225-
* it's really a MultiXactId; else it's a TransactionId. We are already
226-
* storing MultiXactId in HeapTupleHeader's xmax so assuming the datatypes
227-
* are equivalent is necessary anyway.
224+
* The two XIDs must be different.
228225
*
229-
* If isMulti is true, then get the members of the passed MultiXactId, add
230-
* the passed TransactionId, and create a new MultiXactId. If isMulti is
231-
* false, then take the two TransactionIds and create a new MultiXactId with
232-
* them. The caller must ensure that the multi and xid are different
233-
* in the latter case.
226+
* NB - we don't worry about our local MultiXactId cache here, because that
227+
* is handled by the lower-level routines.
228+
*/
229+
MultiXactId
230+
MultiXactIdCreate(TransactionId xid1, TransactionId xid2)
231+
{
232+
MultiXactId newMulti;
233+
TransactionId xids[2];
234+
235+
AssertArg(TransactionIdIsValid(xid1));
236+
AssertArg(TransactionIdIsValid(xid2));
237+
238+
Assert(!TransactionIdEquals(xid1, xid2));
239+
240+
/*
241+
* Note: unlike MultiXactIdExpand, we don't bother to check that both
242+
* XIDs are still running. In typical usage, xid2 will be our own XID
243+
* and the caller just did a check on xid1, so it'd be wasted effort.
244+
*/
245+
246+
xids[0] = xid1;
247+
xids[1] = xid2;
248+
249+
newMulti = CreateMultiXactId(2, xids);
250+
251+
debug_elog5(DEBUG2, "Create: returning %u for %u, %u",
252+
newMulti, xid1, xid2);
253+
254+
return newMulti;
255+
}
256+
257+
/*
258+
* MultiXactIdExpand
259+
* Add a TransactionId to a pre-existing MultiXactId.
234260
*
235261
* If the TransactionId is already a member of the passed MultiXactId,
236262
* just return it as-is.
@@ -243,7 +269,7 @@ static void TruncateMultiXact(void);
243269
* is handled by the lower-level routines.
244270
*/
245271
MultiXactId
246-
MultiXactIdExpand(MultiXactId multi, bool isMulti, TransactionId xid)
272+
MultiXactIdExpand(MultiXactId multi, TransactionId xid)
247273
{
248274
MultiXactId newMulti;
249275
TransactionId *members;
@@ -255,30 +281,9 @@ MultiXactIdExpand(MultiXactId multi, bool isMulti, TransactionId xid)
255281
AssertArg(MultiXactIdIsValid(multi));
256282
AssertArg(TransactionIdIsValid(xid));
257283

258-
debug_elog5(DEBUG2, "Expand: received %s %u, xid %u",
259-
isMulti ? "MultiXactId" : "TransactionId",
284+
debug_elog4(DEBUG2, "Expand: received multi %u, xid %u",
260285
multi, xid);
261286

262-
if (!isMulti)
263-
{
264-
/*
265-
* The first argument is a TransactionId, not a MultiXactId.
266-
*/
267-
TransactionId xids[2];
268-
269-
Assert(!TransactionIdEquals(multi, xid));
270-
271-
xids[0] = multi;
272-
xids[1] = xid;
273-
274-
newMulti = CreateMultiXactId(2, xids);
275-
276-
debug_elog5(DEBUG2, "Expand: returning %u two-elem %u/%u",
277-
newMulti, multi, xid);
278-
279-
return newMulti;
280-
}
281-
282287
nmembers = GetMultiXactIdMembers(multi, &members);
283288

284289
if (nmembers < 0)

src/include/access/multixact.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/access/multixact.h,v 1.1 2005/04/28 21:47:17 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/access/multixact.h,v 1.2 2005/05/03 19:42:41 tgl Exp $
1010
*/
1111
#ifndef MULTIXACT_H
1212
#define MULTIXACT_H
@@ -16,10 +16,10 @@
1616

1717
#define MultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId)
1818

19-
extern void MultiXactIdWait(MultiXactId multi);
20-
extern MultiXactId MultiXactIdExpand(MultiXactId multi, bool isMulti,
21-
TransactionId xid);
19+
extern MultiXactId MultiXactIdCreate(TransactionId xid1, TransactionId xid2);
20+
extern MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid);
2221
extern bool MultiXactIdIsRunning(MultiXactId multi);
22+
extern void MultiXactIdWait(MultiXactId multi);
2323
extern void MultiXactIdSetOldestMember(void);
2424

2525
extern void AtEOXact_MultiXact(void);

0 commit comments

Comments
 (0)