diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-11-08 20:12:05 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-11-08 20:12:05 +0000 |
commit | dcbdf9b1d46dc9f95c55f78da4754ded4f0cd17d (patch) | |
tree | 1491476e2bd79f27b13abb429512793cabb526b4 /src/port/dirmod.c | |
parent | 808b3190d143f3df7217f94aff9e97fdf19c790a (diff) | |
download | postgresql-dcbdf9b1d46dc9f95c55f78da4754ded4f0cd17d.tar.gz postgresql-dcbdf9b1d46dc9f95c55f78da4754ded4f0cd17d.zip |
Change Windows rename and unlink substitutes so that they time out after
30 seconds instead of retrying forever. Also modify xlog.c so that if
it fails to rename an old xlog segment up to a future slot, it will
unlink the segment instead. Per discussion of bug #2712, in which it
became apparent that Windows can handle unlinking a file that's being
held open, but not renaming it.
Diffstat (limited to 'src/port/dirmod.c')
-rw-r--r-- | src/port/dirmod.c | 68 |
1 files changed, 20 insertions, 48 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c index e58384a749c..3934b5cf7dd 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -10,7 +10,7 @@ * Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.43 2006/07/18 22:36:46 tgl Exp $ + * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.44 2006/11/08 20:12:05 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -117,43 +117,28 @@ pgrename(const char *from, const char *to) int loops = 0; /* - * We need these loops because even though PostgreSQL uses flags that + * We need to loop because even though PostgreSQL uses flags that * allow rename while the file is open, other applications might have - * these files open without those flags. + * the file open without those flags. However, we won't wait + * indefinitely for someone else to close the file. */ #if defined(WIN32) && !defined(__CYGWIN__) while (!MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)) -#endif -#ifdef __CYGWIN__ - while (rename(from, to) < 0) -#endif - { -#if defined(WIN32) && !defined(__CYGWIN__) - if (GetLastError() != ERROR_ACCESS_DENIED) -#endif -#ifdef __CYGWIN__ - if (errno != EACCES) -#endif - /* set errno? */ - return -1; - pg_usleep(100000); /* us */ - if (loops == 30) -#ifndef FRONTEND - elog(LOG, "could not rename file \"%s\" to \"%s\", continuing to try", - from, to); #else - fprintf(stderr, _("could not rename file \"%s\" to \"%s\", continuing to try\n"), - from, to); + while (rename(from, to) < 0) #endif - loops++; - } - - if (loops > 30) -#ifndef FRONTEND - elog(LOG, "completed rename of file \"%s\" to \"%s\"", from, to); + { +#if defined(WIN32) && !defined(__CYGWIN__) + if (GetLastError() != ERROR_ACCESS_DENIED) #else - fprintf(stderr, _("completed rename of file \"%s\" to \"%s\"\n"), from, to); + if (errno != EACCES) #endif + /* set errno? */ + return -1; + if (++loops > 300) /* time out after 30 sec */ + return -1; + pg_usleep(100000); /* us */ + } return 0; } @@ -167,33 +152,20 @@ pgunlink(const char *path) int loops = 0; /* - * We need these loops because even though PostgreSQL uses flags that + * We need to loop because even though PostgreSQL uses flags that * allow unlink while the file is open, other applications might have - * these files open without those flags. + * the file open without those flags. However, we won't wait + * indefinitely for someone else to close the file. */ while (unlink(path)) { if (errno != EACCES) /* set errno? */ return -1; + if (++loops > 300) /* time out after 30 sec */ + return -1; pg_usleep(100000); /* us */ - if (loops == 30) -#ifndef FRONTEND - elog(LOG, "could not remove file \"%s\", continuing to try", - path); -#else - fprintf(stderr, _("could not remove file \"%s\", continuing to try\n"), - path); -#endif - loops++; } - - if (loops > 30) -#ifndef FRONTEND - elog(LOG, "completed removal of file \"%s\"", path); -#else - fprintf(stderr, _("completed removal of file \"%s\"\n"), path); -#endif return 0; } |