From 4e1c57094af7cdbdbbc534b0e50c03f40dc8ce2f Mon Sep 17 00:00:00 2001 From: "suyu.cmj" Date: Fri, 26 Mar 2021 15:02:07 +0800 Subject: [PATCH] Update walrcv->flushedUpto each time when request xlog streaming --- src/backend/replication/walreceiverfuncs.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index c3e317d..83de80e 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -280,16 +280,19 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, walrcv->walRcvState = WALRCV_RESTARTING; walrcv->startTime = now; - /* - * If this is the first startup of walreceiver (on this timeline), - * initialize flushedUpto and latestChunkStart to the starting point. - */ - if (walrcv->receiveStart == 0 || walrcv->receivedTLI != tli) - { - walrcv->flushedUpto = recptr; + /* Set received tli */ + if (walrcv->receivedTLI != tli) walrcv->receivedTLI = tli; - walrcv->latestChunkStart = recptr; - } + + /* + * Set flushedUpto and latestChunkStart to the starting point each time when request xlog streaming + * so that when we re-receive a wal segment file(there may be wrong data in the wal file so we need to re-receive it) + * we can correctly judge whether we have received new wal in WaitForWALToBecomeAvailable func according to new flushedUpto + * rather than the previous one, which maybe greater than the wal we actually received in current streaming process. + * similarly, set latestChunkStart each time so that we can update XLogReceiptTime correctly when we have replayed new wal + */ + walrcv->flushedUpto = recptr; + walrcv->latestChunkStart = recptr; walrcv->receiveStart = recptr; walrcv->receiveStartTLI = tli; -- 2.24.3 (Apple Git-128)