Skip to content

Commit d99fb0d

Browse files
committed
Don't Assert() that fsync() and close() never fail; I have seen this
crash on Solaris when over disk quota. Instead, report such failures via elog(DEBUG).
1 parent dbb76bf commit d99fb0d

File tree

1 file changed

+30
-23
lines changed
  • src/backend/storage/file

1 file changed

+30
-23
lines changed

src/backend/storage/file/fd.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.87 2001/11/05 17:46:27 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.88 2002/02/10 22:56:31 tgl Exp $
1111
*
1212
* NOTES:
1313
*
@@ -110,7 +110,7 @@ int max_files_per_process = 1000;
110110

111111
#define FileIsNotOpen(file) (VfdCache[file].fd == VFD_CLOSED)
112112

113-
#define FileUnknownPos (-1)
113+
#define FileUnknownPos (-1L)
114114

115115
typedef struct vfd
116116
{
@@ -380,7 +380,6 @@ static void
380380
LruDelete(File file)
381381
{
382382
Vfd *vfdP;
383-
int returnValue;
384383

385384
Assert(file != 0);
386385

@@ -394,19 +393,21 @@ LruDelete(File file)
394393

395394
/* save the seek position */
396395
vfdP->seekPos = (long) lseek(vfdP->fd, 0L, SEEK_CUR);
397-
Assert(vfdP->seekPos != -1);
396+
Assert(vfdP->seekPos != -1L);
398397

399398
/* if we have written to the file, sync it before closing */
400399
if (vfdP->fdstate & FD_DIRTY)
401400
{
402-
returnValue = pg_fsync(vfdP->fd);
403-
Assert(returnValue != -1);
401+
if (pg_fsync(vfdP->fd))
402+
elog(DEBUG, "LruDelete: failed to fsync %s: %m",
403+
vfdP->fileName);
404404
vfdP->fdstate &= ~FD_DIRTY;
405405
}
406406

407407
/* close the file */
408-
returnValue = close(vfdP->fd);
409-
Assert(returnValue != -1);
408+
if (close(vfdP->fd))
409+
elog(DEBUG, "LruDelete: failed to close %s: %m",
410+
vfdP->fileName);
410411

411412
--nfile;
412413
vfdP->fd = VFD_CLOSED;
@@ -437,7 +438,6 @@ static int
437438
LruInsert(File file)
438439
{
439440
Vfd *vfdP;
440-
int returnValue;
441441

442442
Assert(file != 0);
443443

@@ -475,8 +475,10 @@ LruInsert(File file)
475475
/* seek to the right position */
476476
if (vfdP->seekPos != 0L)
477477
{
478-
returnValue = lseek(vfdP->fd, vfdP->seekPos, SEEK_SET);
479-
Assert(returnValue != -1);
478+
long returnValue;
479+
480+
returnValue = (long) lseek(vfdP->fd, vfdP->seekPos, SEEK_SET);
481+
Assert(returnValue != -1L);
480482
}
481483
}
482484

@@ -824,43 +826,48 @@ OpenTemporaryFile(void)
824826
void
825827
FileClose(File file)
826828
{
827-
int returnValue;
829+
Vfd *vfdP;
828830

829831
Assert(FileIsValid(file));
830832

831833
DO_DB(elog(DEBUG, "FileClose: %d (%s)",
832834
file, VfdCache[file].fileName));
833835

836+
vfdP = &VfdCache[file];
837+
834838
if (!FileIsNotOpen(file))
835839
{
836-
837840
/* remove the file from the lru ring */
838841
Delete(file);
839842

840843
/* if we did any writes, sync the file before closing */
841-
if (VfdCache[file].fdstate & FD_DIRTY)
844+
if (vfdP->fdstate & FD_DIRTY)
842845
{
843-
returnValue = pg_fsync(VfdCache[file].fd);
844-
Assert(returnValue != -1);
845-
VfdCache[file].fdstate &= ~FD_DIRTY;
846+
if (pg_fsync(vfdP->fd))
847+
elog(DEBUG, "FileClose: failed to fsync %s: %m",
848+
vfdP->fileName);
849+
vfdP->fdstate &= ~FD_DIRTY;
846850
}
847851

848852
/* close the file */
849-
returnValue = close(VfdCache[file].fd);
850-
Assert(returnValue != -1);
853+
if (close(vfdP->fd))
854+
elog(DEBUG, "FileClose: failed to close %s: %m",
855+
vfdP->fileName);
851856

852857
--nfile;
853-
VfdCache[file].fd = VFD_CLOSED;
858+
vfdP->fd = VFD_CLOSED;
854859
}
855860

856861
/*
857862
* Delete the file if it was temporary
858863
*/
859-
if (VfdCache[file].fdstate & FD_TEMPORARY)
864+
if (vfdP->fdstate & FD_TEMPORARY)
860865
{
861866
/* reset flag so that die() interrupt won't cause problems */
862-
VfdCache[file].fdstate &= ~FD_TEMPORARY;
863-
unlink(VfdCache[file].fileName);
867+
vfdP->fdstate &= ~FD_TEMPORARY;
868+
if (unlink(vfdP->fileName))
869+
elog(DEBUG, "FileClose: failed to unlink %s: %m",
870+
vfdP->fileName);
864871
}
865872

866873
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy