From b09762726f3c8309c073c5511fb1d9a13f11fef9 Mon Sep 17 00:00:00 2001 From: alterego655 <824662526@qq.com> Date: Fri, 23 Oct 2026 20:35:57 +0800 Subject: [PATCH v1 2/2] Fix a WAL timeline assertion and simplify timeline handling Allow reads ending exactly at currTLIValidUntil, since that limit is exclusive. Change the assertion from < to <=. Remove the redundant local tli variable and pass state->currTLI directly to WALRead(). Also remove the redundant readLen == 0 check from the page-length assertion. --- src/backend/access/transam/xlogutils.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 1d034944465..d7429c42f64 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -735,7 +735,7 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, Assert(XLogRecPtrIsValid(wantPage) && wantPage % XLOG_BLCKSZ == 0); Assert(wantLength <= XLOG_BLCKSZ); - Assert(state->readLen == 0 || state->readLen <= XLOG_BLCKSZ); + Assert(state->readLen <= XLOG_BLCKSZ); Assert(currTLI != 0); /* @@ -815,7 +815,7 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, &state->nextTLI); Assert(!XLogRecPtrIsValid(state->currTLIValidUntil) || - wantPage + wantLength < state->currTLIValidUntil); + wantPage + wantLength <= state->currTLIValidUntil); list_free_deep(timelineHistory); @@ -899,7 +899,6 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr, { XLogRecPtr read_upto, loc; - TimeLineID tli; int count; WALReadError errinfo; TimeLineID currTLI; @@ -936,7 +935,6 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr, if (insertTLI != 0) currTLI = insertTLI; } - tli = currTLI; /* * Check which timeline to get the record from. @@ -959,7 +957,7 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr, * and fail with an ERROR. We don't retry the open here. An * already-open file remains usable after the rename. */ - XLogReadDetermineTimeline(state, targetPagePtr, reqLen, tli); + XLogReadDetermineTimeline(state, targetPagePtr, reqLen, currTLI); if (state->currTLI == currTLI) { @@ -997,13 +995,6 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr, */ read_upto = state->currTLIValidUntil; - /* - * Use the selected timeline's segment file. The page might begin - * on an older timeline, since its xlog segment may have been - * copied from a prior timeline. See XLogReadDetermineTimeline(). - */ - tli = state->currTLI; - /* No need to wait on a historical timeline */ break; } @@ -1028,7 +1019,12 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr, count = read_upto - targetPagePtr; } - if (!WALRead(state, cur_page, targetPagePtr, count, tli, + /* + * Use the selected timeline's segment file. The page might begin + * on an older timeline, since its xlog segment may have been + * copied from a prior timeline. See XLogReadDetermineTimeline(). + */ + if (!WALRead(state, cur_page, targetPagePtr, count, state->currTLI, &errinfo)) WALReadRaiseError(&errinfo); -- 2.51.0