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

Commit 5b571bb

Browse files
committed
Handle posix_fallocate() errors.
On some platforms, posix_fallocate() is available but may still return EINVAL if the underlying filesystem does not support it. So, in case of an error, fall through to the alternate implementation that just writes zeros. Per buildfarm failure and analysis by Tom Lane.
1 parent 43c3aab commit 5b571bb

File tree

1 file changed

+12
-18
lines changed
  • src/backend/access/transam

1 file changed

+12
-18
lines changed

src/backend/access/transam/xlog.c

+12-18
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
22592259
XLogSegNo installed_segno;
22602260
int max_advance;
22612261
int fd;
2262+
bool zero_fill = true;
22622263

22632264
XLogFilePath(path, ThisTimeLineID, logsegno);
22642265

@@ -2301,24 +2302,18 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
23012302
errmsg("could not create file \"%s\": %m", tmppath)));
23022303

23032304
#ifdef HAVE_POSIX_FALLOCATE
2304-
{
2305-
errno = posix_fallocate(fd, 0, XLogSegSize);
2306-
2307-
if (errno)
2308-
{
2309-
int errno_saved = errno;
2310-
2311-
close(fd);
2312-
unlink(tmppath);
2313-
errno = errno_saved;
2305+
/*
2306+
* If posix_fallocate() is available and succeeds, then the file is
2307+
* properly allocated and we don't need to zero-fill it (which is less
2308+
* efficient). In case of an error, fall back to writing zeros, because on
2309+
* some platforms posix_fallocate() is available but will not always
2310+
* succeed in cases where zero-filling will.
2311+
*/
2312+
if (posix_fallocate(fd, 0, XLogSegSize) == 0)
2313+
zero_fill = false;
2314+
#endif /* HAVE_POSIX_FALLOCATE */
23142315

2315-
ereport(ERROR,
2316-
(errcode_for_file_access(),
2317-
errmsg("could not allocate space for file \"%s\" using posix_fallocate: %m",
2318-
tmppath)));
2319-
}
2320-
}
2321-
#else /* !HAVE_POSIX_FALLOCATE */
2316+
if (zero_fill)
23222317
{
23232318
/*
23242319
* Allocate a buffer full of zeros. This is done before opening the
@@ -2366,7 +2361,6 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
23662361
}
23672362
pfree(zbuffer);
23682363
}
2369-
#endif /* HAVE_POSIX_FALLOCATE */
23702364

23712365
if (pg_fsync(fd) != 0)
23722366
{

0 commit comments

Comments
 (0)