Skip to content

Commit 80727ce

Browse files
committed
Use stat(2) to probe for existing xlog segments in InstallXLogFileSegment,
rather than actually opening the files. This eliminates some corner cases where the file indeed exists but open() fails for another reason, such as being out of file descriptors. The net reliability gain is probably tiny, since xlog.c is full of other file open calls that will elog(PANIC) if they fail for any reason; but this specific failure mode has been observed in the field, so we may as well fix it.
1 parent 7a196ba commit 80727ce

File tree

1 file changed

+3
-5
lines changed
  • src/backend/access/transam

1 file changed

+3
-5
lines changed

src/backend/access/transam/xlog.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.110 2002/11/08 20:23:56 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.111 2003/01/25 03:06:04 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1471,7 +1471,7 @@ InstallXLogFileSegment(uint32 log, uint32 seg, char *tmppath,
14711471
bool use_lock)
14721472
{
14731473
char path[MAXPGPATH];
1474-
int fd;
1474+
struct stat stat_buf;
14751475

14761476
XLogFileName(path, log, seg);
14771477

@@ -1489,10 +1489,8 @@ InstallXLogFileSegment(uint32 log, uint32 seg, char *tmppath,
14891489
else
14901490
{
14911491
/* Find a free slot to put it in */
1492-
while ((fd = BasicOpenFile(path, O_RDWR | PG_BINARY,
1493-
S_IRUSR | S_IWUSR)) >= 0)
1492+
while (stat(path, &stat_buf) == 0)
14941493
{
1495-
close(fd);
14961494
if (--max_advance < 0)
14971495
{
14981496
/* Failed to find a free slot within specified range */

0 commit comments

Comments
 (0)