03-modify-xlog-macros_rebase.patch
application/octet-stream
Filename: 03-modify-xlog-macros_rebase.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| contrib/pg_standby/pg_standby.c | 10 | 10 |
| src/backend/access/transam/xlogarchive.c | 6 | 6 |
| src/backend/access/transam/xlog.c | 74 | 73 |
| src/backend/access/transam/xlogfuncs.c | 5 | 5 |
| src/backend/access/transam/xlogreader.c | 11 | 11 |
| src/backend/access/transam/xlogutils.c | 6 | 6 |
| src/backend/postmaster/checkpointer.c | 1 | 1 |
| src/backend/replication/basebackup.c | 10 | 10 |
| src/backend/replication/logical/reorderbuffer.c | 9 | 9 |
| src/backend/replication/slot.c | 1 | 1 |
| src/backend/replication/walreceiver.c | 5 | 5 |
| src/backend/replication/walreceiverfuncs.c | 2 | 2 |
| src/backend/replication/walsender.c | 6 | 6 |
| src/backend/utils/misc/pg_controldata.c | 2 | 2 |
| src/bin/pg_basebackup/pg_basebackup.c | 1 | 1 |
| src/bin/pg_basebackup/pg_receivewal.c | 6 | 6 |
| src/bin/pg_basebackup/receivelog.c | 15 | 14 |
| src/bin/pg_basebackup/streamutil.c | 8 | 8 |
| src/bin/pg_basebackup/streamutil.h | 1 | 0 |
| src/bin/pg_controldata/pg_controldata.c | 8 | 8 |
| src/bin/pg_resetwal/pg_resetwal.c | 17 | 16 |
| src/bin/pg_rewind/parsexlog.c | 9 | 7 |
| src/bin/pg_rewind/pg_rewind.c | 2 | 2 |
| src/bin/pg_rewind/pg_rewind.h | 2 | 0 |
| src/bin/pg_waldump/pg_waldump.c | 16 | 14 |
| src/include/access/xlog_internal.h | 31 | 28 |
diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c
index 349f1ca..34148dd 100644
--- a/contrib/pg_standby/pg_standby.c
+++ b/contrib/pg_standby/pg_standby.c
@@ -37,7 +37,7 @@
const char *progname;
-int XLogSegSize;
+int WalSegsz;
/* Options and defaults */
int sleeptime = 5; /* amount of time to sleep between file checks */
@@ -113,8 +113,8 @@ RetrieveXLogSegSize(void)
int fd;
char *buf = (char *) malloc(XLOG_BLCKSZ);
- /* Already set a valid XLogSegSize? */
- if (IsValidXLogSegSize(XLogSegSize))
+ /* Already set a valid WalSegsz? */
+ if (IsValidXLogSegSize(WalSegsz))
return true;
if ((fd = open(WALFilePath, O_RDWR, 0)) < 0)
@@ -128,9 +128,9 @@ RetrieveXLogSegSize(void)
XLogPageHeader hdr = (XLogPageHeader) buf;
XLogLongPageHeader longhdr = (XLogLongPageHeader) hdr;
- XLogSegSize = longhdr->xlp_seg_size;
+ WalSegsz = longhdr->xlp_seg_size;
- if (IsValidXLogSegSize(XLogSegSize))
+ if (IsValidXLogSegSize(WalSegsz))
{
/* successfully retrieved WAL segment size */
ret_val = true;
@@ -140,7 +140,7 @@ RetrieveXLogSegSize(void)
if (debug)
{
fprintf(stderr,
- _("WAL segment size: %d \n"), XLogSegSize);
+ _("WAL segment size: %d \n"), WalSegsz);
fprintf(stderr, "Keep archive history: ");
if (need_cleanup)
@@ -153,7 +153,7 @@ RetrieveXLogSegSize(void)
else
fprintf(stderr,
"%s: WAL segment size must be a power of two between 1MB and 1GB, but the WAL file header specifies %d bytes\n",
- progname, XLogSegSize);
+ progname, WalSegsz);
close(fd);
}
else
@@ -255,7 +255,7 @@ CustomizableNextWALFileReady(void)
}
else if (!RetrieveXLogSegSize())
return false;
- else if (stat_buf.st_size == XLogSegSize)
+ else if (stat_buf.st_size == WalSegsz)
{
#ifdef WIN32
@@ -275,7 +275,7 @@ CustomizableNextWALFileReady(void)
/*
* If still too small, wait until it is the correct size
*/
- if (stat_buf.st_size > XLogSegSize)
+ if (stat_buf.st_size > WalSegsz)
{
if (debug)
{
@@ -384,7 +384,7 @@ SetWALFileNameForCleanup(void)
uint32 log_diff = 0,
seg_diff = 0;
bool cleanup = false;
- int MaxSegmentsPerLogFile = (0xFFFFFFFF / XLogSegSize);
+ int MaxSegmentsPerLogFile = (0xFFFFFFFF / WalSegsz);
if (restartWALFileName)
{
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 4e7c50d..ccc3c19 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1141,7 +1141,7 @@ XLogInsertRecord(XLogRecData *rdata,
EndPos = StartPos + SizeOfXLogRecord;
if (StartPos / XLOG_BLCKSZ != EndPos / XLOG_BLCKSZ)
{
- if (XLogSegmentOffset(EndPos) == EndPos % XLOG_BLCKSZ)
+ if (XLogSegmentOffset(EndPos, XLogSegSize) == EndPos % XLOG_BLCKSZ)
EndPos += SizeOfXLogLongPHD;
else
EndPos += SizeOfXLogShortPHD;
@@ -1300,7 +1300,7 @@ ReserveXLogSwitch(XLogRecPtr *StartPos, XLogRecPtr *EndPos, XLogRecPtr *PrevPtr)
startbytepos = Insert->CurrBytePos;
ptr = XLogBytePosToEndRecPtr(startbytepos);
- if (XLogSegmentOffset(ptr) == 0)
+ if (XLogSegmentOffset(ptr, XLogSegSize) == 0)
{
SpinLockRelease(&Insert->insertpos_lck);
*EndPos = *StartPos = ptr;
@@ -1313,7 +1313,7 @@ ReserveXLogSwitch(XLogRecPtr *StartPos, XLogRecPtr *EndPos, XLogRecPtr *PrevPtr)
*StartPos = XLogBytePosToRecPtr(startbytepos);
*EndPos = XLogBytePosToEndRecPtr(endbytepos);
- segleft = XLogSegSize - (XLogSegmentOffset(*EndPos));
+ segleft = XLogSegSize - (XLogSegmentOffset(*EndPos, XLogSegSize));
if (segleft != XLogSegSize)
{
/* consume the rest of the segment */
@@ -1327,7 +1327,7 @@ ReserveXLogSwitch(XLogRecPtr *StartPos, XLogRecPtr *EndPos, XLogRecPtr *PrevPtr)
*PrevPtr = XLogBytePosToRecPtr(prevbytepos);
- Assert(XLogSegmentOffset(*EndPos) == 0);
+ Assert(XLogSegmentOffset(*EndPos, XLogSegSize) == 0);
Assert(XLogRecPtrToBytePos(*EndPos) == endbytepos);
Assert(XLogRecPtrToBytePos(*StartPos) == startbytepos);
Assert(XLogRecPtrToBytePos(*PrevPtr) == prevbytepos);
@@ -1505,7 +1505,7 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
pagehdr->xlp_info |= XLP_FIRST_IS_CONTRECORD;
/* skip over the page header */
- if (XLogSegmentOffset(CurrPos) == 0)
+ if (XLogSegmentOffset(CurrPos, XLogSegSize) == 0)
{
CurrPos += SizeOfXLogLongPHD;
currpos += SizeOfXLogLongPHD;
@@ -1536,7 +1536,7 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
* allocated and zeroed in the WAL buffers so that when the caller (or
* someone else) does XLogWrite(), it can really write out all the zeros.
*/
- if (isLogSwitch && XLogSegmentOffset(CurrPos) != 0)
+ if (isLogSwitch && XLogSegmentOffset(CurrPos, XLogSegSize) != 0)
{
/* An xlog-switch record doesn't contain any data besides the header */
Assert(write_len == SizeOfXLogRecord);
@@ -1545,7 +1545,7 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
* We do this one page at a time, to make sure we don't deadlock
* against ourselves if wal_buffers < XLogSegSize.
*/
- Assert(XLogSegmentOffset(EndPos) == 0);
+ Assert(XLogSegmentOffset(EndPos, XLogSegSize) == 0);
/* Use up all the remaining space on the first page */
CurrPos += freespace;
@@ -1870,10 +1870,10 @@ GetXLogBuffer(XLogRecPtr ptr)
* the page header.
*/
if (ptr % XLOG_BLCKSZ == SizeOfXLogShortPHD &&
- XLogSegmentOffset(ptr) > XLOG_BLCKSZ)
+ XLogSegmentOffset(ptr, XLogSegSize) > XLOG_BLCKSZ)
initializedUpto = ptr - SizeOfXLogShortPHD;
else if (ptr % XLOG_BLCKSZ == SizeOfXLogLongPHD &&
- XLogSegmentOffset(ptr) < XLOG_BLCKSZ)
+ XLogSegmentOffset(ptr, XLogSegSize) < XLOG_BLCKSZ)
initializedUpto = ptr - SizeOfXLogLongPHD;
else
initializedUpto = ptr;
@@ -1943,7 +1943,7 @@ XLogBytePosToRecPtr(uint64 bytepos)
seg_offset += fullpages * XLOG_BLCKSZ + bytesleft + SizeOfXLogShortPHD;
}
- XLogSegNoOffsetToRecPtr(fullsegs, seg_offset, result);
+ XLogSegNoOffsetToRecPtr(fullsegs, seg_offset, result, XLogSegSize);
return result;
}
@@ -1989,7 +1989,7 @@ XLogBytePosToEndRecPtr(uint64 bytepos)
seg_offset += fullpages * XLOG_BLCKSZ + bytesleft + SizeOfXLogShortPHD;
}
- XLogSegNoOffsetToRecPtr(fullsegs, seg_offset, result);
+ XLogSegNoOffsetToRecPtr(fullsegs, seg_offset, result, XLogSegSize);
return result;
}
@@ -2005,9 +2005,9 @@ XLogRecPtrToBytePos(XLogRecPtr ptr)
uint32 offset;
uint64 result;
- XLByteToSeg(ptr, fullsegs);
+ XLByteToSeg(ptr, fullsegs, XLogSegSize);
- fullpages = (XLogSegmentOffset(ptr)) / XLOG_BLCKSZ;
+ fullpages = (XLogSegmentOffset(ptr, XLogSegSize)) / XLOG_BLCKSZ;
offset = ptr % XLOG_BLCKSZ;
if (fullpages == 0)
@@ -2172,7 +2172,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, bool opportunistic)
/*
* If first page of an XLOG segment file, make it a long header.
*/
- if ((XLogSegmentOffset(NewPage->xlp_pageaddr)) == 0)
+ if ((XLogSegmentOffset(NewPage->xlp_pageaddr, XLogSegSize)) == 0)
{
XLogLongPageHeader NewLongPage = (XLogLongPageHeader) NewPage;
@@ -2318,7 +2318,7 @@ XLogCheckpointNeeded(XLogSegNo new_segno)
{
XLogSegNo old_segno;
- XLByteToSeg(RedoRecPtr, old_segno);
+ XLByteToSeg(RedoRecPtr, old_segno, XLogSegSize);
if (new_segno >= old_segno + (uint64) (CheckPointSegments - 1))
return true;
@@ -2396,7 +2396,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
LogwrtResult.Write = EndPtr;
ispartialpage = WriteRqst.Write < LogwrtResult.Write;
- if (!XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo))
+ if (!XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo, XLogSegSize))
{
/*
* Switch to new logfile segment. We cannot have any pending
@@ -2405,7 +2405,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
Assert(npages == 0);
if (openLogFile >= 0)
XLogFileClose();
- XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo);
+ XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo, XLogSegSize);
/* create/use new log file */
use_existent = true;
@@ -2416,7 +2416,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
/* Make sure we have the current logfile open */
if (openLogFile < 0)
{
- XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo);
+ XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo, XLogSegSize);
openLogFile = XLogFileOpen(openLogSegNo);
openLogOff = 0;
}
@@ -2426,7 +2426,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
{
/* first of group */
startidx = curridx;
- startoffset = XLogSegmentOffset(LogwrtResult.Write - XLOG_BLCKSZ);
+ startoffset = XLogSegmentOffset(LogwrtResult.Write - XLOG_BLCKSZ, XLogSegSize);
}
npages++;
@@ -2566,11 +2566,11 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
sync_method != SYNC_METHOD_OPEN_DSYNC)
{
if (openLogFile >= 0 &&
- !XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo))
+ !XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo, XLogSegSize))
XLogFileClose();
if (openLogFile < 0)
{
- XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo);
+ XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo, XLogSegSize);
openLogFile = XLogFileOpen(openLogSegNo);
openLogOff = 0;
}
@@ -2986,7 +2986,7 @@ XLogBackgroundFlush(void)
{
if (openLogFile >= 0)
{
- if (!XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo))
+ if (!XLByteInPrevSeg(LogwrtResult.Write, openLogSegNo, XLogSegSize))
{
XLogFileClose();
}
@@ -3165,7 +3165,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
int fd;
int nbytes;
- XLogFilePath(path, ThisTimeLineID, logsegno);
+ XLogFilePath(path, ThisTimeLineID, logsegno, XLogSegSize);
/*
* Try to use existent file (checkpoint maker may have created it already)
@@ -3336,7 +3336,7 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
/*
* Open the source file
*/
- XLogFilePath(path, srcTLI, srcsegno);
+ XLogFilePath(path, srcTLI, srcsegno, XLogSegSize);
srcfd = OpenTransientFile(path, O_RDONLY | PG_BINARY, 0);
if (srcfd < 0)
ereport(ERROR,
@@ -3471,7 +3471,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
char path[MAXPGPATH];
struct stat stat_buf;
- XLogFilePath(path, ThisTimeLineID, *segno);
+ XLogFilePath(path, ThisTimeLineID, *segno, XLogSegSize);
/*
* We want to be sure that only one process does this at a time.
@@ -3497,7 +3497,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
return false;
}
(*segno)++;
- XLogFilePath(path, ThisTimeLineID, *segno);
+ XLogFilePath(path, ThisTimeLineID, *segno, XLogSegSize);
}
}
@@ -3528,7 +3528,7 @@ XLogFileOpen(XLogSegNo segno)
char path[MAXPGPATH];
int fd;
- XLogFilePath(path, ThisTimeLineID, segno);
+ XLogFilePath(path, ThisTimeLineID, segno, XLogSegSize);
fd = BasicOpenFile(path, O_RDWR | PG_BINARY | get_sync_bit(sync_method),
S_IRUSR | S_IWUSR);
@@ -3555,7 +3555,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
char path[MAXPGPATH];
int fd;
- XLogFileName(xlogfname, tli, segno);
+ XLogFileName(xlogfname, tli, segno, XLogSegSize);
switch (source)
{
@@ -3575,7 +3575,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
case XLOG_FROM_PG_WAL:
case XLOG_FROM_STREAM:
- XLogFilePath(path, tli, segno);
+ XLogFilePath(path, tli, segno, XLogSegSize);
restoredFromArchive = false;
break;
@@ -3694,7 +3694,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, int source)
}
/* Couldn't find it. For simplicity, complain about front timeline */
- XLogFilePath(path, recoveryTargetTLI, segno);
+ XLogFilePath(path, recoveryTargetTLI, segno, XLogSegSize);
errno = ENOENT;
ereport(emode,
(errcode_for_file_access(),
@@ -3746,8 +3746,8 @@ PreallocXlogFiles(XLogRecPtr endptr)
int lf;
bool use_existent;
- XLByteToPrevSeg(endptr, _logSegNo);
- if (XLogSegmentOffset(endptr - 1) >= (uint32) (0.75 * XLogSegSize))
+ XLByteToPrevSeg(endptr, _logSegNo, XLogSegSize);
+ if (XLogSegmentOffset(endptr - 1, XLogSegSize) >= (uint32) (0.75 * XLogSegSize))
{
_logSegNo++;
use_existent = true;
@@ -3778,7 +3778,7 @@ CheckXLogRemoved(XLogSegNo segno, TimeLineID tli)
{
char filename[MAXFNAMELEN];
- XLogFileName(filename, tli, segno);
+ XLogFileName(filename, tli, segno, XLogSegSize);
ereport(ERROR,
(errcode_for_file_access(),
errmsg("requested WAL segment %s has already been removed",
@@ -3815,7 +3815,7 @@ UpdateLastRemovedPtr(char *filename)
uint32 tli;
XLogSegNo segno;
- XLogFromFileName(filename, &tli, &segno);
+ XLogFromFileName(filename, &tli, &segno, XLogSegSize);
SpinLockAcquire(&XLogCtl->info_lck);
if (segno > XLogCtl->lastRemovedSegNo)
@@ -3849,7 +3849,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
* doesn't matter, we ignore that in the comparison. (During recovery,
* ThisTimeLineID isn't set, so we can't use that.)
*/
- XLogFileName(lastoff, 0, segno);
+ XLogFileName(lastoff, 0, segno, XLogSegSize);
elog(DEBUG2, "attempting to remove WAL segments older than log file %s",
lastoff);
@@ -3910,7 +3910,7 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
char switchseg[MAXFNAMELEN];
XLogSegNo endLogSegNo;
- XLByteToPrevSeg(switchpoint, endLogSegNo);
+ XLByteToPrevSeg(switchpoint, endLogSegNo, XLogSegSize);
xldir = AllocateDir(XLOGDIR);
if (xldir == NULL)
@@ -3922,7 +3922,7 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
/*
* Construct a filename of the last segment to be kept.
*/
- XLogFileName(switchseg, newTLI, endLogSegNo);
+ XLogFileName(switchseg, newTLI, endLogSegNo, XLogSegSize);
elog(DEBUG2, "attempting to remove WAL segments newer than log file %s",
switchseg);
@@ -3978,7 +3978,7 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
/*
* Initialize info about where to try to recycle to.
*/
- XLByteToSeg(endptr, endlogSegNo);
+ XLByteToSeg(endptr, endlogSegNo, XLogSegSize);
if (PriorRedoPtr == InvalidXLogRecPtr)
recycleSegNo = endlogSegNo + 10;
else
@@ -4196,9 +4196,9 @@ ReadRecord(XLogReaderState *xlogreader, XLogRecPtr RecPtr, int emode,
XLogSegNo segno;
int32 offset;
- XLByteToSeg(xlogreader->latestPagePtr, segno);
- offset = XLogSegmentOffset(xlogreader->latestPagePtr);
- XLogFileName(fname, xlogreader->readPageTLI, segno);
+ XLByteToSeg(xlogreader->latestPagePtr, segno, XLogSegSize);
+ offset = XLogSegmentOffset(xlogreader->latestPagePtr, XLogSegSize);
+ XLogFileName(fname, xlogreader->readPageTLI, segno, XLogSegSize);
ereport(emode_for_corrupt_record(emode,
RecPtr ? RecPtr : EndRecPtr),
(errmsg("unexpected timeline ID %u in log segment %s, offset %u",
@@ -5545,8 +5545,8 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
* they are the same, but if the switch happens exactly at a segment
* boundary, startLogSegNo will be endLogSegNo + 1.
*/
- XLByteToPrevSeg(endOfLog, endLogSegNo);
- XLByteToSeg(endOfLog, startLogSegNo);
+ XLByteToPrevSeg(endOfLog, endLogSegNo, XLogSegSize);
+ XLByteToSeg(endOfLog, startLogSegNo, XLogSegSize);
/*
* Initialize the starting WAL segment for the new timeline. If the switch
@@ -5564,7 +5564,7 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
* avoid emplacing a bogus file.
*/
XLogFileCopy(endLogSegNo, endTLI, endLogSegNo,
- XLogSegmentOffset(endOfLog));
+ XLogSegmentOffset(endOfLog, XLogSegSize));
}
else
{
@@ -5588,7 +5588,7 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
* Let's just make real sure there are not .ready or .done flags posted
* for the new segment.
*/
- XLogFileName(xlogfname, ThisTimeLineID, startLogSegNo);
+ XLogFileName(xlogfname, ThisTimeLineID, startLogSegNo, XLogSegSize);
XLogArchiveCleanup(xlogfname);
/*
@@ -7533,7 +7533,7 @@ StartupXLOG(void)
XLogRecPtr pageBeginPtr;
pageBeginPtr = EndOfLog - (EndOfLog % XLOG_BLCKSZ);
- Assert(readOff == XLogSegmentOffset(pageBeginPtr));
+ Assert(readOff == XLogSegmentOffset(pageBeginPtr, XLogSegSize));
firstIdx = XLogRecPtrToBufIdx(EndOfLog);
@@ -7682,13 +7682,13 @@ StartupXLOG(void)
* restored from the archive to begin with, it's expected to have a
* .done file).
*/
- if (XLogSegmentOffset(EndOfLog) != 0 && XLogArchivingActive())
+ if (XLogSegmentOffset(EndOfLog, XLogSegSize) != 0 && XLogArchivingActive())
{
char origfname[MAXFNAMELEN];
XLogSegNo endLogSegNo;
- XLByteToPrevSeg(EndOfLog, endLogSegNo);
- XLogFileName(origfname, EndOfLogTLI, endLogSegNo);
+ XLByteToPrevSeg(EndOfLog, endLogSegNo, XLogSegSize);
+ XLogFileName(origfname, EndOfLogTLI, endLogSegNo, XLogSegSize);
if (!XLogArchiveIsReadyOrDone(origfname))
{
@@ -7696,7 +7696,7 @@ StartupXLOG(void)
char partialfname[MAXFNAMELEN];
char partialpath[MAXPGPATH];
- XLogFilePath(origpath, EndOfLogTLI, endLogSegNo);
+ XLogFilePath(origpath, EndOfLogTLI, endLogSegNo, XLogSegSize);
snprintf(partialfname, MAXFNAMELEN, "%s.partial", origfname);
snprintf(partialpath, MAXPGPATH, "%s.partial", origpath);
@@ -8734,7 +8734,7 @@ CreateCheckPoint(int flags)
freespace = INSERT_FREESPACE(curInsert);
if (freespace == 0)
{
- if (XLogSegmentOffset(curInsert) == 0)
+ if (XLogSegmentOffset(curInsert, XLogSegSize) == 0)
curInsert += SizeOfXLogLongPHD;
else
curInsert += SizeOfXLogShortPHD;
@@ -8968,7 +8968,7 @@ CreateCheckPoint(int flags)
/* Update the average distance between checkpoints. */
UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr);
- XLByteToSeg(PriorRedoPtr, _logSegNo);
+ XLByteToSeg(PriorRedoPtr, _logSegNo, XLogSegSize);
KeepLogSeg(recptr, &_logSegNo);
_logSegNo--;
RemoveOldXlogFiles(_logSegNo, PriorRedoPtr, recptr);
@@ -9296,7 +9296,7 @@ CreateRestartPoint(int flags)
/* Update the average distance between checkpoints/restartpoints. */
UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr);
- XLByteToSeg(PriorRedoPtr, _logSegNo);
+ XLByteToSeg(PriorRedoPtr, _logSegNo, XLogSegSize);
/*
* Get the current end of xlog replayed or received, whichever is
@@ -9391,7 +9391,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
XLogSegNo segno;
XLogRecPtr keep;
- XLByteToSeg(recptr, segno);
+ XLByteToSeg(recptr, segno, XLogSegSize);
keep = XLogGetReplicationSlotMinimumLSN();
/* compute limit for wal_keep_segments first */
@@ -9409,7 +9409,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
{
XLogSegNo slotSegNo;
- XLByteToSeg(keep, slotSegNo);
+ XLByteToSeg(keep, slotSegNo, XLogSegSize);
if (slotSegNo <= 0)
segno = 1;
@@ -10192,7 +10192,7 @@ XLogFileNameP(TimeLineID tli, XLogSegNo segno)
{
char *result = palloc(MAXFNAMELEN);
- XLogFileName(result, tli, segno);
+ XLogFileName(result, tli, segno, XLogSegSize);
return result;
}
@@ -10446,8 +10446,8 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
WALInsertLockRelease();
} while (!gotUniqueStartpoint);
- XLByteToSeg(startpoint, _logSegNo);
- XLogFileName(xlogfilename, starttli, _logSegNo);
+ XLByteToSeg(startpoint, _logSegNo, XLogSegSize);
+ XLogFileName(xlogfilename, starttli, _logSegNo, XLogSegSize);
/*
* Construct tablespace_map file
@@ -10998,8 +10998,8 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
*/
RequestXLogSwitch(false);
- XLByteToPrevSeg(stoppoint, _logSegNo);
- XLogFileName(stopxlogfilename, stoptli, _logSegNo);
+ XLByteToPrevSeg(stoppoint, _logSegNo, XLogSegSize);
+ XLogFileName(stopxlogfilename, stoptli, _logSegNo, XLogSegSize);
/* Use the log timezone here, not the session timezone */
stamp_time = (pg_time_t) time(NULL);
@@ -11010,9 +11010,9 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
/*
* Write the backup history file
*/
- XLByteToSeg(startpoint, _logSegNo);
+ XLByteToSeg(startpoint, _logSegNo, XLogSegSize);
BackupHistoryFilePath(histfilepath, stoptli, _logSegNo,
- (uint32) (XLogSegmentOffset(startpoint)));
+ startpoint, XLogSegSize);
fp = AllocateFile(histfilepath, "w");
if (!fp)
ereport(ERROR,
@@ -11066,12 +11066,12 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
((!backup_started_in_recovery && XLogArchivingActive()) ||
(backup_started_in_recovery && XLogArchivingAlways())))
{
- XLByteToPrevSeg(stoppoint, _logSegNo);
- XLogFileName(lastxlogfilename, stoptli, _logSegNo);
+ XLByteToPrevSeg(stoppoint, _logSegNo, XLogSegSize);
+ XLogFileName(lastxlogfilename, stoptli, _logSegNo, XLogSegSize);
- XLByteToSeg(startpoint, _logSegNo);
+ XLByteToSeg(startpoint, _logSegNo, XLogSegSize);
BackupHistoryFileName(histfilename, stoptli, _logSegNo,
- (uint32) (XLogSegmentOffset(startpoint)));
+ startpoint, XLogSegSize);
seconds_before_warning = 60;
waits = 0;
@@ -11514,14 +11514,14 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
uint32 targetPageOff;
XLogSegNo targetSegNo PG_USED_FOR_ASSERTS_ONLY;
- XLByteToSeg(targetPagePtr, targetSegNo);
- targetPageOff = XLogSegmentOffset(targetPagePtr);
+ XLByteToSeg(targetPagePtr, targetSegNo, XLogSegSize);
+ targetPageOff = XLogSegmentOffset(targetPagePtr, XLogSegSize);
/*
* See if we need to switch to a new segment because the requested record
* is not in the currently open one.
*/
- if (readFile >= 0 && !XLByteInSeg(targetPagePtr, readSegNo))
+ if (readFile >= 0 && !XLByteInSeg(targetPagePtr, readSegNo, XLogSegSize))
{
/*
* Request a restartpoint if we've replayed too much xlog since the
@@ -11542,7 +11542,7 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
readSource = 0;
}
- XLByteToSeg(targetPagePtr, readSegNo);
+ XLByteToSeg(targetPagePtr, readSegNo, XLogSegSize);
retry:
/* See if we need to retrieve more data */
@@ -11582,7 +11582,8 @@ retry:
if (((targetPagePtr) / XLOG_BLCKSZ) != (receivedUpto / XLOG_BLCKSZ))
readLen = XLOG_BLCKSZ;
else
- readLen = XLogSegmentOffset(receivedUpto) - targetPageOff;
+ readLen = XLogSegmentOffset(receivedUpto, XLogSegSize)
+ - targetPageOff;
}
else
readLen = XLOG_BLCKSZ;
@@ -11593,7 +11594,7 @@ retry:
{
char fname[MAXFNAMELEN];
- XLogFileName(fname, curFileTLI, readSegNo);
+ XLogFileName(fname, curFileTLI, readSegNo, XLogSegSize);
ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
(errcode_for_file_access(),
errmsg("could not seek in log segment %s to offset %u: %m",
@@ -11607,7 +11608,7 @@ retry:
char fname[MAXFNAMELEN];
pgstat_report_wait_end();
- XLogFileName(fname, curFileTLI, readSegNo);
+ XLogFileName(fname, curFileTLI, readSegNo, XLogSegSize);
ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
(errcode_for_file_access(),
errmsg("could not read from log segment %s, offset %u: %m",
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index 7afb735..99c0253 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -134,13 +134,13 @@ RestoreArchivedFile(char *path, const char *xlogfname,
if (cleanupEnabled)
{
GetOldestRestartPoint(&restartRedoPtr, &restartTli);
- XLByteToSeg(restartRedoPtr, restartSegNo);
- XLogFileName(lastRestartPointFname, restartTli, restartSegNo);
+ XLByteToSeg(restartRedoPtr, restartSegNo, XLogSegSize);
+ XLogFileName(lastRestartPointFname, restartTli, restartSegNo, XLogSegSize);
/* we shouldn't need anything earlier than last restart point */
Assert(strcmp(lastRestartPointFname, xlogfname) <= 0);
}
else
- XLogFileName(lastRestartPointFname, 0, 0L);
+ XLogFileName(lastRestartPointFname, 0, 0L, XLogSegSize);
/*
* construct the command to be executed
@@ -347,8 +347,8 @@ ExecuteRecoveryCommand(char *command, char *commandName, bool failOnSignal)
* archive, though there is no requirement to do so.
*/
GetOldestRestartPoint(&restartRedoPtr, &restartTli);
- XLByteToSeg(restartRedoPtr, restartSegNo);
- XLogFileName(lastRestartPointFname, restartTli, restartSegNo);
+ XLByteToSeg(restartRedoPtr, restartSegNo, XLogSegSize);
+ XLogFileName(lastRestartPointFname, restartTli, restartSegNo, XLogSegSize);
/*
* construct the command to be executed
@@ -547,7 +547,7 @@ XLogArchiveNotifySeg(XLogSegNo segno)
{
char xlog[MAXFNAMELEN];
- XLogFileName(xlog, ThisTimeLineID, segno);
+ XLogFileName(xlog, ThisTimeLineID, segno, XLogSegSize);
XLogArchiveNotify(xlog);
}
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index c4e8492..4aac86b 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -489,8 +489,8 @@ pg_walfile_name_offset(PG_FUNCTION_ARGS)
/*
* xlogfilename
*/
- XLByteToPrevSeg(locationpoint, xlogsegno);
- XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno);
+ XLByteToPrevSeg(locationpoint, xlogsegno, XLogSegSize);
+ XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno, XLogSegSize);
values[0] = CStringGetTextDatum(xlogfilename);
isnull[0] = false;
@@ -498,7 +498,7 @@ pg_walfile_name_offset(PG_FUNCTION_ARGS)
/*
* offset
*/
- xrecoff = XLogSegmentOffset(locationpoint);
+ xrecoff = XLogSegmentOffset(locationpoint, XLogSegSize);
values[1] = UInt32GetDatum(xrecoff);
isnull[1] = false;
@@ -530,8 +530,8 @@ pg_walfile_name(PG_FUNCTION_ARGS)
errmsg("recovery is in progress"),
errhint("pg_walfile_name() cannot be executed during recovery.")));
- XLByteToPrevSeg(locationpoint, xlogsegno);
- XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno);
+ XLByteToPrevSeg(locationpoint, xlogsegno, XLogSegSize);
+ XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno, XLogSegSize);
PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
}
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 02e38f6..a7d2e13 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -467,7 +467,7 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg)
{
/* Pretend it extends to end of segment */
state->EndRecPtr += XLogSegSize - 1;
- state->EndRecPtr -= XLogSegmentOffset(state->EndRecPtr);
+ state->EndRecPtr -= XLogSegmentOffset(state->EndRecPtr, XLogSegSize);
}
if (DecodeXLogRecord(state, record, errormsg))
@@ -509,8 +509,8 @@ ReadPageInternal(XLogReaderState *state, XLogRecPtr pageptr, int reqLen)
Assert((pageptr % XLOG_BLCKSZ) == 0);
- XLByteToSeg(pageptr, targetSegNo);
- targetPageOff = XLogSegmentOffset(pageptr);
+ XLByteToSeg(pageptr, targetSegNo, XLogSegSize);
+ targetPageOff = XLogSegmentOffset(pageptr, XLogSegSize);
/* check whether we have all the requested data already */
if (targetSegNo == state->readSegNo && targetPageOff == state->readOff &&
@@ -719,16 +719,16 @@ ValidXLogPageHeader(XLogReaderState *state, XLogRecPtr recptr,
Assert((recptr % XLOG_BLCKSZ) == 0);
- XLByteToSeg(recptr, segno);
- offset = XLogSegmentOffset(recptr);
+ XLByteToSeg(recptr, segno, XLogSegSize);
+ offset = XLogSegmentOffset(recptr, XLogSegSize);
- XLogSegNoOffsetToRecPtr(segno, offset, recaddr);
+ XLogSegNoOffsetToRecPtr(segno, offset, recaddr, XLogSegSize);
if (hdr->xlp_magic != XLOG_PAGE_MAGIC)
{
char fname[MAXFNAMELEN];
- XLogFileName(fname, state->readPageTLI, segno);
+ XLogFileName(fname, state->readPageTLI, segno, XLogSegSize);
report_invalid_record(state,
"invalid magic number %04X in log segment %s, offset %u",
@@ -742,7 +742,7 @@ ValidXLogPageHeader(XLogReaderState *state, XLogRecPtr recptr,
{
char fname[MAXFNAMELEN];
- XLogFileName(fname, state->readPageTLI, segno);
+ XLogFileName(fname, state->readPageTLI, segno, XLogSegSize);
report_invalid_record(state,
"invalid info bits %04X in log segment %s, offset %u",
@@ -792,7 +792,7 @@ ValidXLogPageHeader(XLogReaderState *state, XLogRecPtr recptr,
{
char fname[MAXFNAMELEN];
- XLogFileName(fname, state->readPageTLI, segno);
+ XLogFileName(fname, state->readPageTLI, segno, XLogSegSize);
/* hmm, first page of file doesn't have a long header? */
report_invalid_record(state,
@@ -807,7 +807,7 @@ ValidXLogPageHeader(XLogReaderState *state, XLogRecPtr recptr,
{
char fname[MAXFNAMELEN];
- XLogFileName(fname, state->readPageTLI, segno);
+ XLogFileName(fname, state->readPageTLI, segno, XLogSegSize);
report_invalid_record(state,
"unexpected pageaddr %X/%X in log segment %s, offset %u",
@@ -832,7 +832,7 @@ ValidXLogPageHeader(XLogReaderState *state, XLogRecPtr recptr,
{
char fname[MAXFNAMELEN];
- XLogFileName(fname, state->readPageTLI, segno);
+ XLogFileName(fname, state->readPageTLI, segno, XLogSegSize);
report_invalid_record(state,
"out-of-sequence timeline ID %u (after %u) in log segment %s, offset %u",
diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index c8f234e..f7778de 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -676,10 +676,10 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
int segbytes;
int readbytes;
- startoff = XLogSegmentOffset(recptr);
+ startoff = XLogSegmentOffset(recptr, XLogSegSize);
/* Do we need to switch to a different xlog segment? */
- if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo) ||
+ if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo, XLogSegSize) ||
sendTLI != tli)
{
char path[MAXPGPATH];
@@ -687,9 +687,9 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
if (sendFile >= 0)
close(sendFile);
- XLByteToSeg(recptr, sendSegNo);
+ XLByteToSeg(recptr, sendSegNo, XLogSegSize);
- XLogFilePath(path, tli, sendSegNo);
+ XLogFilePath(path, tli, sendSegNo, XLogSegSize);
sendFile = BasicOpenFile(path, O_RDONLY | PG_BINARY, 0);
@@ -717,7 +717,7 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
{
char path[MAXPGPATH];
- XLogFilePath(path, tli, sendSegNo);
+ XLogFilePath(path, tli, sendSegNo, XLogSegSize);
ereport(ERROR,
(errcode_for_file_access(),
@@ -740,7 +740,7 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
{
char path[MAXPGPATH];
- XLogFilePath(path, tli, sendSegNo);
+ XLogFilePath(path, tli, sendSegNo, XLogSegSize);
ereport(ERROR,
(errcode_for_file_access(),
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index f14f23a..d1c2e96 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -624,7 +624,7 @@ CheckArchiveTimeout(void)
* If the returned pointer points exactly to a segment boundary,
* assume nothing happened.
*/
- if (XLogSegmentOffset(switchpoint) != 0)
+ if (XLogSegmentOffset(switchpoint, XLogSegSize) != 0)
elog(DEBUG1, "write-ahead log switch forced (archive_timeout=%d)",
XLogArchiveTimeout);
}
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 9776858..9336f23 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -357,10 +357,10 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
* shouldn't be such files, but if there are, there's little harm in
* including them.
*/
- XLByteToSeg(startptr, startsegno);
- XLogFileName(firstoff, ThisTimeLineID, startsegno);
- XLByteToPrevSeg(endptr, endsegno);
- XLogFileName(lastoff, ThisTimeLineID, endsegno);
+ XLByteToSeg(startptr, startsegno, XLogSegSize);
+ XLogFileName(firstoff, ThisTimeLineID, startsegno, XLogSegSize);
+ XLByteToPrevSeg(endptr, endsegno, XLogSegSize);
+ XLogFileName(lastoff, ThisTimeLineID, endsegno, XLogSegSize);
dir = AllocateDir("pg_wal");
if (!dir)
@@ -415,12 +415,12 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
* Sanity check: the first and last segment should cover startptr and
* endptr, with no gaps in between.
*/
- XLogFromFileName(walFiles[0], &tli, &segno);
+ XLogFromFileName(walFiles[0], &tli, &segno, XLogSegSize);
if (segno != startsegno)
{
char startfname[MAXFNAMELEN];
- XLogFileName(startfname, ThisTimeLineID, startsegno);
+ XLogFileName(startfname, ThisTimeLineID, startsegno, XLogSegSize);
ereport(ERROR,
(errmsg("could not find WAL file \"%s\"", startfname)));
}
@@ -429,12 +429,12 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
XLogSegNo currsegno = segno;
XLogSegNo nextsegno = segno + 1;
- XLogFromFileName(walFiles[i], &tli, &segno);
+ XLogFromFileName(walFiles[i], &tli, &segno, XLogSegSize);
if (!(nextsegno == segno || currsegno == segno))
{
char nextfname[MAXFNAMELEN];
- XLogFileName(nextfname, ThisTimeLineID, nextsegno);
+ XLogFileName(nextfname, ThisTimeLineID, nextsegno, XLogSegSize);
ereport(ERROR,
(errmsg("could not find WAL file \"%s\"", nextfname)));
}
@@ -443,7 +443,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
{
char endfname[MAXFNAMELEN];
- XLogFileName(endfname, ThisTimeLineID, endsegno);
+ XLogFileName(endfname, ThisTimeLineID, endsegno, XLogSegSize);
ereport(ERROR,
(errmsg("could not find WAL file \"%s\"", endfname)));
}
@@ -457,7 +457,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
pgoff_t len = 0;
snprintf(pathbuf, MAXPGPATH, XLOGDIR "/%s", walFiles[i]);
- XLogFromFileName(walFiles[i], &tli, &segno);
+ XLogFromFileName(walFiles[i], &tli, &segno, XLogSegSize);
fp = AllocateFile(pathbuf, "rb");
if (fp == NULL)
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 657bafa..7a10705 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -2083,15 +2083,15 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
* store in segment in which it belongs by start lsn, don't split over
* multiple segments tho
*/
- if (fd == -1 || !XLByteInSeg(change->lsn, curOpenSegNo))
+ if (fd == -1 || !XLByteInSeg(change->lsn, curOpenSegNo, XLogSegSize))
{
XLogRecPtr recptr;
if (fd != -1)
CloseTransientFile(fd);
- XLByteToSeg(change->lsn, curOpenSegNo);
- XLogSegNoOffsetToRecPtr(curOpenSegNo, 0, recptr);
+ XLByteToSeg(change->lsn, curOpenSegNo, XLogSegSize);
+ XLogSegNoOffsetToRecPtr(curOpenSegNo, 0, recptr, XLogSegSize);
/*
* No need to care about TLIs here, only used during a single run,
@@ -2319,7 +2319,7 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn,
txn->nentries_mem = 0;
Assert(dlist_is_empty(&txn->changes));
- XLByteToSeg(txn->final_lsn, last_segno);
+ XLByteToSeg(txn->final_lsn, last_segno, XLogSegSize);
while (restored < max_changes_in_memory && *segno <= last_segno)
{
@@ -2334,11 +2334,11 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn,
/* first time in */
if (*segno == 0)
{
- XLByteToSeg(txn->first_lsn, *segno);
+ XLByteToSeg(txn->first_lsn, *segno, XLogSegSize);
}
Assert(*segno != 0 || dlist_is_empty(&txn->changes));
- XLogSegNoOffsetToRecPtr(*segno, 0, recptr);
+ XLogSegNoOffsetToRecPtr(*segno, 0, recptr, XLogSegSize);
/*
* No need to care about TLIs here, only used during a single run,
@@ -2575,8 +2575,8 @@ ReorderBufferRestoreCleanup(ReorderBuffer *rb, ReorderBufferTXN *txn)
Assert(txn->first_lsn != InvalidXLogRecPtr);
Assert(txn->final_lsn != InvalidXLogRecPtr);
- XLByteToSeg(txn->first_lsn, first);
- XLByteToSeg(txn->final_lsn, last);
+ XLByteToSeg(txn->first_lsn, first, XLogSegSize);
+ XLByteToSeg(txn->final_lsn, last, XLogSegSize);
/* iterate over all possible filenames, and delete them */
for (cur = first; cur <= last; cur++)
@@ -2584,7 +2584,7 @@ ReorderBufferRestoreCleanup(ReorderBuffer *rb, ReorderBufferTXN *txn)
char path[MAXPGPATH];
XLogRecPtr recptr;
- XLogSegNoOffsetToRecPtr(cur, 0, recptr);
+ XLogSegNoOffsetToRecPtr(cur, 0, recptr, XLogSegSize);
sprintf(path, "pg_replslot/%s/xid-%u-lsn-%X-%X.snap",
NameStr(MyReplicationSlot->data.name), txn->xid,
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index a8a16f5..7f06409 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -1039,7 +1039,7 @@ ReplicationSlotReserveWal(void)
* the new restart_lsn above, so normally we should never need to loop
* more than twice.
*/
- XLByteToSeg(slot->data.restart_lsn, segno);
+ XLByteToSeg(slot->data.restart_lsn, segno, XLogSegSize);
if (XLogGetLastRemovedSegno() < segno)
break;
}
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 768f8c7..3adc4d1 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -613,7 +613,7 @@ WalReceiverMain(void)
* Create .done file forcibly to prevent the streamed segment from
* being archived later.
*/
- XLogFileName(xlogfname, recvFileTLI, recvSegNo);
+ XLogFileName(xlogfname, recvFileTLI, recvSegNo, XLogSegSize);
if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS)
XLogArchiveForceDone(xlogfname);
else
@@ -943,7 +943,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
{
int segbytes;
- if (recvFile < 0 || !XLByteInSeg(recptr, recvSegNo))
+ if (recvFile < 0 || !XLByteInSeg(recptr, recvSegNo, XLogSegSize))
{
bool use_existent;
@@ -972,7 +972,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
* Create .done file forcibly to prevent the streamed segment
* from being archived later.
*/
- XLogFileName(xlogfname, recvFileTLI, recvSegNo);
+ XLogFileName(xlogfname, recvFileTLI, recvSegNo, XLogSegSize);
if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS)
XLogArchiveForceDone(xlogfname);
else
@@ -981,7 +981,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
recvFile = -1;
/* Create/use new log file */
- XLByteToSeg(recptr, recvSegNo);
+ XLByteToSeg(recptr, recvSegNo, XLogSegSize);
use_existent = true;
recvFile = XLogFileInit(recvSegNo, &use_existent, true);
recvFileTLI = ThisTimeLineID;
@@ -989,7 +989,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
}
/* Calculate the start offset of the received logs */
- startoff = XLogSegmentOffset(recptr);
+ startoff = XLogSegmentOffset(recptr, XLogSegSize);
if (startoff + nbytes > XLogSegSize)
segbytes = XLogSegSize - startoff;
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index a7338dd..0ec5c2a 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -233,8 +233,8 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo,
* being created by XLOG streaming, which might cause trouble later on if
* the segment is e.g archived.
*/
- if (XLogSegmentOffset(recptr) != 0)
- recptr -= XLogSegmentOffset(recptr);
+ if (XLogSegmentOffset(recptr, XLogSegSize) != 0)
+ recptr -= XLogSegmentOffset(recptr, XLogSegSize);
SpinLockAcquire(&walrcv->mutex);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 7626cfa..ae5e040 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -2316,9 +2316,9 @@ retry:
int segbytes;
int readbytes;
- startoff = XLogSegmentOffset(recptr);
+ startoff = XLogSegmentOffset(recptr, XLogSegSize);
- if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo))
+ if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo, XLogSegSize))
{
char path[MAXPGPATH];
@@ -2326,7 +2326,7 @@ retry:
if (sendFile >= 0)
close(sendFile);
- XLByteToSeg(recptr, sendSegNo);
+ XLByteToSeg(recptr, sendSegNo, XLogSegSize);
/*-------
* When reading from a historic timeline, and there is a timeline
@@ -2359,12 +2359,12 @@ retry:
{
XLogSegNo endSegNo;
- XLByteToSeg(sendTimeLineValidUpto, endSegNo);
+ XLByteToSeg(sendTimeLineValidUpto, endSegNo, XLogSegSize);
if (sendSegNo == endSegNo)
curFileTimeLine = sendTimeLineNextTLI;
}
- XLogFilePath(path, curFileTimeLine, sendSegNo);
+ XLogFilePath(path, curFileTimeLine, sendSegNo, XLogSegSize);
sendFile = BasicOpenFile(path, O_RDONLY | PG_BINARY, 0);
if (sendFile < 0)
@@ -2433,7 +2433,7 @@ retry:
* read() succeeds in that case, but the data we tried to read might
* already have been overwritten with new WAL records.
*/
- XLByteToSeg(startptr, segno);
+ XLByteToSeg(startptr, segno, XLogSegSize);
CheckXLogRemoved(segno, ThisTimeLineID);
/*
diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c
index 0dbfe7f..9cb32d5 100644
--- a/src/backend/utils/misc/pg_controldata.c
+++ b/src/backend/utils/misc/pg_controldata.c
@@ -141,8 +141,8 @@ pg_control_checkpoint(PG_FUNCTION_ARGS)
* Calculate name of the WAL file containing the latest checkpoint's REDO
* start point.
*/
- XLByteToSeg(ControlFile->checkPointCopy.redo, segno);
- XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID, segno);
+ XLByteToSeg(ControlFile->checkPointCopy.redo, segno, XLogSegSize);
+ XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID, segno, XLogSegSize);
/* Populate the values and null arrays */
values[0] = LSNGetDatum(ControlFile->checkPoint);
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 6886e35..b3142bb 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -556,7 +556,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
}
param->startptr = ((uint64) hi) << 32 | lo;
/* Round off to even segment position */
- param->startptr -= XLogSegmentOffset(param->startptr);
+ param->startptr -= XLogSegmentOffset(param->startptr, WalSegsz);
#ifndef WIN32
/* Create our background pipe */
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index 442d5bc..89a43aa 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -179,7 +179,7 @@ close_destination_dir(DIR *dest_dir, char *dest_folder)
/*
* Determine starting location for streaming, based on any existing xlog
* segments in the directory. We start at the end of the last one that is
- * complete (size matches XLogSegSize), on the timeline with highest ID.
+ * complete (size matches wal segment size), on the timeline with highest ID.
*
* If there are no WAL files in the directory, returns InvalidXLogRecPtr.
*/
@@ -230,7 +230,7 @@ FindStreamingStart(uint32 *tli)
/*
* Looks like an xlog file. Parse its position.
*/
- XLogFromFileName(dirent->d_name, &tli, &segno);
+ XLogFromFileName(dirent->d_name, &tli, &segno, WalSegsz);
/*
* Check that the segment has the right size, if it's supposed to be
@@ -255,7 +255,7 @@ FindStreamingStart(uint32 *tli)
disconnect_and_exit(1);
}
- if (statbuf.st_size != XLogSegSize)
+ if (statbuf.st_size != WalSegsz)
{
fprintf(stderr,
_("%s: segment file \"%s\" has incorrect size %d, skipping\n"),
@@ -296,7 +296,7 @@ FindStreamingStart(uint32 *tli)
bytes_out = (buf[3] << 24) | (buf[2] << 16) |
(buf[1] << 8) | buf[0];
- if (bytes_out != XLogSegSize)
+ if (bytes_out != WalSegsz)
{
fprintf(stderr,
_("%s: compressed segment file \"%s\" has incorrect uncompressed size %d, skipping\n"),
@@ -337,7 +337,7 @@ FindStreamingStart(uint32 *tli)
if (!high_ispartial)
high_segno++;
- XLogSegNoOffsetToRecPtr(high_segno, 0, high_ptr);
+ XLogSegNoOffsetToRecPtr(high_segno, 0, high_ptr, WalSegsz);
*tli = high_tli;
return high_ptr;
@@ -398,7 +398,7 @@ StreamLog(void)
/*
* Always start streaming at the beginning of a segment
*/
- stream.startpos -= XLogSegmentOffset(stream.startpos);
+ stream.startpos -= XLogSegmentOffset(stream.startpos, WalSegsz);
/*
* Start the replication
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index fd3ce0a..3303bb2 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -95,8 +95,8 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
ssize_t size;
XLogSegNo segno;
- XLByteToSeg(startpoint, segno);
- XLogFileName(current_walfile_name, stream->timeline, segno);
+ XLByteToSeg(startpoint, segno, WalSegsz);
+ XLogFileName(current_walfile_name, stream->timeline, segno, WalSegsz);
snprintf(fn, sizeof(fn), "%s%s", current_walfile_name,
stream->partial_suffix ? stream->partial_suffix : "");
@@ -120,7 +120,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
progname, fn, stream->walmethod->getlasterror());
return false;
}
- if (size == XLogSegSize)
+ if (size == WalSegsz)
{
/* Already padded file. Open it for use */
f = stream->walmethod->open_for_write(current_walfile_name, stream->partial_suffix, 0);
@@ -154,7 +154,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
ngettext("%s: write-ahead log file \"%s\" has %d byte, should be 0 or %d\n",
"%s: write-ahead log file \"%s\" has %d bytes, should be 0 or %d\n",
size),
- progname, fn, (int) size, XLogSegSize);
+ progname, fn, (int) size, WalSegsz);
return false;
}
/* File existed and was empty, so fall through and open */
@@ -162,7 +162,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
/* No file existed, so create one */
- f = stream->walmethod->open_for_write(current_walfile_name, stream->partial_suffix, XLogSegSize);
+ f = stream->walmethod->open_for_write(current_walfile_name, stream->partial_suffix, WalSegsz);
if (f == NULL)
{
fprintf(stderr,
@@ -203,7 +203,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
if (stream->partial_suffix)
{
- if (currpos == XLogSegSize)
+ if (currpos == WalSegsz)
r = stream->walmethod->close(walfile, CLOSE_NORMAL);
else
{
@@ -231,7 +231,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
* new node. This is in line with walreceiver.c always doing a
* XLogArchiveForceDone() after a complete segment.
*/
- if (currpos == XLogSegSize && stream->mark_done)
+ if (currpos == WalSegsz && stream->mark_done)
{
/* writes error message if failed */
if (!mark_file_as_archived(stream, current_walfile_name))
@@ -676,7 +676,8 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
* start streaming at the beginning of a segment.
*/
stream->timeline = newtimeline;
- stream->startpos = stream->startpos - XLogSegmentOffset(stream->startpos);
+ stream->startpos = stream->startpos -
+ XLogSegmentOffset(stream->startpos, WalSegsz);
continue;
}
else if (PQresultStatus(res) == PGRES_COMMAND_OK)
@@ -1111,7 +1112,7 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
*blockpos = fe_recvint64(©buf[1]);
/* Extract WAL location for this block */
- xlogoff = XLogSegmentOffset(*blockpos);
+ xlogoff = XLogSegmentOffset(*blockpos, WalSegsz);
/*
* Verify that the initial location in the stream matches where we think
@@ -1148,11 +1149,11 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
int bytes_to_write;
/*
- * If crossing a WAL boundary, only write up until we reach
- * XLogSegSize.
+ * If crossing a WAL boundary, only write up until we reach wal
+ * segment size.
*/
- if (xlogoff + bytes_left > XLogSegSize)
- bytes_to_write = XLogSegSize - xlogoff;
+ if (xlogoff + bytes_left > WalSegsz)
+ bytes_to_write = WalSegsz - xlogoff;
else
bytes_to_write = bytes_left;
@@ -1182,7 +1183,7 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
xlogoff += bytes_to_write;
/* Did we reach the end of a WAL segment? */
- if (XLogSegmentOffset(*blockpos) == 0)
+ if (XLogSegmentOffset(*blockpos, WalSegsz) == 0)
{
if (!close_walfile(stream, *blockpos))
/* Error message written in close_walfile() */
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 3806b59..84bd0db 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -32,7 +32,7 @@
#define ERRCODE_DUPLICATE_OBJECT "42710"
-int XLogSegSize;
+uint32 WalSegsz;
/* SHOW command for replication connection was introduced in version 10 */
#define MINIMUM_VERSION_FOR_SHOW_CMD 100000
@@ -238,7 +238,7 @@ GetConnection(void)
}
/*
- * From version 10, explicitly set XLogSegSize using SHOW wal_segment_size
+ * From version 10, explicitly set wal segment size using SHOW wal_segment_size
* since ControlFile is not accessible here.
*/
bool
@@ -255,7 +255,7 @@ RetrieveXLogSegSize(PGconn *conn)
/* for previous versions set the default xlog seg size */
if (PQserverVersion(conn) < MINIMUM_VERSION_FOR_SHOW_CMD)
{
- XLogSegSize = DEFAULT_XLOG_SEG_SIZE;
+ WalSegsz = DEFAULT_XLOG_SEG_SIZE;
return true;
}
@@ -286,20 +286,20 @@ RetrieveXLogSegSize(PGconn *conn)
return false;
}
- /* set the multiplier based on unit to convert XLogSegSize to bytes */
+ /* set the multiplier based on unit to convert xlog_val to bytes */
if (strcmp(xlog_unit, "MB") == 0)
multiplier = 1024 * 1024;
else if (strcmp(xlog_unit, "GB") == 0)
multiplier = 1024 * 1024 * 1024;
- /* convert and set XLogSegSize */
- XLogSegSize = xlog_val * multiplier;
+ /* convert and set WalSegsz */
+ WalSegsz = xlog_val * multiplier;
- if (!IsValidXLogSegSize(XLogSegSize))
+ if (!IsValidXLogSegSize(WalSegsz))
{
fprintf(stderr,
_("%s: WAL segment size must be a power of two between 1MB and 1GB, but the remote server reported a value of %d bytes\n"),
- progname, XLogSegSize);
+ progname, WalSegsz);
return false;
}
diff --git a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
index 6fb85ba..ee9a814 100644
--- a/src/bin/pg_basebackup/streamutil.h
+++ b/src/bin/pg_basebackup/streamutil.h
@@ -24,6 +24,7 @@ extern char *dbuser;
extern char *dbport;
extern char *dbname;
extern int dbgetpassword;
+extern uint32 WalSegsz;
/* Connection kept global so we can disconnect easily */
extern PGconn *conn;
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 9c7ea0e..59642cc 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -26,8 +26,6 @@
#include "common/controldata_utils.h"
#include "pg_getopt.h"
-int XLogSegSize;
-
static void
usage(const char *progname)
{
@@ -100,6 +98,7 @@ main(int argc, char *argv[])
char xlogfilename[MAXFNAMELEN];
int c;
int i;
+ int WalSegsz;
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata"));
@@ -165,13 +164,13 @@ main(int argc, char *argv[])
"Either the file is corrupt, or it has a different layout than this program\n"
"is expecting. The results below are untrustworthy.\n\n"));
- /* set XLogSegSize */
- XLogSegSize = ControlFile->xlog_seg_size;
+ /* set wal segment size */
+ WalSegsz = ControlFile->xlog_seg_size;
- if (!IsValidXLogSegSize(XLogSegSize))
+ if (!IsValidXLogSegSize(WalSegsz))
fprintf(stderr,
_("WARNING: WAL segment size specified, %d bytes, is not a power of two between 1MB and 1GB. The file is corrupt and the results below are untrustworthy."),
- XLogSegSize);
+ WalSegsz);
/*
* This slightly-chintzy coding will work as long as the control file
@@ -193,8 +192,9 @@ main(int argc, char *argv[])
* Calculate name of the WAL file containing the latest checkpoint's REDO
* start point.
*/
- XLByteToSeg(ControlFile->checkPointCopy.redo, segno);
- XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID, segno);
+ XLByteToSeg(ControlFile->checkPointCopy.redo, segno, WalSegsz);
+ XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID,
+ segno, WalSegsz);
/*
* Format system_identifier and mock_authentication_nonce separately to
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index 319170e..09e005c 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -56,8 +56,6 @@
#include "storage/large_object.h"
#include "pg_getopt.h"
-int XLogSegSize;
-
static ControlFileData ControlFile; /* pg_control values */
static XLogSegNo newXlogSegNo; /* new XLOG segment # */
static bool guessed = false; /* T if we had to guess at any values */
@@ -71,6 +69,7 @@ static MultiXactId set_mxid = 0;
static MultiXactOffset set_mxoff = (MultiXactOffset) -1;
static uint32 minXlogTli = 0;
static XLogSegNo minXlogSegNo = 0;
+static int WalSegsz;
static void CheckDataVersion(void);
static bool ReadControlFile(void);
@@ -269,8 +268,8 @@ main(int argc, char *argv[])
}
/*
- * XLogFromFileName requires XLogSegSize which is not yet
- * set. Hence XLog details are set later on.
+ * XLogFromFileName requires wal segment size which is not yet
+ * set. Hence wal details are set later on.
*/
log_fname = pg_strdup(optarg);
break;
@@ -358,7 +357,7 @@ main(int argc, char *argv[])
GuessControlValues();
if (log_fname != NULL)
- XLogFromFileName(log_fname, &minXlogTli, &minXlogSegNo);
+ XLogFromFileName(log_fname, &minXlogTli, &minXlogSegNo, WalSegsz);
/*
* Also look at existing segment files to set up newXlogSegNo
@@ -592,14 +591,14 @@ ReadControlFile(void)
}
memcpy(&ControlFile, buffer, sizeof(ControlFile));
- XLogSegSize = ControlFile.xlog_seg_size;
+ WalSegsz = ControlFile.xlog_seg_size;
- /* return false if XLogSegSize is not valid */
- if (!IsValidXLogSegSize(XLogSegSize))
+ /* return false if WalSegsz is not valid */
+ if (!IsValidXLogSegSize(WalSegsz))
{
fprintf(stderr,
_("%s: WAL segment size must be a power of two between 1MB and 1GB; ignoring control file specifying %d bytes\n"),
- progname, XLogSegSize);
+ progname, WalSegsz);
return false;
}
@@ -791,7 +790,8 @@ PrintNewControlValues(void)
/* This will be always printed in order to keep format same. */
printf(_("\n\nValues to be changed:\n\n"));
- XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID, newXlogSegNo);
+ XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID,
+ newXlogSegNo, WalSegsz);
printf(_("First log segment after reset: %s\n"), fname);
if (set_mxid != 0)
@@ -868,7 +868,7 @@ RewriteControlFile(void)
* newXlogSegNo.
*/
XLogSegNoOffsetToRecPtr(newXlogSegNo, SizeOfXLogLongPHD,
- ControlFile.checkPointCopy.redo);
+ ControlFile.checkPointCopy.redo, WalSegsz);
ControlFile.checkPointCopy.time = (pg_time_t) time(NULL);
ControlFile.state = DB_SHUTDOWNED;
@@ -895,7 +895,7 @@ RewriteControlFile(void)
ControlFile.max_locks_per_xact = 64;
/* Now we can force the recorded xlog seg size to the right thing. */
- ControlFile.xlog_seg_size = XLogSegSize;
+ ControlFile.xlog_seg_size = WalSegsz;
/* Contents are protected with a CRC */
INIT_CRC32C(ControlFile.crc);
@@ -1032,7 +1032,7 @@ FindEndOfXLOG(void)
* are in virgin territory.
*/
xlogbytepos = newXlogSegNo * ControlFile.xlog_seg_size;
- newXlogSegNo = (xlogbytepos + XLogSegSize - 1) / XLogSegSize;
+ newXlogSegNo = (xlogbytepos + WalSegsz - 1) / WalSegsz;
newXlogSegNo++;
}
@@ -1169,7 +1169,7 @@ WriteEmptyXLOG(void)
page->xlp_pageaddr = ControlFile.checkPointCopy.redo - SizeOfXLogLongPHD;
longpage = (XLogLongPageHeader) page;
longpage->xlp_sysid = ControlFile.system_identifier;
- longpage->xlp_seg_size = XLogSegSize;
+ longpage->xlp_seg_size = WalSegsz;
longpage->xlp_xlog_blcksz = XLOG_BLCKSZ;
/* Insert the initial checkpoint record */
@@ -1194,7 +1194,8 @@ WriteEmptyXLOG(void)
record->xl_crc = crc;
/* Write the first page */
- XLogFilePath(path, ControlFile.checkPointCopy.ThisTimeLineID, newXlogSegNo);
+ XLogFilePath(path, ControlFile.checkPointCopy.ThisTimeLineID,
+ newXlogSegNo, WalSegsz);
unlink(path);
@@ -1220,7 +1221,7 @@ WriteEmptyXLOG(void)
/* Fill the rest of the file with zeroes */
memset(buffer, 0, XLOG_BLCKSZ);
- for (nbytes = XLOG_BLCKSZ; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ)
+ for (nbytes = XLOG_BLCKSZ; nbytes < WalSegsz; nbytes += XLOG_BLCKSZ)
{
errno = 0;
if (write(fd, buffer, XLOG_BLCKSZ) != XLOG_BLCKSZ)
diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c
index c5e00da..8693462 100644
--- a/src/bin/pg_rewind/parsexlog.c
+++ b/src/bin/pg_rewind/parsexlog.c
@@ -170,7 +170,8 @@ findLastCheckpoint(const char *datadir, XLogRecPtr forkptr, int tliIndex,
* header in that case to find the next record.
*/
if (forkptr % XLOG_BLCKSZ == 0)
- forkptr += (XLogSegmentOffset(forkptr) == 0) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD;
+ forkptr += (XLogSegmentOffset(forkptr, XLogSegSize) == 0) ?
+ SizeOfXLogLongPHD : SizeOfXLogShortPHD;
private.datadir = datadir;
private.tliIndex = tliIndex;
@@ -239,21 +240,21 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
XLogRecPtr targetSegEnd;
XLogSegNo targetSegNo;
- XLByteToSeg(targetPagePtr, targetSegNo);
- XLogSegNoOffsetToRecPtr(targetSegNo + 1, 0, targetSegEnd);
- targetPageOff = XLogSegmentOffset(targetPagePtr);
+ XLByteToSeg(targetPagePtr, targetSegNo, XLogSegSize);
+ XLogSegNoOffsetToRecPtr(targetSegNo + 1, 0, targetSegEnd, XLogSegSize);
+ targetPageOff = XLogSegmentOffset(targetPagePtr, XLogSegSize);
/*
* See if we need to switch to a new segment because the requested record
* is not in the currently open one.
*/
- if (xlogreadfd >= 0 && !XLByteInSeg(targetPagePtr, xlogreadsegno))
+ if (xlogreadfd >= 0 && !XLByteInSeg(targetPagePtr, xlogreadsegno, XLogSegSize))
{
close(xlogreadfd);
xlogreadfd = -1;
}
- XLByteToSeg(targetPagePtr, xlogreadsegno);
+ XLByteToSeg(targetPagePtr, xlogreadsegno, XLogSegSize);
if (xlogreadfd < 0)
{
@@ -272,7 +273,8 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
targetHistory[private->tliIndex].begin >= targetSegEnd)
private->tliIndex--;
- XLogFileName(xlogfname, targetHistory[private->tliIndex].tli, xlogreadsegno);
+ XLogFileName(xlogfname, targetHistory[private->tliIndex].tli,
+ xlogreadsegno, XLogSegSize);
snprintf(xlogfpath, MAXPGPATH, "%s/" XLOGDIR "/%s", private->datadir, xlogfname);
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 53883a5..52209ed 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -573,8 +573,8 @@ createBackupLabel(XLogRecPtr startpoint, TimeLineID starttli, XLogRecPtr checkpo
char buf[1000];
int len;
- XLByteToSeg(startpoint, startsegno);
- XLogFileName(xlogfilename, starttli, startsegno);
+ XLByteToSeg(startpoint, startsegno, XLogSegSize);
+ XLogFileName(xlogfilename, starttli, startsegno, XLogSegSize);
/*
* Construct backup label file
diff --git a/src/bin/pg_rewind/pg_rewind.h b/src/bin/pg_rewind/pg_rewind.h
index 31353dd..ed6f1b4 100644
--- a/src/bin/pg_rewind/pg_rewind.h
+++ b/src/bin/pg_rewind/pg_rewind.h
@@ -29,6 +29,8 @@ extern bool dry_run;
extern TimeLineHistoryEntry *targetHistory;
extern int targetNentries;
+extern int XLogSegSize;
+
/* in parsexlog.c */
extern void extractPageMap(const char *datadir, XLogRecPtr startpoint,
int tliIndex, XLogRecPtr endpoint);
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index b9819b7..cf27bff 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -338,9 +338,9 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
int segbytes;
int readbytes;
- startoff = XLogSegmentOffset(recptr);
+ startoff = XLogSegmentOffset(recptr, XLogSegSize);
- if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo))
+ if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo, XLogSegSize))
{
char fname[MAXFNAMELEN];
int tries;
@@ -349,9 +349,9 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
if (sendFile >= 0)
close(sendFile);
- XLByteToSeg(recptr, sendSegNo);
+ XLByteToSeg(recptr, sendSegNo, XLogSegSize);
- XLogFileName(fname, timeline_id, sendSegNo);
+ XLogFileName(fname, timeline_id, sendSegNo, XLogSegSize);
/*
* In follow mode there is a short period of time after the server
@@ -392,7 +392,7 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
int err = errno;
char fname[MAXPGPATH];
- XLogFileName(fname, timeline_id, sendSegNo);
+ XLogFileName(fname, timeline_id, sendSegNo, XLogSegSize);
fatal_error("could not seek in log file %s to offset %u: %s",
fname, startoff, strerror(err));
@@ -412,7 +412,7 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
int err = errno;
char fname[MAXPGPATH];
- XLogFileName(fname, timeline_id, sendSegNo);
+ XLogFileName(fname, timeline_id, sendSegNo, XLogSegSize);
fatal_error("could not read from log file %s, offset %u, length %d: %s",
fname, sendOff, segbytes, strerror(err));
@@ -1036,11 +1036,11 @@ main(int argc, char **argv)
close(fd);
/* parse position from file */
- XLogFromFileName(fname, &private.timeline, &segno);
+ XLogFromFileName(fname, &private.timeline, &segno, XLogSegSize);
if (XLogRecPtrIsInvalid(private.startptr))
- XLogSegNoOffsetToRecPtr(segno, 0, private.startptr);
- else if (!XLByteInSeg(private.startptr, segno))
+ XLogSegNoOffsetToRecPtr(segno, 0, private.startptr, XLogSegSize);
+ else if (!XLByteInSeg(private.startptr, segno, XLogSegSize))
{
fprintf(stderr,
_("%s: start WAL location %X/%X is not inside file \"%s\"\n"),
@@ -1053,7 +1053,7 @@ main(int argc, char **argv)
/* no second file specified, set end position */
if (!(optind + 1 < argc) && XLogRecPtrIsInvalid(private.endptr))
- XLogSegNoOffsetToRecPtr(segno + 1, 0, private.endptr);
+ XLogSegNoOffsetToRecPtr(segno + 1, 0, private.endptr, XLogSegSize);
/* parse ENDSEG if passed */
if (optind + 1 < argc)
@@ -1069,21 +1069,22 @@ main(int argc, char **argv)
close(fd);
/* parse position from file */
- XLogFromFileName(fname, &private.timeline, &endsegno);
+ XLogFromFileName(fname, &private.timeline, &endsegno, XLogSegSize);
if (endsegno < segno)
fatal_error("ENDSEG %s is before STARTSEG %s",
argv[optind + 1], argv[optind]);
if (XLogRecPtrIsInvalid(private.endptr))
- XLogSegNoOffsetToRecPtr(endsegno + 1, 0, private.endptr);
+ XLogSegNoOffsetToRecPtr(endsegno + 1, 0, private.endptr,
+ XLogSegSize);
/* set segno to endsegno for check of --end */
segno = endsegno;
}
- if (!XLByteInSeg(private.endptr, segno) &&
+ if (!XLByteInSeg(private.endptr, segno, XLogSegSize) &&
private.endptr != (segno + 1) * XLogSegSize)
{
fprintf(stderr,
@@ -1125,7 +1126,8 @@ main(int argc, char **argv)
* to the start of a record and also wasn't a pointer to the beginning of
* a segment (e.g. we were used in file mode).
*/
- if (first_record != private.startptr && XLogSegmentOffset(private.startptr) != 0)
+ if (first_record != private.startptr &&
+ XLogSegmentOffset(private.startptr, XLogSegSize) != 0)
printf(ngettext("first record is after %X/%X, at %X/%X, skipping over %u byte\n",
"first record is after %X/%X, at %X/%X, skipping over %u bytes\n",
(first_record - private.startptr)),
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index f2084ca..0c45d65 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -106,13 +106,14 @@ extern int XLogSegSize;
(IsPowerOf2(size) && \
((size) >= XLogSegMinSize && (size) <= XLogSegMaxSize))
-#define XLogSegmentsPerXLogId (UINT64CONST(0x100000000) / XLogSegSize)
+#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
+ (UINT64CONST(0x100000000) / (wal_segsz_bytes))
-#define XLogSegNoOffsetToRecPtr(segno, offset, dest) \
- (dest) = (segno) * (XLogSegSize) + (offset)
+#define XLogSegNoOffsetToRecPtr(segno, offset, dest, wal_segsz_bytes) \
+ (dest) = (segno) * (wal_segsz_bytes) + (offset)
-#define XLogSegmentOffset(xlogptr) \
- ((xlogptr) & (XLogSegSize - 1))
+#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
+ ((xlogptr) & ((wal_segsz_bytes) - 1))
/*
* Compute a segment number from an XLogRecPtr.
@@ -122,11 +123,11 @@ extern int XLogSegSize;
* for deciding which segment to write given a pointer to a record end,
* for example.
*/
-#define XLByteToSeg(xlrp, logSegNo) \
- logSegNo = (xlrp) / XLogSegSize
+#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = (xlrp) / (wal_segsz_bytes)
-#define XLByteToPrevSeg(xlrp, logSegNo) \
- logSegNo = ((xlrp) - 1) / XLogSegSize
+#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
/*
* Is an XLogRecPtr within a particular XLOG segment?
@@ -134,11 +135,11 @@ extern int XLogSegSize;
* For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
* a boundary byte is taken to be in the previous segment.
*/
-#define XLByteInSeg(xlrp, logSegNo) \
- (((xlrp) / XLogSegSize) == (logSegNo))
+#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
-#define XLByteInPrevSeg(xlrp, logSegNo) \
- ((((xlrp) - 1) / XLogSegSize) == (logSegNo))
+#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
/* Check if an XLogRecPtr value is in a plausible range */
#define XRecOffIsValid(xlrp) \
@@ -159,10 +160,10 @@ extern int XLogSegSize;
/* Length of XLog file name */
#define XLOG_FNAME_LEN 24
-#define XLogFileName(fname, tli, logSegNo) \
+#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes) \
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
- (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
- (uint32) ((logSegNo) % XLogSegmentsPerXLogId))
+ (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
+ (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
#define XLogFileNameById(fname, tli, log, seg) \
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
@@ -181,18 +182,18 @@ extern int XLogSegSize;
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0)
-#define XLogFromFileName(fname, tli, logSegNo) \
+#define XLogFromFileName(fname, tli, logSegNo, wal_segsz_bytes) \
do { \
uint32 log; \
uint32 seg; \
sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \
- *logSegNo = (uint64) log * XLogSegmentsPerXLogId + seg; \
+ *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg; \
} while (0)
-#define XLogFilePath(path, tli, logSegNo) \
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \
- (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
- (uint32) ((logSegNo) % XLogSegmentsPerXLogId))
+#define XLogFilePath(path, tli, logSegNo, wal_segsz_bytes) \
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \
+ (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
+ (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
#define TLHistoryFileName(fname, tli) \
snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
@@ -208,20 +209,22 @@ extern int XLogSegSize;
#define StatusFilePath(path, xlog, suffix) \
snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
-#define BackupHistoryFileName(fname, tli, logSegNo, offset) \
+#define BackupHistoryFileName(fname, tli, logSegNo, startpoint, wal_segsz_bytes) \
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \
- (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
- (uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
+ (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
+ (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
+ (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)))
#define IsBackupHistoryFileName(fname) \
(strlen(fname) > XLOG_FNAME_LEN && \
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0)
-#define BackupHistoryFilePath(path, tli, logSegNo, offset) \
+#define BackupHistoryFilePath(path, tli, logSegNo, startpoint, wal_segsz_bytes) \
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \
- (uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
- (uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
+ (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
+ (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
+ (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)))
/*
* Information logged when we detect a change in one of the parameters