aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2016-09-30 11:19:30 +0200
committerMagnus Hagander <magnus@hagander.net>2016-09-30 11:22:20 +0200
commit41d58e97afe4c24398a5469f79468a50895b3ab0 (patch)
treedb1b691630bf9dee817abca9c55839cc95634d6d /src
parent7341c2830cf3d06a96d97f0e6a2e85bf808faae4 (diff)
downloadpostgresql-41d58e97afe4c24398a5469f79468a50895b3ab0.tar.gz
postgresql-41d58e97afe4c24398a5469f79468a50895b3ab0.zip
Retry opening new segments in pg_xlogdump --folllow
There is a small window between when the server closes out the existing segment and the new one is created. Put a loop around the open call in this case to make sure we wait for the new file to actually appear.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_xlogdump/pg_xlogdump.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/bin/pg_xlogdump/pg_xlogdump.c b/src/bin/pg_xlogdump/pg_xlogdump.c
index 02575eb1c57..9ad9321e1f9 100644
--- a/src/bin/pg_xlogdump/pg_xlogdump.c
+++ b/src/bin/pg_xlogdump/pg_xlogdump.c
@@ -249,6 +249,7 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo))
{
char fname[MAXFNAMELEN];
+ int tries;
/* Switch to another logfile segment */
if (sendFile >= 0)
@@ -258,7 +259,30 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
XLogFileName(fname, timeline_id, sendSegNo);
- sendFile = fuzzy_open_file(directory, fname);
+ /*
+ * In follow mode there is a short period of time after the
+ * server has written the end of the previous file before the
+ * new file is available. So we loop for 5 seconds looking
+ * for the file to appear before giving up.
+ */
+ for (tries = 0; tries < 10; tries++)
+ {
+ sendFile = fuzzy_open_file(directory, fname);
+ if (sendFile >= 0)
+ break;
+ if (errno == ENOENT)
+ {
+ int save_errno = errno;
+
+ /* File not there yet, try again */
+ pg_usleep(500 * 1000);
+
+ errno = save_errno;
+ continue;
+ }
+ /* Any other error, fall through and fail */
+ break;
+ }
if (sendFile < 0)
fatal_error("could not find file \"%s\": %s",