diff options
author | Magnus Hagander <magnus@hagander.net> | 2016-09-30 11:19:30 +0200 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2016-09-30 11:22:49 +0200 |
commit | da3f71a080fb7a615f5074eee44e524b045740f3 (patch) | |
tree | a2c9bb1ac2a842d50d10537d7179ed3af1d99594 | |
parent | a4daf8319923505b60c02b23bf3cfd1bd0b89d40 (diff) |
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.
-rw-r--r-- | contrib/pg_xlogdump/pg_xlogdump.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/contrib/pg_xlogdump/pg_xlogdump.c b/contrib/pg_xlogdump/pg_xlogdump.c index 30a8634da8a..499c855785b 100644 --- a/contrib/pg_xlogdump/pg_xlogdump.c +++ b/contrib/pg_xlogdump/pg_xlogdump.c @@ -232,6 +232,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) @@ -241,7 +242,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", |