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

Commitde3e018

Browse files
committed
Back-patch fix that allows AllocateFile() to return errno=ENFILE/EMFILE
after we are no longer able to close any more VFDs. This is needed toavoid postmaster crash under out-of-file-descriptors conditions.
1 parentc954088 commitde3e018

File tree

1 file changed

+37
-20
lines changed
  • src/backend/storage/file

1 file changed

+37
-20
lines changed

‎src/backend/storage/file/fd.c

Lines changed: 37 additions & 20 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.56 2000/04/12 17:15:35 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.56.2.1 2000/09/23 23:31:24 tgl Exp $
1111
*
1212
* NOTES:
1313
*
@@ -181,7 +181,7 @@ static void Delete(File file);
181181
staticvoidLruDelete(Filefile);
182182
staticvoidInsert(Filefile);
183183
staticintLruInsert(Filefile);
184-
staticvoidReleaseLruFile(void);
184+
staticboolReleaseLruFile(void);
185185
staticFileAllocateVfd(void);
186186
staticvoidFreeVfd(Filefile);
187187

@@ -347,7 +347,10 @@ LruInsert(File file)
347347
{
348348

349349
while (nfile+numAllocatedFiles >=pg_nofile())
350-
ReleaseLruFile();
350+
{
351+
if (!ReleaseLruFile())
352+
break;
353+
}
351354

352355
/*
353356
* The open could still fail for lack of file descriptors, eg due
@@ -358,9 +361,12 @@ LruInsert(File file)
358361
vfdP->fd=open(vfdP->fileName,vfdP->fileFlags,vfdP->fileMode);
359362
if (vfdP->fd<0&& (errno==EMFILE||errno==ENFILE))
360363
{
364+
intsave_errno=errno;
365+
361366
errno=0;
362-
ReleaseLruFile();
363-
gototryAgain;
367+
if (ReleaseLruFile())
368+
gototryAgain;
369+
errno=save_errno;
364370
}
365371

366372
if (vfdP->fd<0)
@@ -392,20 +398,22 @@ LruInsert(File file)
392398
return0;
393399
}
394400

395-
staticvoid
401+
staticbool
396402
ReleaseLruFile()
397403
{
398404
DO_DB(elog(DEBUG,"ReleaseLruFile. Opened %d",nfile));
399405

400-
if (nfile <=0)
401-
elog(ERROR,"ReleaseLruFile: No open files available to be closed");
402-
403-
/*
404-
* There are opened files and so there should be at least one used vfd
405-
* in the ring.
406-
*/
407-
Assert(VfdCache[0].lruMoreRecently!=0);
408-
LruDelete(VfdCache[0].lruMoreRecently);
406+
if (nfile>0)
407+
{
408+
/*
409+
* There are opened files and so there should be at least one used
410+
* vfd in the ring.
411+
*/
412+
Assert(VfdCache[0].lruMoreRecently!=0);
413+
LruDelete(VfdCache[0].lruMoreRecently);
414+
return true;/* freed a file */
415+
}
416+
return false;/* no files available to free */
409417
}
410418

411419
/*
@@ -612,17 +620,23 @@ fileNameOpenFile(FileName fileName,
612620
vfdP=&VfdCache[file];
613621

614622
while (nfile+numAllocatedFiles >=pg_nofile())
615-
ReleaseLruFile();
623+
{
624+
if (!ReleaseLruFile())
625+
break;
626+
}
616627

617628
tryAgain:
618629
vfdP->fd=open(fileName,fileFlags,fileMode);
619630
if (vfdP->fd<0&& (errno==EMFILE||errno==ENFILE))
620631
{
632+
intsave_errno=errno;
633+
621634
DO_DB(elog(DEBUG,"fileNameOpenFile: not enough descs, retry, er= %d",
622635
errno));
623636
errno=0;
624-
ReleaseLruFile();
625-
gototryAgain;
637+
if (ReleaseLruFile())
638+
gototryAgain;
639+
errno=save_errno;
626640
}
627641

628642
if (vfdP->fd<0)
@@ -1004,11 +1018,14 @@ AllocateFile(char *name, char *mode)
10041018
{
10051019
if (errno==EMFILE||errno==ENFILE)
10061020
{
1021+
intsave_errno=errno;
1022+
10071023
DO_DB(elog(DEBUG,"AllocateFile: not enough descs, retry, er= %d",
10081024
errno));
10091025
errno=0;
1010-
ReleaseLruFile();
1011-
gotoTryAgain;
1026+
if (ReleaseLruFile())
1027+
gotoTryAgain;
1028+
errno=save_errno;
10121029
}
10131030
}
10141031
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp