Skip to content

Commit dc7dfc9

Browse files
melanieplagemanCommitfest Bot
authored andcommitted
Fix XLogNeedsFlush() for checkpointer
In normal operation, XLogNeedsFlush() returns true if the flush ptr has not been advanced past the provided LSN. During normal recovery on a standby (not crash recovery), it return true if the minimum recovery point hasn't been advanced past the provided LSN. However, during an end-of-recovery checkpoint, the checkpointer flushes WAL, so XLogNeedsFlush() should compare the provided location with the flush pointer. Correct the logic in XLogNeedsFlush() to compare the LSN to the flush pointer when WAL inserts are allowed and the minimum recovery point otherwise. This is not an active bug because no current users of XLogNeedsFlush() temporarily allowed WAL inserts during recovery. Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Jeff Davis <pgsql@j-davis.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/flat/CAAKRu_a1vZRZRWO3_jv_X13RYoqLRVipGO0237g5PKzPa2YX6g%40mail.gmail.com Discussion: https://postgr.es/m/flat/CAAKRu_bcWRvRwZUop_d9vzF9nHAiT%2B-uPzkJ%3DS3ShZ1GqeAYOw%40mail.gmail.com
1 parent 7269860 commit dc7dfc9

File tree

1 file changed

+12
-7
lines changed
  • src/backend/access/transam

1 file changed

+12
-7
lines changed

src/backend/access/transam/xlog.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,21 +3102,26 @@ XLogBackgroundFlush(void)
31023102
}
31033103

31043104
/*
3105-
* Test whether XLOG data has been flushed up to (at least) the given position.
3105+
* Test whether XLOG data has been flushed up to (at least) the given position
3106+
* or whether the minimum recovery point is updated past the given position.
31063107
*
3107-
* Returns true if a flush is still needed. (It may be that someone else
3108-
* is already in process of flushing that far, however.)
3108+
* Returns true if a flush is still needed or if the minimum recovery point
3109+
* must be updated.
3110+
*
3111+
* It is possible that someone else is already in the process of flushing that
3112+
* far or updating the minimum recovery point that far.
31093113
*/
31103114
bool
31113115
XLogNeedsFlush(XLogRecPtr record)
31123116
{
31133117
/*
3114-
* During recovery, we don't flush WAL but update minRecoveryPoint
3115-
* instead. So "needs flush" is taken to mean whether minRecoveryPoint
3116-
* would need to be updated.
3118+
* During recovery, when WAL inserts are forbidden, "needs flush" is taken
3119+
* to mean whether minRecoveryPoint would need to be updated.
31173120
*/
3118-
if (RecoveryInProgress())
3121+
if (!XLogInsertAllowed())
31193122
{
3123+
Assert(RecoveryInProgress());
3124+
31203125
/*
31213126
* An invalid minRecoveryPoint means that we need to recover all the
31223127
* WAL, i.e., we're doing crash recovery. We never modify the control

0 commit comments

Comments
 (0)