Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 46287bd

Browse files
committed
Simplify relcache startup sequence. With the new design of InitPostgres
it's not necessary to have three separate calls anymore. This patch also fixes things so we don't try to read pg_internal.init until after we've obtained lock on the target database; which was fairly harmless, but it's certainly cleaner this way.
1 parent 52667d5 commit 46287bd

File tree

3 files changed

+49
-55
lines changed

3 files changed

+49
-55
lines changed

src/backend/utils/cache/relcache.c

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.239 2006/04/25 22:46:05 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.240 2006/05/04 18:51:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2156,10 +2156,11 @@ RelationBuildLocalRelation(const char *relname,
21562156
*
21572157
* This initializes the relation descriptor cache. At the time
21582158
* that this is invoked, we can't do database access yet (mainly
2159-
* because the transaction subsystem is not up), so we can't get
2160-
* "real" info. However it's okay to read the pg_internal.init
2161-
* cache file, if one is available. Otherwise we make phony
2162-
* entries for the minimum set of nailed-in-cache relations.
2159+
* because the transaction subsystem is not up); all we are doing
2160+
* is making an empty cache hashtable. This must be done before
2161+
* starting the initialization transaction, because otherwise
2162+
* AtEOXact_RelationCache would crash if that transaction aborts
2163+
* before we can get the relcache set up.
21632164
*/
21642165

21652166
#define INITRELCACHESIZE 400
@@ -2188,10 +2189,38 @@ RelationCacheInitialize(void)
21882189
RelationIdCache = hash_create("Relcache by OID", INITRELCACHESIZE,
21892190
&ctl, HASH_ELEM | HASH_FUNCTION);
21902191

2192+
MemoryContextSwitchTo(oldcxt);
2193+
}
2194+
2195+
/*
2196+
* RelationCacheInitializePhase2
2197+
*
2198+
* This is called as soon as the catcache and transaction system
2199+
* are functional. At this point we can actually read data from
2200+
* the system catalogs. We first try to read pre-computed relcache
2201+
* entries from the pg_internal.init file. If that's missing or
2202+
* broken, make phony entries for the minimum set of nailed-in-cache
2203+
* relations. Then (unless bootstrapping) make sure we have entries
2204+
* for the critical system indexes. Once we've done all this, we
2205+
* have enough infrastructure to open any system catalog or use any
2206+
* catcache. The last step is to rewrite pg_internal.init if needed.
2207+
*/
2208+
void
2209+
RelationCacheInitializePhase2(void)
2210+
{
2211+
HASH_SEQ_STATUS status;
2212+
RelIdCacheEnt *idhentry;
2213+
MemoryContext oldcxt;
2214+
21912215
/*
2192-
* Try to load the relcache cache file. If successful, we're done for
2193-
* now. Otherwise, initialize the cache with pre-made descriptors for the
2194-
* critical "nailed-in" system catalogs.
2216+
* switch to cache memory context
2217+
*/
2218+
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
2219+
2220+
/*
2221+
* Try to load the relcache cache file. If unsuccessful, bootstrap the
2222+
* cache with pre-made descriptors for the critical "nailed-in" system
2223+
* catalogs.
21952224
*/
21962225
if (IsBootstrapProcessingMode() ||
21972226
!load_relcache_init_file())
@@ -2209,23 +2238,8 @@ RelationCacheInitialize(void)
22092238
}
22102239

22112240
MemoryContextSwitchTo(oldcxt);
2212-
}
2213-
2214-
/*
2215-
* RelationCacheInitializePhase2
2216-
*
2217-
* This is called as soon as the catcache and transaction system
2218-
* are functional. At this point we can actually read data from
2219-
* the system catalogs. Update the relcache entries made during
2220-
* RelationCacheInitialize, and make sure we have entries for the
2221-
* critical system indexes.
2222-
*/
2223-
void
2224-
RelationCacheInitializePhase2(void)
2225-
{
2226-
HASH_SEQ_STATUS status;
2227-
RelIdCacheEnt *idhentry;
22282241

2242+
/* In bootstrap mode, the faked-up formrdesc info is all we'll have */
22292243
if (IsBootstrapProcessingMode())
22302244
return;
22312245

@@ -2334,20 +2348,10 @@ RelationCacheInitializePhase2(void)
23342348
if (relation->rd_rel->reltriggers > 0 && relation->trigdesc == NULL)
23352349
RelationBuildTriggers(relation);
23362350
}
2337-
}
2338-
2339-
/*
2340-
* RelationCacheInitializePhase3
2341-
*
2342-
* Final step of relcache initialization: write out a new relcache
2343-
* cache file if one is needed.
2344-
*/
2345-
void
2346-
RelationCacheInitializePhase3(void)
2347-
{
2348-
if (IsBootstrapProcessingMode())
2349-
return;
23502351

2352+
/*
2353+
* Lastly, write out a new relcache cache file if one is needed.
2354+
*/
23512355
if (needNewCacheFile)
23522356
{
23532357
/*

src/backend/utils/init/postinit.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.166 2006/05/04 16:07:29 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.167 2006/05/04 18:51:36 tgl Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -357,16 +357,12 @@ InitPostgres(const char *dbname, const char *username)
357357
InitXLOGAccess();
358358

359359
/*
360-
* Initialize the relation descriptor cache. This must create at least
361-
* the minimum set of "nailed-in" cache entries. No catalog access
362-
* happens here.
360+
* Initialize the relation cache and the system catalog caches. Note that
361+
* no catalog access happens here; we only set up the hashtable structure.
362+
* We must do this before starting a transaction because transaction
363+
* abort would try to touch these hashtables.
363364
*/
364365
RelationCacheInitialize();
365-
366-
/*
367-
* Initialize all the system catalog caches. Note that no catalog access
368-
* happens here; we only set up the cache structure.
369-
*/
370366
InitCatalogCache();
371367

372368
/* Initialize portal manager */
@@ -458,7 +454,8 @@ InitPostgres(const char *dbname, const char *username)
458454
/*
459455
* It's now possible to do real access to the system catalogs.
460456
*
461-
* Replace faked-up relcache entries with correct info.
457+
* Load relcache entries for the system catalogs. This must create at
458+
* least the minimum set of "nailed-in" cache entries.
462459
*/
463460
RelationCacheInitializePhase2();
464461

@@ -503,12 +500,6 @@ InitPostgres(const char *dbname, const char *username)
503500
if (!bootstrap)
504501
CheckMyDatabase(dbname, am_superuser);
505502

506-
/*
507-
* Final phase of relation cache startup: write a new cache file if
508-
* necessary. (XXX this could be folded back into Phase2)
509-
*/
510-
RelationCacheInitializePhase3();
511-
512503
/*
513504
* Check a normal user hasn't connected to a superuser reserved slot.
514505
*/

src/include/utils/relcache.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.53 2006/03/05 15:59:07 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.54 2006/05/04 18:51:36 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -44,7 +44,6 @@ extern void RelationInitIndexAccessInfo(Relation relation);
4444
*/
4545
extern void RelationCacheInitialize(void);
4646
extern void RelationCacheInitializePhase2(void);
47-
extern void RelationCacheInitializePhase3(void);
4847

4948
/*
5049
* Routine to create a relcache entry for an about-to-be-created relation

0 commit comments

Comments
 (0)