Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c843ff

Browse files
committed
Bootstrap WAL to begin at segment logid=0 logseg=1 (000000010000000000000001)
rather than 0/0, so that we can safely use 0/0 as an invalid value. This is amore future-proof fix for the corner-case bug in streaming replication thatwas fixed yesterday. We had a similar corner-case bug with log/seg 0/0 back inFebruary as well. Avoiding 0/0 as a valid value should prevent bugs like thatin the future. Per Tom Lane's idea.Back-patch to 9.0. Since this only affects bootstrapping, it makes nodifference to existing installations. We don't need to worry about thebug in existing installations, because if you've managed to get past theinitial base backup already, you won't hit the bug in the future either.
1 parent0811ff2 commit8c843ff

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ typedef struct XLogCtlData
364364
uint32ckptXidEpoch;/* nextXID & epoch of latest checkpoint */
365365
TransactionIdckptXid;
366366
XLogRecPtrasyncXactLSN;/* LSN of newest async commit/abort */
367-
uint32lastRemovedLog;/* latest removed/recycled XLOG segment+ 1*/
367+
uint32lastRemovedLog;/* latest removed/recycled XLOG segment */
368368
uint32lastRemovedSeg;
369369

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

32203220
/*
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.
3221+
* Get the log/seg of the latest removed or recycled WAL segment.
32243222
* Returns 0/0 if no WAL segments have been removed since startup.
32253223
*/
32263224
void
@@ -3249,7 +3247,6 @@ UpdateLastRemovedPtr(char *filename)
32493247
seg;
32503248

32513249
XLogFromFileName(filename,&tli,&log,&seg);
3252-
NextLogSeg(log,seg);
32533250

32543251
SpinLockAcquire(&xlogctl->info_lck);
32553252
if (log>xlogctl->lastRemovedLog||
@@ -4903,9 +4900,15 @@ BootStrapXLOG(void)
49034900
page= (XLogPageHeader)TYPEALIGN(ALIGNOF_XLOG_BUFFER,buffer);
49044901
memset(page,0,XLOG_BLCKSZ);
49054902

4906-
/* Set up information for the initial checkpoint record */
4903+
/*
4904+
* Set up information for the initial checkpoint record
4905+
*
4906+
* The initial checkpoint record is written to the beginning of the
4907+
* WAL segment with logid=0 logseg=1. The very first WAL segment, 0/0, is
4908+
* not used, so that we can use 0/0 to mean "before any valid WAL segment".
4909+
*/
49074910
checkPoint.redo.xlogid=0;
4908-
checkPoint.redo.xrecoff=SizeOfXLogLongPHD;
4911+
checkPoint.redo.xrecoff=XLogSegSize+SizeOfXLogLongPHD;
49094912
checkPoint.ThisTimeLineID=ThisTimeLineID;
49104913
checkPoint.nextXidEpoch=0;
49114914
checkPoint.nextXid=FirstNormalTransactionId;
@@ -4928,7 +4931,7 @@ BootStrapXLOG(void)
49284931
page->xlp_info=XLP_LONG_HEADER;
49294932
page->xlp_tli=ThisTimeLineID;
49304933
page->xlp_pageaddr.xlogid=0;
4931-
page->xlp_pageaddr.xrecoff=0;
4934+
page->xlp_pageaddr.xrecoff=XLogSegSize;
49324935
longpage= (XLogLongPageHeader)page;
49334936
longpage->xlp_sysid=sysidentifier;
49344937
longpage->xlp_seg_size=XLogSegSize;
@@ -4954,7 +4957,7 @@ BootStrapXLOG(void)
49544957

49554958
/* Create first XLOG segment file */
49564959
use_existent= false;
4957-
openLogFile=XLogFileInit(0,0,&use_existent, false);
4960+
openLogFile=XLogFileInit(0,1,&use_existent, false);
49584961

49594962
/* Write the first page with the initial record */
49604963
errno=0;

‎src/backend/replication/walsender.c

Lines changed: 1 addition & 1 deletion
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
charfilename[MAXFNAMELEN];
660660

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp