Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a50d976

Browse files
committed
Wrap multixact/members correctly during extension
In the 9.2 code for extending multixact/members, the logic was very simple because the number of entries in a members page was a proper divisor of 2^32, and thus at 2^32 wraparound the logic for page switch was identical than at any other page boundary. In commit 0ac5ad5 I failed to realize this and introduced code that was not able to go over the 2^32 boundary. Fix that by ensuring that when we reach the last page of the last segment we correctly zero the initial page of the initial segment, using correct uint32-wraparound-safe arithmetic. Noticed while investigating bug #8673 reported by Serge Negodyuck, as diagnosed by Andres Freund.
1 parent 722acf5 commit a50d976

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/backend/access/transam/multixact.c

+19-5
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,6 @@ ExtendMultiXactMember(MultiXactOffset offset, int nmembers)
22592259
{
22602260
int flagsoff;
22612261
int flagsbit;
2262-
int difference;
22632262

22642263
/*
22652264
* Only zero when at first entry of a page.
@@ -2280,10 +2279,25 @@ ExtendMultiXactMember(MultiXactOffset offset, int nmembers)
22802279
LWLockRelease(MultiXactMemberControlLock);
22812280
}
22822281

2283-
/* Advance to next page (OK if nmembers goes negative) */
2284-
difference = MULTIXACT_MEMBERS_PER_PAGE - offset % MULTIXACT_MEMBERS_PER_PAGE;
2285-
offset += difference;
2286-
nmembers -= difference;
2282+
/*
2283+
* Advance to next page, taking care to properly handle the wraparound
2284+
* case. OK if nmembers goes negative.
2285+
*/
2286+
if ((unsigned int) (offset + nmembers) < offset)
2287+
{
2288+
uint32 difference = offset + MULTIXACT_MEMBERS_PER_PAGE;
2289+
2290+
nmembers -= (unsigned int) (MULTIXACT_MEMBERS_PER_PAGE - difference);
2291+
offset = 0;
2292+
}
2293+
else
2294+
{
2295+
int difference;
2296+
2297+
difference = MULTIXACT_MEMBERS_PER_PAGE - offset % MULTIXACT_MEMBERS_PER_PAGE;
2298+
nmembers -= difference;
2299+
offset += difference;
2300+
}
22872301
}
22882302
}
22892303

0 commit comments

Comments
 (0)