Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 571f7f7

Browse files
author
Amit Kapila
committed
To improve the code, move the error check in logical_read_xlog_page().
Commit 0fdab27 changed the code to wait for WAL to be available before determining the timeline but forgot to move the failure check. This change is to make the related code easier to understand and enhance otherwise there is no bug in the current code. In the passing, improve the nearby comments to explain why we determine am_cascading_walsender after waiting for the required WAL. Author: Peter Smith Reviewed-by: Bertrand Drouvot, Amit Kapila Discussion: https://postgr.es/m/CAHut+PvqX49fusLyXspV1Mmd_EekPtXG0oT146vZjcb9XDvNgw@mail.gmail.com
1 parent b68b29b commit 571f7f7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/backend/replication/walsender.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -1057,16 +1057,21 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
10571057

10581058
/*
10591059
* Make sure we have enough WAL available before retrieving the current
1060-
* timeline. This is needed to determine am_cascading_walsender accurately
1061-
* which is needed to determine the current timeline.
1060+
* timeline.
10621061
*/
10631062
flushptr = WalSndWaitForWal(targetPagePtr + reqLen);
10641063

1064+
/* Fail if not enough (implies we are going to shut down) */
1065+
if (flushptr < targetPagePtr + reqLen)
1066+
return -1;
1067+
10651068
/*
10661069
* Since logical decoding is also permitted on a standby server, we need
10671070
* to check if the server is in recovery to decide how to get the current
1068-
* timeline ID (so that it also cover the promotion or timeline change
1069-
* cases).
1071+
* timeline ID (so that it also covers the promotion or timeline change
1072+
* cases). We must determine am_cascading_walsender after waiting for the
1073+
* required WAL so that it is correct when the walsender wakes up after a
1074+
* promotion.
10701075
*/
10711076
am_cascading_walsender = RecoveryInProgress();
10721077

@@ -1081,10 +1086,6 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
10811086
sendTimeLineValidUpto = state->currTLIValidUntil;
10821087
sendTimeLineNextTLI = state->nextTLI;
10831088

1084-
/* fail if not (implies we are going to shut down) */
1085-
if (flushptr < targetPagePtr + reqLen)
1086-
return -1;
1087-
10881089
if (targetPagePtr + XLOG_BLCKSZ <= flushptr)
10891090
count = XLOG_BLCKSZ; /* more than one block available */
10901091
else

0 commit comments

Comments
 (0)