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).
This commit is contained in:
parent
dbb76bf2e0
commit
d99fb0d909
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.87 2001/11/05 17:46:27 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.88 2002/02/10 22:56:31 tgl Exp $
|
||||||
*
|
*
|
||||||
* NOTES:
|
* NOTES:
|
||||||
*
|
*
|
||||||
@ -110,7 +110,7 @@ int max_files_per_process = 1000;
|
|||||||
|
|
||||||
#define FileIsNotOpen(file) (VfdCache[file].fd == VFD_CLOSED)
|
#define FileIsNotOpen(file) (VfdCache[file].fd == VFD_CLOSED)
|
||||||
|
|
||||||
#define FileUnknownPos (-1)
|
#define FileUnknownPos (-1L)
|
||||||
|
|
||||||
typedef struct vfd
|
typedef struct vfd
|
||||||
{
|
{
|
||||||
@ -380,7 +380,6 @@ static void
|
|||||||
LruDelete(File file)
|
LruDelete(File file)
|
||||||
{
|
{
|
||||||
Vfd *vfdP;
|
Vfd *vfdP;
|
||||||
int returnValue;
|
|
||||||
|
|
||||||
Assert(file != 0);
|
Assert(file != 0);
|
||||||
|
|
||||||
@ -394,19 +393,21 @@ LruDelete(File file)
|
|||||||
|
|
||||||
/* save the seek position */
|
/* save the seek position */
|
||||||
vfdP->seekPos = (long) lseek(vfdP->fd, 0L, SEEK_CUR);
|
vfdP->seekPos = (long) lseek(vfdP->fd, 0L, SEEK_CUR);
|
||||||
Assert(vfdP->seekPos != -1);
|
Assert(vfdP->seekPos != -1L);
|
||||||
|
|
||||||
/* if we have written to the file, sync it before closing */
|
/* if we have written to the file, sync it before closing */
|
||||||
if (vfdP->fdstate & FD_DIRTY)
|
if (vfdP->fdstate & FD_DIRTY)
|
||||||
{
|
{
|
||||||
returnValue = pg_fsync(vfdP->fd);
|
if (pg_fsync(vfdP->fd))
|
||||||
Assert(returnValue != -1);
|
elog(DEBUG, "LruDelete: failed to fsync %s: %m",
|
||||||
|
vfdP->fileName);
|
||||||
vfdP->fdstate &= ~FD_DIRTY;
|
vfdP->fdstate &= ~FD_DIRTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close the file */
|
/* close the file */
|
||||||
returnValue = close(vfdP->fd);
|
if (close(vfdP->fd))
|
||||||
Assert(returnValue != -1);
|
elog(DEBUG, "LruDelete: failed to close %s: %m",
|
||||||
|
vfdP->fileName);
|
||||||
|
|
||||||
--nfile;
|
--nfile;
|
||||||
vfdP->fd = VFD_CLOSED;
|
vfdP->fd = VFD_CLOSED;
|
||||||
@ -437,7 +438,6 @@ static int
|
|||||||
LruInsert(File file)
|
LruInsert(File file)
|
||||||
{
|
{
|
||||||
Vfd *vfdP;
|
Vfd *vfdP;
|
||||||
int returnValue;
|
|
||||||
|
|
||||||
Assert(file != 0);
|
Assert(file != 0);
|
||||||
|
|
||||||
@ -475,8 +475,10 @@ LruInsert(File file)
|
|||||||
/* seek to the right position */
|
/* seek to the right position */
|
||||||
if (vfdP->seekPos != 0L)
|
if (vfdP->seekPos != 0L)
|
||||||
{
|
{
|
||||||
returnValue = lseek(vfdP->fd, vfdP->seekPos, SEEK_SET);
|
long returnValue;
|
||||||
Assert(returnValue != -1);
|
|
||||||
|
returnValue = (long) lseek(vfdP->fd, vfdP->seekPos, SEEK_SET);
|
||||||
|
Assert(returnValue != -1L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -824,43 +826,48 @@ OpenTemporaryFile(void)
|
|||||||
void
|
void
|
||||||
FileClose(File file)
|
FileClose(File file)
|
||||||
{
|
{
|
||||||
int returnValue;
|
Vfd *vfdP;
|
||||||
|
|
||||||
Assert(FileIsValid(file));
|
Assert(FileIsValid(file));
|
||||||
|
|
||||||
DO_DB(elog(DEBUG, "FileClose: %d (%s)",
|
DO_DB(elog(DEBUG, "FileClose: %d (%s)",
|
||||||
file, VfdCache[file].fileName));
|
file, VfdCache[file].fileName));
|
||||||
|
|
||||||
|
vfdP = &VfdCache[file];
|
||||||
|
|
||||||
if (!FileIsNotOpen(file))
|
if (!FileIsNotOpen(file))
|
||||||
{
|
{
|
||||||
|
|
||||||
/* remove the file from the lru ring */
|
/* remove the file from the lru ring */
|
||||||
Delete(file);
|
Delete(file);
|
||||||
|
|
||||||
/* if we did any writes, sync the file before closing */
|
/* if we did any writes, sync the file before closing */
|
||||||
if (VfdCache[file].fdstate & FD_DIRTY)
|
if (vfdP->fdstate & FD_DIRTY)
|
||||||
{
|
{
|
||||||
returnValue = pg_fsync(VfdCache[file].fd);
|
if (pg_fsync(vfdP->fd))
|
||||||
Assert(returnValue != -1);
|
elog(DEBUG, "FileClose: failed to fsync %s: %m",
|
||||||
VfdCache[file].fdstate &= ~FD_DIRTY;
|
vfdP->fileName);
|
||||||
|
vfdP->fdstate &= ~FD_DIRTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close the file */
|
/* close the file */
|
||||||
returnValue = close(VfdCache[file].fd);
|
if (close(vfdP->fd))
|
||||||
Assert(returnValue != -1);
|
elog(DEBUG, "FileClose: failed to close %s: %m",
|
||||||
|
vfdP->fileName);
|
||||||
|
|
||||||
--nfile;
|
--nfile;
|
||||||
VfdCache[file].fd = VFD_CLOSED;
|
vfdP->fd = VFD_CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete the file if it was temporary
|
* Delete the file if it was temporary
|
||||||
*/
|
*/
|
||||||
if (VfdCache[file].fdstate & FD_TEMPORARY)
|
if (vfdP->fdstate & FD_TEMPORARY)
|
||||||
{
|
{
|
||||||
/* reset flag so that die() interrupt won't cause problems */
|
/* reset flag so that die() interrupt won't cause problems */
|
||||||
VfdCache[file].fdstate &= ~FD_TEMPORARY;
|
vfdP->fdstate &= ~FD_TEMPORARY;
|
||||||
unlink(VfdCache[file].fileName);
|
if (unlink(vfdP->fileName))
|
||||||
|
elog(DEBUG, "FileClose: failed to unlink %s: %m",
|
||||||
|
vfdP->fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user