提交 5b571bb8 编写于 作者: J Jeff Davis

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.
上级 43c3aab1
...@@ -2259,6 +2259,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock) ...@@ -2259,6 +2259,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
XLogSegNo installed_segno; XLogSegNo installed_segno;
int max_advance; int max_advance;
int fd; int fd;
bool zero_fill = true;
XLogFilePath(path, ThisTimeLineID, logsegno); XLogFilePath(path, ThisTimeLineID, logsegno);
...@@ -2301,24 +2302,18 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock) ...@@ -2301,24 +2302,18 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
errmsg("could not create file \"%s\": %m", tmppath))); errmsg("could not create file \"%s\": %m", tmppath)));
#ifdef HAVE_POSIX_FALLOCATE #ifdef HAVE_POSIX_FALLOCATE
{ /*
errno = posix_fallocate(fd, 0, XLogSegSize); * If posix_fallocate() is available and succeeds, then the file is
* properly allocated and we don't need to zero-fill it (which is less
if (errno) * efficient). In case of an error, fall back to writing zeros, because on
{ * some platforms posix_fallocate() is available but will not always
int errno_saved = errno; * succeed in cases where zero-filling will.
*/
close(fd); if (posix_fallocate(fd, 0, XLogSegSize) == 0)
unlink(tmppath); zero_fill = false;
errno = errno_saved; #endif /* HAVE_POSIX_FALLOCATE */
ereport(ERROR, if (zero_fill)
(errcode_for_file_access(),
errmsg("could not allocate space for file \"%s\" using posix_fallocate: %m",
tmppath)));
}
}
#else /* !HAVE_POSIX_FALLOCATE */
{ {
/* /*
* Allocate a buffer full of zeros. This is done before opening the * 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) ...@@ -2366,7 +2361,6 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
} }
pfree(zbuffer); pfree(zbuffer);
} }
#endif /* HAVE_POSIX_FALLOCATE */
if (pg_fsync(fd) != 0) if (pg_fsync(fd) != 0)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册