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

Commit 931b6db

Browse files
committed
Fix corner-case bug in tracking of latest removed WAL segment during
streaming replication. We used log/seg 0/0 to indicate that no WAL segments have been removed since startup, but 0/0 is a valid value for the very first WAL segment after initdb. To make that disambiguous, store (latest removed WAL segment + 1) in the global variable. Per report from Matt Chesler, also reproduced by Greg Smith.
1 parent 76b12e0 commit 931b6db

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/backend/access/transam/xlog.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ typedef struct XLogCtlData
364364
uint32 ckptXidEpoch; /* nextXID & epoch of latest checkpoint */
365365
TransactionId ckptXid;
366366
XLogRecPtr asyncXactLSN; /* LSN of newest async commit/abort */
367-
uint32 lastRemovedLog; /* latest removed/recycled XLOG segment */
367+
uint32 lastRemovedLog; /* latest removed/recycled XLOG segment + 1 */
368368
uint32 lastRemovedSeg;
369369

370370
/* Protected by WALWriteLock: */
@@ -3218,8 +3218,10 @@ PreallocXlogFiles(XLogRecPtr endptr)
32183218
}
32193219

32203220
/*
3221-
* Get the log/seg of the latest removed or recycled WAL segment.
3222-
* Returns 0 if no WAL segments have been removed since startup.
3221+
* Get the log/seg of the first WAL segment that has not been removed or
3222+
* recycled. In other words, the log/seg of the last removed/recycled WAL
3223+
* segment + 1.
3224+
* Returns 0/0 if no WAL segments have been removed since startup.
32233225
*/
32243226
void
32253227
XLogGetLastRemoved(uint32 *log, uint32 *seg)
@@ -3247,6 +3249,7 @@ UpdateLastRemovedPtr(char *filename)
32473249
seg;
32483250

32493251
XLogFromFileName(filename, &tli, &log, &seg);
3252+
NextLogSeg(log, seg);
32503253

32513254
SpinLockAcquire(&xlogctl->info_lck);
32523255
if (log > xlogctl->lastRemovedLog ||

src/backend/replication/walsender.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ XLogRead(char *buf, XLogRecPtr recptr, Size nbytes)
654654
XLogGetLastRemoved(&lastRemovedLog, &lastRemovedSeg);
655655
XLByteToSeg(startRecPtr, log, seg);
656656
if (log < lastRemovedLog ||
657-
(log == lastRemovedLog && seg <= lastRemovedSeg))
657+
(log == lastRemovedLog && seg < lastRemovedSeg))
658658
{
659659
char filename[MAXFNAMELEN];
660660

0 commit comments

Comments
 (0)