Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb0b263b

Browse files
committed
Wrap multixact/members correctly during extension, take 2
Ina50d976 I already changed this, but got it wrong for the casewhere the number of members is larger than the number of entries thatfit in the last page of the last segment.As reported by Serge Negodyuck in a followup to bug #8673.
1 parentfe7337f commitb0b263b

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

‎src/backend/access/transam/multixact.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@
133133
#defineMULTIXACT_MEMBERS_PER_PAGE\
134134
(MULTIXACT_MEMBERGROUPS_PER_PAGE * MULTIXACT_MEMBERS_PER_MEMBERGROUP)
135135

136+
/*
137+
* Because the number of items per page is not a divisor of the last item
138+
* number (member 0xFFFFFFFF), the last segment does not use the maximum number
139+
* of pages, and moreover the last used page therein does not use the same
140+
* number of items as previous pages. (Another way to say it is that the
141+
* 0xFFFFFFFF member is somewhere in the middle of the last page, so the page
142+
* has some empty space after that item.)
143+
*
144+
* This constant is the number of members in the last page of the last segment.
145+
*/
146+
#defineMAX_MEMBERS_IN_LAST_MEMBERS_PAGE \
147+
((uint32) ((0xFFFFFFFF % MULTIXACT_MEMBERS_PER_PAGE) + 1))
148+
136149
/* page in which a member is to be found */
137150
#defineMXOffsetToMemberPage(xid) ((xid) / (TransactionId) MULTIXACT_MEMBERS_PER_PAGE)
138151

@@ -2278,6 +2291,7 @@ ExtendMultiXactMember(MultiXactOffset offset, int nmembers)
22782291
{
22792292
intflagsoff;
22802293
intflagsbit;
2294+
uint32difference;
22812295

22822296
/*
22832297
* Only zero when at first entry of a page.
@@ -2299,24 +2313,29 @@ ExtendMultiXactMember(MultiXactOffset offset, int nmembers)
22992313
}
23002314

23012315
/*
2302-
* Advance to next page, taking care to properly handle the wraparound
2303-
* case. OK if nmembers goes negative.
2316+
* Compute the number of items till end of current page. Careful: if
2317+
* addition of unsigned ints wraps around, we're at the last page of
2318+
* the last segment; since that page holds a different number of items
2319+
* than other pages, we need to do it differently.
23042320
*/
2305-
if ((unsignedint) (offset+nmembers)<offset)
2321+
if (offset+MAX_MEMBERS_IN_LAST_MEMBERS_PAGE<offset)
23062322
{
2307-
uint32difference=offset+MULTIXACT_MEMBERS_PER_PAGE;
2308-
2309-
nmembers-= (unsignedint) (MULTIXACT_MEMBERS_PER_PAGE-difference);
2310-
offset=0;
2323+
/*
2324+
* This is the last page of the last segment; we can compute the
2325+
* number of items left to allocate in it without modulo
2326+
* arithmetic.
2327+
*/
2328+
difference=MaxMultiXactOffset-offset+1;
23112329
}
23122330
else
2313-
{
2314-
intdifference;
2315-
23162331
difference=MULTIXACT_MEMBERS_PER_PAGE-offset %MULTIXACT_MEMBERS_PER_PAGE;
2317-
nmembers-=difference;
2318-
offset+=difference;
2319-
}
2332+
2333+
/*
2334+
* Advance to next page, taking care to properly handle the wraparound
2335+
* case. OK if nmembers goes negative.
2336+
*/
2337+
nmembers-=difference;
2338+
offset+=difference;
23202339
}
23212340
}
23222341

‎src/include/access/multixact.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#defineMultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId)
2727

28+
#defineMaxMultiXactOffset((MultiXactOffset) 0xFFFFFFFF)
29+
2830
/* Number of SLRU buffers to use for multixact */
2931
#defineNUM_MXACTOFFSET_BUFFERS8
3032
#defineNUM_MXACTMEMBER_BUFFERS16

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp