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

Commit0f2d949

Browse files
committed
Fix init_irels to close the pg_internal.init file before returning.
This saves one open file descriptor per backend, and avoids anannoying NOTICE on Cygwin (which has trouble deleting open files).Bug appears to date back to original coding of init_irels, circa 1992.
1 parentd66b108 commit0f2d949

File tree

1 file changed

+28
-56
lines changed

1 file changed

+28
-56
lines changed

‎src/backend/utils/cache/relcache.c

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.150 2002/01/15 22:33:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.151 2002/01/16 17:34:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2659,33 +2659,22 @@ init_irels(void)
26592659
return;
26602660
}
26612661

2662-
FileSeek(fd,0L,SEEK_SET);
2663-
26642662
for (relno=0;relno<Num_indices_bootstrap;relno++)
26652663
{
26662664
/* first read the relation descriptor length */
26672665
if ((nread=FileRead(fd, (char*)&len,sizeof(len)))!=sizeof(len))
2668-
{
2669-
write_irels();
2670-
return;
2671-
}
2666+
gotoread_failed;
26722667

26732668
/* safety check for incompatible relcache layout */
26742669
if (len!=sizeof(RelationData))
2675-
{
2676-
write_irels();
2677-
return;
2678-
}
2670+
gotoread_failed;
26792671

26802672
ird=irel[relno]= (Relation)palloc(len);
26812673
MemSet(ird,0,len);
26822674

26832675
/* then, read the Relation structure */
26842676
if ((nread=FileRead(fd, (char*)ird,len))!=len)
2685-
{
2686-
write_irels();
2687-
return;
2688-
}
2677+
gotoread_failed;
26892678

26902679
/* reset transient fields */
26912680
ird->rd_targblock=InvalidBlockNumber;
@@ -2696,33 +2685,21 @@ init_irels(void)
26962685

26972686
/* next, read the access method tuple form */
26982687
if ((nread=FileRead(fd, (char*)&len,sizeof(len)))!=sizeof(len))
2699-
{
2700-
write_irels();
2701-
return;
2702-
}
2688+
gotoread_failed;
27032689

27042690
am= (Form_pg_am)palloc(len);
27052691
if ((nread=FileRead(fd, (char*)am,len))!=len)
2706-
{
2707-
write_irels();
2708-
return;
2709-
}
2692+
gotoread_failed;
27102693

27112694
ird->rd_am=am;
27122695

27132696
/* next read the relation tuple form */
27142697
if ((nread=FileRead(fd, (char*)&len,sizeof(len)))!=sizeof(len))
2715-
{
2716-
write_irels();
2717-
return;
2718-
}
2698+
gotoread_failed;
27192699

27202700
relform= (Form_pg_class)palloc(len);
27212701
if ((nread=FileRead(fd, (char*)relform,len))!=len)
2722-
{
2723-
write_irels();
2724-
return;
2725-
}
2702+
gotoread_failed;
27262703

27272704
ird->rd_rel=relform;
27282705

@@ -2734,18 +2711,12 @@ init_irels(void)
27342711
for (i=0;i<relform->relnatts;i++)
27352712
{
27362713
if ((nread=FileRead(fd, (char*)&len,sizeof(len)))!=sizeof(len))
2737-
{
2738-
write_irels();
2739-
return;
2740-
}
2714+
gotoread_failed;
27412715

27422716
ird->rd_att->attrs[i]= (Form_pg_attribute)palloc(len);
27432717

27442718
if ((nread=FileRead(fd, (char*)ird->rd_att->attrs[i],len))!=len)
2745-
{
2746-
write_irels();
2747-
return;
2748-
}
2719+
gotoread_failed;
27492720
}
27502721

27512722
/*
@@ -2761,17 +2732,11 @@ init_irels(void)
27612732

27622733
/* next, read the index strategy map */
27632734
if ((nread=FileRead(fd, (char*)&len,sizeof(len)))!=sizeof(len))
2764-
{
2765-
write_irels();
2766-
return;
2767-
}
2735+
gotoread_failed;
27682736

27692737
strat= (IndexStrategy)MemoryContextAlloc(indexcxt,len);
27702738
if ((nread=FileRead(fd, (char*)strat,len))!=len)
2771-
{
2772-
write_irels();
2773-
return;
2774-
}
2739+
gotoread_failed;
27752740

27762741
/* have to invalidate any FmgrInfo data in the strategy maps */
27772742
nstrategies=am->amstrategies*relform->relnatts;
@@ -2782,17 +2747,11 @@ init_irels(void)
27822747

27832748
/* finally, read the vector of support procedures */
27842749
if ((nread=FileRead(fd, (char*)&len,sizeof(len)))!=sizeof(len))
2785-
{
2786-
write_irels();
2787-
return;
2788-
}
2789-
2750+
gotoread_failed;
27902751
support= (RegProcedure*)MemoryContextAlloc(indexcxt,len);
27912752
if ((nread=FileRead(fd, (char*)support,len))!=len)
2792-
{
2793-
write_irels();
2794-
return;
2795-
}
2753+
gotoread_failed;
2754+
27962755
ird->rd_support=support;
27972756

27982757
nsupport=relform->relnatts*am->amsupport;
@@ -2804,7 +2763,16 @@ init_irels(void)
28042763

28052764
RelationCacheInsert(ird);
28062765
}
2766+
2767+
/* successfully read the init file */
2768+
FileClose(fd);
28072769
criticalRelcachesBuilt= true;
2770+
return;
2771+
2772+
/* init file is broken, so do it the hard way */
2773+
read_failed:
2774+
FileClose(fd);
2775+
write_irels();
28082776
}
28092777

28102778
staticvoid
@@ -2976,6 +2944,10 @@ write_irels(void)
29762944
/*
29772945
* And rename the temp file to its final name, deleting any
29782946
* previously-existing init file.
2947+
*
2948+
* Note: a failure here is possible under Cygwin, if some other
2949+
* backend is holding open an unlinked-but-not-yet-gone init file.
2950+
* So treat this as a noncritical failure.
29792951
*/
29802952
if (rename(tempfilename,finalfilename)<0)
29812953
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp