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

Commit 30dcb62

Browse files
committed
Tolerate ENOSYS failure from sync_file_range().
One unintended consequence of commit 9ccdd7f was that Windows WSL users started getting a panic whenever we tried to initiate data flushing with sync_file_range(), because WSL does not implement that system call. Previously, they got a stream of periodic warnings, which was also undesirable but at least ignorable. Prevent the panic by handling ENOSYS specially and skipping the panic promotion with data_sync_elevel(). Also suppress future attempts after the first such failure so that the pre-existing problem of noisy warnings is improved. Back-patch to 9.6 (older branches were not affected in this way by 9ccdd7f). Author: Thomas Munro and James Sewell Tested-by: James Sewell Reported-by: Bruce Klein Discussion: https://postgr.es/m/CA+mCpegfOUph2U4ZADtQT16dfbkjjYNJL1bSTWErsazaFjQW9A@mail.gmail.com
1 parent 07fba9a commit 30dcb62

File tree

1 file changed

+20
-1
lines changed
  • src/backend/storage/file

1 file changed

+20
-1
lines changed

src/backend/storage/file/fd.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
432432
#if defined(HAVE_SYNC_FILE_RANGE)
433433
{
434434
int rc;
435+
static bool not_implemented_by_kernel = false;
436+
437+
if (not_implemented_by_kernel)
438+
return;
435439

436440
/*
437441
* sync_file_range(SYNC_FILE_RANGE_WRITE), currently linux specific,
@@ -446,7 +450,22 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
446450
SYNC_FILE_RANGE_WRITE);
447451
if (rc != 0)
448452
{
449-
ereport(data_sync_elevel(WARNING),
453+
int elevel;
454+
455+
/*
456+
* For systems that don't have an implementation of
457+
* sync_file_range() such as Windows WSL, generate only one
458+
* warning and then suppress all further attempts by this process.
459+
*/
460+
if (errno == ENOSYS)
461+
{
462+
elevel = WARNING;
463+
not_implemented_by_kernel = true;
464+
}
465+
else
466+
elevel = data_sync_elevel(WARNING);
467+
468+
ereport(elevel,
450469
(errcode_for_file_access(),
451470
errmsg("could not flush dirty data: %m")));
452471
}

0 commit comments

Comments
 (0)