Fix issues with Windows' stat() for files pending on deletion
authorMichael Paquier <[email protected]>
Mon, 12 Jul 2021 04:02:31 +0000 (13:02 +0900)
committerMichael Paquier <[email protected]>
Mon, 12 Jul 2021 04:02:31 +0000 (13:02 +0900)
commit54fb8c7ddf152629021cab3ac3596354217b7d81
tree3de2fa3ee50ce42e3da439e0cd78ac5e5d1c9821
parent127404fbe28455d6e8183fa58f3b7aefeba8f909
Fix issues with Windows' stat() for files pending on deletion

The code introduced by bed9075 to enhance the stat() implementation on
Windows for file sizes larger than 4GB fails to properly detect files
pending for deletion with its method based on NtQueryInformationFile()
or GetFileInformationByHandleEx(), as proved by Alexander Lakhin in a
custom TAP test of his own.

The method used in the implementation of open() to sleep and loop when
when failing on ERROR_ACCESS_DENIED (EACCES) is showing much more
stability, so switch to this method.  This could still lead to issues if
the permission problem stays around for much longer than the timeout of
1 second used, but that should (hopefully) never happen in
performance-critical paths.  Still, there could be a point in increasing
the timeouts for the sake of machines that handle heavy loads.

Note that WIN32's open() now uses microsoft_native_stat() as it should
be similar to stat() when working around issues with concurrent file
deletions.

I have spent some time testing this  with pgbench in combination
of the SQL functions from genfile.c, as well as running the TAP test
provided on the thread with MSVC builds, and this looks much more
stable than the previous method.

Author: Alexander Lakhin
Reviewed-by: Tom Lane, Michael Paquier, Justin Pryzby
Discussion: https://postgr.es/m/c3427edf-d7c0-ff57-90f6-b5de3bb62709@gmail.com
Back-through: 14
src/port/open.c
src/port/win32stat.c