Skip to content

Commit 6830cae

Browse files
Correct StartupSUBTRANS for page wraparound
StartupSUBTRANS() incorrectly handled cases near the max pageid in the subtrans data structure, which in some cases could lead to errors in startup for Hot Standby. This patch wraps the pageids correctly, avoiding any such errors. Identified by exhaustive crash testing by Jeff Janes. Jeff Janes
1 parent bec4d0f commit 6830cae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backend/access/transam/subtrans.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
* 0xFFFFFFFF/SUBTRANS_XACTS_PER_PAGE, and segment numbering at
4545
* 0xFFFFFFFF/SUBTRANS_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT. We need take no
4646
* explicit notice of that fact in this module, except when comparing segment
47-
* and page numbers in TruncateSUBTRANS (see SubTransPagePrecedes).
47+
* and page numbers in TruncateSUBTRANS (see SubTransPagePrecedes) and zeroing
48+
* them in StartupSUBTRANS.
4849
*/
4950

5051
/* We need four bytes per xact */
@@ -253,6 +254,9 @@ StartupSUBTRANS(TransactionId oldestActiveXID)
253254
{
254255
(void) ZeroSUBTRANSPage(startPage);
255256
startPage++;
257+
/* must account for wraparound */
258+
if (startPage > TransactionIdToPage(MaxTransactionId))
259+
startPage=0;
256260
}
257261
(void) ZeroSUBTRANSPage(startPage);
258262

0 commit comments

Comments
 (0)