Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 41d58e9

Browse files
committed
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.
1 parent 7341c28 commit 41d58e9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/bin/pg_xlogdump/pg_xlogdump.c

+25-1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
249249
if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo))
250250
{
251251
char fname[MAXFNAMELEN];
252+
int tries;
252253

253254
/* Switch to another logfile segment */
254255
if (sendFile >= 0)
@@ -258,7 +259,30 @@ XLogDumpXLogRead(const char *directory, TimeLineID timeline_id,
258259

259260
XLogFileName(fname, timeline_id, sendSegNo);
260261

261-
sendFile = fuzzy_open_file(directory, fname);
262+
/*
263+
* In follow mode there is a short period of time after the
264+
* server has written the end of the previous file before the
265+
* new file is available. So we loop for 5 seconds looking
266+
* for the file to appear before giving up.
267+
*/
268+
for (tries = 0; tries < 10; tries++)
269+
{
270+
sendFile = fuzzy_open_file(directory, fname);
271+
if (sendFile >= 0)
272+
break;
273+
if (errno == ENOENT)
274+
{
275+
int save_errno = errno;
276+
277+
/* File not there yet, try again */
278+
pg_usleep(500 * 1000);
279+
280+
errno = save_errno;
281+
continue;
282+
}
283+
/* Any other error, fall through and fail */
284+
break;
285+
}
262286

263287
if (sendFile < 0)
264288
fatal_error("could not find file \"%s\": %s",

0 commit comments

Comments
 (0)