diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-06-24 18:06:38 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-06-24 18:35:29 +0300 |
commit | dfda6ebaec6763090fb78b458a979b558c50b39b (patch) | |
tree | 15720cd5663330a8c0bc1875d1041fbecd413130 /src/bin/pg_basebackup/pg_receivexlog.c | |
parent | 47c7365e794a0a57382efefbf1f2b062c7a3e3d3 (diff) | |
download | postgresql-dfda6ebaec6763090fb78b458a979b558c50b39b.tar.gz |
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.
Diffstat (limited to 'src/bin/pg_basebackup/pg_receivexlog.c')
-rw-r--r-- | src/bin/pg_basebackup/pg_receivexlog.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c index 20adb653cf..4b109f4b96 100644 --- a/src/bin/pg_basebackup/pg_receivexlog.c +++ b/src/bin/pg_basebackup/pg_receivexlog.c @@ -102,8 +102,7 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) struct dirent *dirent; int i; bool b; - uint32 high_log = 0; - uint32 high_seg = 0; + XLogSegNo high_segno = 0; dir = opendir(basedir); if (dir == NULL) @@ -117,9 +116,10 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) { char fullpath[MAXPGPATH]; struct stat statbuf; - uint32 tli, - log, + uint32 tli; + unsigned int log, seg; + XLogSegNo segno; if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue; @@ -151,6 +151,7 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) progname, dirent->d_name); disconnect_and_exit(1); } + segno = ((uint64) log) << 32 | seg; /* Ignore any files that are for another timeline */ if (tli != currenttimeline) @@ -168,11 +169,9 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) if (statbuf.st_size == XLOG_SEG_SIZE) { /* Completed segment */ - if (log > high_log || - (log == high_log && seg > high_seg)) + if (segno > high_segno) { - high_log = log; - high_seg = seg; + high_segno = segno; continue; } } @@ -186,7 +185,7 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) closedir(dir); - if (high_log > 0 || high_seg > 0) + if (high_segno > 0) { XLogRecPtr high_ptr; @@ -194,10 +193,9 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) * Move the starting pointer to the start of the next segment, since * the highest one we've seen was completed. */ - NextLogSeg(high_log, high_seg); + high_segno++; - high_ptr.xlogid = high_log; - high_ptr.xrecoff = high_seg * XLOG_SEG_SIZE; + XLogSegNoOffsetToRecPtr(high_segno, 0, high_ptr); return high_ptr; } |