mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-30 19:00:29 +08:00
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.
This commit is contained in:
parent
3c97a7ca46
commit
4bff35cca5
@ -231,6 +231,7 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
|
|||||||
if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo))
|
if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo))
|
||||||
{
|
{
|
||||||
char fname[MAXFNAMELEN];
|
char fname[MAXFNAMELEN];
|
||||||
|
int tries;
|
||||||
|
|
||||||
/* Switch to another logfile segment */
|
/* Switch to another logfile segment */
|
||||||
if (sendFile >= 0)
|
if (sendFile >= 0)
|
||||||
@ -240,7 +241,30 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
|
|||||||
|
|
||||||
XLogFileName(fname, timeline_id, sendSegNo);
|
XLogFileName(fname, timeline_id, sendSegNo);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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);
|
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)
|
if (sendFile < 0)
|
||||||
fatal_error("could not find file \"%s\": %s",
|
fatal_error("could not find file \"%s\": %s",
|
||||||
|
Loading…
Reference in New Issue
Block a user