Skip to content

Commit 3d39244

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 fd321a1 commit 3d39244

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/bin/pg_xlogdump/pg_xlogdump.c

Lines changed: 25 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy