]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Correct StartupSUBTRANS for page wraparound
authorSimon Riggs <simon@2ndQuadrant.com>
Fri, 19 Feb 2016 08:35:02 +0000 (08:35 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Fri, 19 Feb 2016 08:35:02 +0000 (08:35 +0000)
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

src/backend/access/transam/subtrans.c

index 39e0f10866f37932eddf2ad62f2d3f67af2fd843..b089fc45084a06ae74e2c648e5c07065e986ef4c 100644 (file)
@@ -44,7 +44,8 @@
  * 0xFFFFFFFF/SUBTRANS_XACTS_PER_PAGE, and segment numbering at
  * 0xFFFFFFFF/SUBTRANS_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT.  We need take no
  * explicit notice of that fact in this module, except when comparing segment
- * and page numbers in TruncateSUBTRANS (see SubTransPagePrecedes).
+ * and page numbers in TruncateSUBTRANS (see SubTransPagePrecedes) and zeroing
+ * them in StartupSUBTRANS.
  */
 
 /* We need four bytes per xact */
@@ -253,6 +254,9 @@ StartupSUBTRANS(TransactionId oldestActiveXID)
        {
                (void) ZeroSUBTRANSPage(startPage);
                startPage++;
+               /* must account for wraparound */
+               if (startPage > TransactionIdToPage(MaxTransactionId))
+                       startPage=0;
        }
        (void) ZeroSUBTRANSPage(startPage);