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)
26592659return ;
26602660}
26612661
2662- FileSeek (fd ,0L ,SEEK_SET );
2663-
26642662for (relno = 0 ;relno < Num_indices_bootstrap ;relno ++ )
26652663{
26662664/* first read the relation descriptor length */
26672665if ((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 */
26742669if (len != sizeof (RelationData ))
2675- {
2676- write_irels ();
2677- return ;
2678- }
2670+ gotoread_failed ;
26792671
26802672ird = irel [relno ]= (Relation )palloc (len );
26812673MemSet (ird ,0 ,len );
26822674
26832675/* then, read the Relation structure */
26842676if ((nread = FileRead (fd , (char * )ird ,len ))!= len )
2685- {
2686- write_irels ();
2687- return ;
2688- }
2677+ gotoread_failed ;
26892678
26902679/* reset transient fields */
26912680ird -> rd_targblock = InvalidBlockNumber ;
@@ -2696,33 +2685,21 @@ init_irels(void)
26962685
26972686/* next, read the access method tuple form */
26982687if ((nread = FileRead (fd , (char * )& len ,sizeof (len )))!= sizeof (len ))
2699- {
2700- write_irels ();
2701- return ;
2702- }
2688+ gotoread_failed ;
27032689
27042690am = (Form_pg_am )palloc (len );
27052691if ((nread = FileRead (fd , (char * )am ,len ))!= len )
2706- {
2707- write_irels ();
2708- return ;
2709- }
2692+ gotoread_failed ;
27102693
27112694ird -> rd_am = am ;
27122695
27132696/* next read the relation tuple form */
27142697if ((nread = FileRead (fd , (char * )& len ,sizeof (len )))!= sizeof (len ))
2715- {
2716- write_irels ();
2717- return ;
2718- }
2698+ gotoread_failed ;
27192699
27202700relform = (Form_pg_class )palloc (len );
27212701if ((nread = FileRead (fd , (char * )relform ,len ))!= len )
2722- {
2723- write_irels ();
2724- return ;
2725- }
2702+ gotoread_failed ;
27262703
27272704ird -> rd_rel = relform ;
27282705
@@ -2734,18 +2711,12 @@ init_irels(void)
27342711for (i = 0 ;i < relform -> relnatts ;i ++ )
27352712{
27362713if ((nread = FileRead (fd , (char * )& len ,sizeof (len )))!= sizeof (len ))
2737- {
2738- write_irels ();
2739- return ;
2740- }
2714+ gotoread_failed ;
27412715
27422716ird -> rd_att -> attrs [i ]= (Form_pg_attribute )palloc (len );
27432717
27442718if ((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 */
27632734if ((nread = FileRead (fd , (char * )& len ,sizeof (len )))!= sizeof (len ))
2764- {
2765- write_irels ();
2766- return ;
2767- }
2735+ gotoread_failed ;
27682736
27692737strat = (IndexStrategy )MemoryContextAlloc (indexcxt ,len );
27702738if ((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 */
27772742nstrategies = am -> amstrategies * relform -> relnatts ;
@@ -2782,17 +2747,11 @@ init_irels(void)
27822747
27832748/* finally, read the vector of support procedures */
27842749if ((nread = FileRead (fd , (char * )& len ,sizeof (len )))!= sizeof (len ))
2785- {
2786- write_irels ();
2787- return ;
2788- }
2789-
2750+ gotoread_failed ;
27902751support = (RegProcedure * )MemoryContextAlloc (indexcxt ,len );
27912752if ((nread = FileRead (fd , (char * )support ,len ))!= len )
2792- {
2793- write_irels ();
2794- return ;
2795- }
2753+ gotoread_failed ;
2754+
27962755ird -> rd_support = support ;
27972756
27982757nsupport = relform -> relnatts * am -> amsupport ;
@@ -2804,7 +2763,16 @@ init_irels(void)
28042763
28052764RelationCacheInsert (ird );
28062765}
2766+
2767+ /* successfully read the init file */
2768+ FileClose (fd );
28072769criticalRelcachesBuilt = 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
28102778static void
@@ -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 */
29802952if (rename (tempfilename ,finalfilename )< 0 )
29812953{