mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-23 04:30:41 +02:00
In pgwin32_open, loop after ERROR_ACCESS_DENIED only if we can't stat.
This fixes a performance problem introduced by commit 6d7547c21
.
ERROR_ACCESS_DENIED is returned in some other cases besides the
delete-pending case considered by that commit; notably, if the
given path names a directory instead of a plain file. In that
case we'll uselessly loop for 1 second before returning the
failure condition. That slows down some usage scenarios enough
to cause test timeout failures on our Windows buildfarm critters.
To fix, try to stat() the file, and sleep/loop only if that fails.
It will fail in the delete-pending case, and also in the case where
the deletion completed before we could stat(), so we have the cases
where we want to loop covered. In the directory case, the stat()
should succeed, letting us exit without a wait.
One case where we'll still wait uselessly is if the access-denied
problem pertains to a directory in the given pathname. But we don't
expect that to happen in any performance-critical code path.
There might be room to refine this further, but I'll push it now
in hopes of making the buildfarm green again.
Back-patch, like the preceding commit.
Alexander Lakhin and Tom Lane
Discussion: https://postgr.es/m/23073.1576626626@sss.pgh.pa.us
This commit is contained in:
parent
7b94a0b389
commit
b3c4e24188
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -120,20 +121,35 @@ pgwin32_open(const char *fileName, int fileFlags,...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ERROR_ACCESS_DENIED can be returned if the file is deleted but not
|
* ERROR_ACCESS_DENIED is returned if the file is deleted but not yet
|
||||||
* yet gone (Windows NT status code is STATUS_DELETE_PENDING). Wait a
|
* gone (Windows NT status code is STATUS_DELETE_PENDING). In that
|
||||||
* bit and try again, giving up after 1 second (since this condition
|
* case we want to wait a bit and try again, giving up after 1 second
|
||||||
* should never persist very long).
|
* (since this condition should never persist very long). However,
|
||||||
|
* there are other commonly-hit cases that return ERROR_ACCESS_DENIED,
|
||||||
|
* so care is needed. In particular that happens if we try to open a
|
||||||
|
* directory, or of course if there's an actual file-permissions
|
||||||
|
* problem. To distinguish these cases, try a stat(). In the
|
||||||
|
* delete-pending case, it will either also get STATUS_DELETE_PENDING,
|
||||||
|
* or it will see the file as gone and fail with ENOENT. In other
|
||||||
|
* cases it will usually succeed. The only somewhat-likely case where
|
||||||
|
* this coding will uselessly wait is if there's a permissions problem
|
||||||
|
* with a containing directory, which we hope will never happen in any
|
||||||
|
* performance-critical code paths.
|
||||||
*/
|
*/
|
||||||
if (err == ERROR_ACCESS_DENIED)
|
if (err == ERROR_ACCESS_DENIED)
|
||||||
{
|
{
|
||||||
if (loops < 10)
|
if (loops < 10)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (stat(fileName, &st) != 0)
|
||||||
{
|
{
|
||||||
pg_usleep(100000);
|
pg_usleep(100000);
|
||||||
loops++;
|
loops++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_dosmaperr(err);
|
_dosmaperr(err);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user