postgres.git / summary / log / commit / refs

commit    ca32f125b92c91c2abd02e25aede7b52b318f840
Author:   Simon Riggs <simon@2ndQuadrant.com>
Date:     Fri Feb 19 08:35:02 2016 +0000

    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


src/backend/access/transam/subtrans.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c index 39e0f10866f..b089fc45084 100644 --- a/src/backend/access/transam/subtrans.c +++ b/src/backend/access/transam/subtrans.c @@ -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); [parent: 0f359c7de9f5]