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

Commitdcbdf9b

Browse files
committed
Change Windows rename and unlink substitutes so that they time out after
30 seconds instead of retrying forever. Also modify xlog.c so that ifit fails to rename an old xlog segment up to a future slot, it willunlink the segment instead. Per discussion of bug #2712, in which itbecame apparent that Windows can handle unlinking a file that's beingheld open, but not renaming it.
1 parent808b319 commitdcbdf9b

File tree

2 files changed

+39
-50
lines changed

2 files changed

+39
-50
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.253 2006/11/05 22:42:08 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.254 2006/11/08 20:12:04 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2140,7 +2140,9 @@ XLogFileCopy(uint32 log, uint32 seg,
21402140
* caller must *not* hold the lock at call.
21412141
*
21422142
* Returns TRUE if file installed, FALSE if not installed because of
2143-
* exceeding max_advance limit. (Any other kind of failure causes ereport().)
2143+
* exceeding max_advance limit. On Windows, we also return FALSE if we
2144+
* can't rename the file into place because someone's got it open.
2145+
* (Any other kind of failure causes ereport().)
21442146
*/
21452147
staticbool
21462148
InstallXLogFileSegment(uint32*log,uint32*seg,char*tmppath,
@@ -2195,10 +2197,25 @@ InstallXLogFileSegment(uint32 *log, uint32 *seg, char *tmppath,
21952197
unlink(tmppath);
21962198
#else
21972199
if (rename(tmppath,path)<0)
2200+
{
2201+
#ifdefWIN32
2202+
#if !defined(__CYGWIN__)
2203+
if (GetLastError()==ERROR_ACCESS_DENIED)
2204+
#else
2205+
if (errno==EACCES)
2206+
#endif
2207+
{
2208+
if (use_lock)
2209+
LWLockRelease(ControlFileLock);
2210+
return false;
2211+
}
2212+
#endif/* WIN32 */
2213+
21982214
ereport(ERROR,
21992215
(errcode_for_file_access(),
22002216
errmsg("could not rename file \"%s\" to \"%s\" (initialization of log file %u, segment %u): %m",
22012217
tmppath,path,*log,*seg)));
2218+
}
22022219
#endif
22032220

22042221
if (use_lock)

‎src/port/dirmod.c

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*Win32 (NT, Win2k, XP).replace() doesn't work on Win95/98/Me.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.43 2006/07/18 22:36:46 tgl Exp $
13+
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.44 2006/11/08 20:12:05 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -117,43 +117,28 @@ pgrename(const char *from, const char *to)
117117
intloops=0;
118118

119119
/*
120-
* We needthese loops because even though PostgreSQL uses flags that
120+
* We needto loop because even though PostgreSQL uses flags that
121121
* allow rename while the file is open, other applications might have
122-
* these files open without those flags.
122+
* the file open without those flags. However, we won't wait
123+
* indefinitely for someone else to close the file.
123124
*/
124125
#if defined(WIN32)&& !defined(__CYGWIN__)
125126
while (!MoveFileEx(from,to,MOVEFILE_REPLACE_EXISTING))
126-
#endif
127-
#ifdef__CYGWIN__
128-
while (rename(from,to)<0)
129-
#endif
130-
{
131-
#if defined(WIN32)&& !defined(__CYGWIN__)
132-
if (GetLastError()!=ERROR_ACCESS_DENIED)
133-
#endif
134-
#ifdef__CYGWIN__
135-
if (errno!=EACCES)
136-
#endif
137-
/* set errno? */
138-
return-1;
139-
pg_usleep(100000);/* us */
140-
if (loops==30)
141-
#ifndefFRONTEND
142-
elog(LOG,"could not rename file \"%s\" to \"%s\", continuing to try",
143-
from,to);
144127
#else
145-
fprintf(stderr,_("could not rename file \"%s\" to \"%s\", continuing to try\n"),
146-
from,to);
128+
while (rename(from,to)<0)
147129
#endif
148-
loops++;
149-
}
150-
151-
if (loops>30)
152-
#ifndefFRONTEND
153-
elog(LOG,"completed rename of file \"%s\" to \"%s\"",from,to);
130+
{
131+
#if defined(WIN32)&& !defined(__CYGWIN__)
132+
if (GetLastError()!=ERROR_ACCESS_DENIED)
154133
#else
155-
fprintf(stderr,_("completed rename of file \"%s\" to \"%s\"\n"),from,to);
134+
if (errno!=EACCES)
156135
#endif
136+
/* set errno? */
137+
return-1;
138+
if (++loops>300)/* time out after 30 sec */
139+
return-1;
140+
pg_usleep(100000);/* us */
141+
}
157142
return0;
158143
}
159144

@@ -167,33 +152,20 @@ pgunlink(const char *path)
167152
intloops=0;
168153

169154
/*
170-
* We needthese loops because even though PostgreSQL uses flags that
155+
* We needto loop because even though PostgreSQL uses flags that
171156
* allow unlink while the file is open, other applications might have
172-
* these files open without those flags.
157+
* the file open without those flags. However, we won't wait
158+
* indefinitely for someone else to close the file.
173159
*/
174160
while (unlink(path))
175161
{
176162
if (errno!=EACCES)
177163
/* set errno? */
178164
return-1;
165+
if (++loops>300)/* time out after 30 sec */
166+
return-1;
179167
pg_usleep(100000);/* us */
180-
if (loops==30)
181-
#ifndefFRONTEND
182-
elog(LOG,"could not remove file \"%s\", continuing to try",
183-
path);
184-
#else
185-
fprintf(stderr,_("could not remove file \"%s\", continuing to try\n"),
186-
path);
187-
#endif
188-
loops++;
189168
}
190-
191-
if (loops>30)
192-
#ifndefFRONTEND
193-
elog(LOG,"completed removal of file \"%s\"",path);
194-
#else
195-
fprintf(stderr,_("completed removal of file \"%s\"\n"),path);
196-
#endif
197169
return0;
198170
}
199171

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp