From dfda6ebaec6763090fb78b458a979b558c50b39b Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Sun, 24 Jun 2012 18:06:38 +0300 Subject: Don't waste the last segment of each 4GB logical log file. The comments claimed that wasting the last segment made it easier to do calculations with XLogRecPtrs, because you don't have problems representing last-byte-position-plus-1 that way. In my experience, however, it only made things more complicated, because the there was two ways to represent the boundary at the beginning of a logical log file: logid = n+1 and xrecoff = 0, or as xlogid = n and xrecoff = 4GB - XLOG_SEG_SIZE. Some functions were picky about which representation was used. Also, use a 64-bit segment number instead of the log/seg combination, to point to a certain WAL segment. We assume that all platforms have a working 64-bit integer type nowadays. This is an incompatible change in WAL format, so bumping WAL version number. --- src/backend/replication/basebackup.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/backend/replication/basebackup.c') diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 0bc88a4040..14c42b46c2 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -221,10 +221,8 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) * We've left the last tar file "open", so we can now append the * required WAL files to it. */ - uint32 logid, - logseg; - uint32 endlogid, - endlogseg; + XLogSegNo logsegno; + XLogSegNo endlogsegno; struct stat statbuf; MemSet(&statbuf, 0, sizeof(statbuf)); @@ -236,8 +234,8 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) statbuf.st_size = XLogSegSize; statbuf.st_mtime = time(NULL); - XLByteToSeg(startptr, logid, logseg); - XLByteToPrevSeg(endptr, endlogid, endlogseg); + XLByteToSeg(startptr, logsegno); + XLByteToPrevSeg(endptr, endlogsegno); while (true) { @@ -245,7 +243,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) char fn[MAXPGPATH]; int i; - XLogFilePath(fn, ThisTimeLineID, logid, logseg); + XLogFilePath(fn, ThisTimeLineID, logsegno); _tarWriteHeader(fn, NULL, &statbuf); /* Send the actual WAL file contents, block-by-block */ @@ -254,8 +252,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) char buf[TAR_SEND_SIZE]; XLogRecPtr ptr; - ptr.xlogid = logid; - ptr.xrecoff = logseg * XLogSegSize + TAR_SEND_SIZE * i; + XLogSegNoOffsetToRecPtr(logsegno, TAR_SEND_SIZE * i, ptr); /* * Some old compilers, e.g. gcc 2.95.3/x86, think that passing @@ -277,11 +274,10 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) /* Advance to the next WAL file */ - NextLogSeg(logid, logseg); + logsegno++; /* Have we reached our stop position yet? */ - if (logid > endlogid || - (logid == endlogid && logseg > endlogseg)) + if (logsegno > endlogsegno) break; } -- cgit v1.2.1