Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit120d7e1

Browse files
committed
On win32, loop when opening files if sharing- och lock-violation errors
occur. Hopefully, this will make it possible to recover from brokenantivirus and/or backup software that locks our files.
1 parentef6bac3 commit120d7e1

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

‎src/port/open.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
*
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
*
9-
* $PostgreSQL: pgsql/src/port/open.c,v 1.22 2007/11/30 11:16:43 mha Exp $
9+
* $PostgreSQL: pgsql/src/port/open.c,v 1.23 2007/12/20 20:27:53 mha Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
1313

1414
#ifdefWIN32
1515

16-
#include"c.h"
16+
#ifndefFRONTEND
17+
#include"postgres.h"
18+
#else
19+
#include"postgres_fe.h"
20+
#endif
1721

1822
#include<windows.h>
1923
#include<fcntl.h>
@@ -58,8 +62,9 @@ int
5862
pgwin32_open(constchar*fileName,intfileFlags,...)
5963
{
6064
intfd;
61-
HANDLEh;
65+
HANDLEh=INVALID_HANDLE_VALUE;
6266
SECURITY_ATTRIBUTESsa;
67+
intloops=0;
6368

6469
/* Check that we can handle the request */
6570
assert((fileFlags& ((O_RDONLY |O_WRONLY |O_RDWR) |O_APPEND |
@@ -71,7 +76,7 @@ pgwin32_open(const char *fileName, int fileFlags,...)
7176
sa.bInheritHandle= TRUE;
7277
sa.lpSecurityDescriptor=NULL;
7378

74-
if ((h=CreateFile(fileName,
79+
while ((h=CreateFile(fileName,
7580
/* cannot use O_RDONLY, as it == 0 */
7681
(fileFlags&O_RDWR) ? (GENERIC_WRITE |GENERIC_READ) :
7782
((fileFlags&O_WRONLY) ?GENERIC_WRITE :GENERIC_READ),
@@ -88,7 +93,32 @@ pgwin32_open(const char *fileName, int fileFlags,...)
8893
((fileFlags&O_DSYNC) ?FILE_FLAG_WRITE_THROUGH :0),
8994
NULL))==INVALID_HANDLE_VALUE)
9095
{
91-
_dosmaperr(GetLastError());
96+
/*
97+
* Sharing violation or locking error can indicate antivirus, backup
98+
* or similar software that's locking the file. Try again for 30 seconds
99+
* before giving up.
100+
*/
101+
DWORDerr=GetLastError();
102+
if (err==ERROR_SHARING_VIOLATION||
103+
err==ERROR_LOCK_VIOLATION)
104+
{
105+
pg_usleep(100000);
106+
loops++;
107+
108+
#ifndefFRONTEND
109+
if (loops==50)
110+
ereport(LOG,
111+
(errmsg("could not open file \"%s\": %s",fileName,
112+
(err==ERROR_SHARING_VIOLATION)?_("sharing violation"):_("lock violation")),
113+
errdetail("Continuing to retry for 30 seconds."),
114+
errhint("You may have antivirus, backup or similar software interfering with the database.")));
115+
#endif
116+
117+
if (loops<300)
118+
continue;
119+
}
120+
121+
_dosmaperr(err);
92122
return-1;
93123
}
94124

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp