MCPcopy Create free account
hub / github.com/apache/cloudberry / load_relcache_init_file

Function load_relcache_init_file

src/backend/utils/cache/relcache.c:6123–6543  ·  view source on GitHub ↗

* load_relcache_init_file -- attempt to load cache from the shared * or local cache init file * * If successful, return true and set criticalRelcachesBuilt or * criticalSharedRelcachesBuilt to true. * If not successful, return false. * * NOTE: we assume we are already switched into CacheMemoryContext. */

Source from the content-addressed store, hash-verified

6121 * NOTE: we assume we are already switched into CacheMemoryContext.
6122 */
6123static bool
6124load_relcache_init_file(bool shared)
6125{
6126 FILE *fp;
6127 char initfilename[MAXPGPATH];
6128 Relation *rels;
6129 int relno,
6130 num_rels,
6131 max_rels,
6132 nailed_rels,
6133 nailed_indexes,
6134 magic;
6135 int i;
6136
6137 if (shared)
6138 snprintf(initfilename, sizeof(initfilename), "global/%s",
6139 RELCACHE_INIT_FILENAME);
6140 else
6141 snprintf(initfilename, sizeof(initfilename), "%s/%s",
6142 DatabasePath, RELCACHE_INIT_FILENAME);
6143
6144 fp = AllocateFile(initfilename, PG_BINARY_R);
6145 if (fp == NULL)
6146 return false;
6147
6148 /*
6149 * Read the index relcache entries from the file. Note we will not enter
6150 * any of them into the cache if the read fails partway through; this
6151 * helps to guard against broken init files.
6152 */
6153 max_rels = 100;
6154 rels = (Relation *) palloc(max_rels * sizeof(Relation));
6155 num_rels = 0;
6156 nailed_rels = nailed_indexes = 0;
6157
6158 /* check for correct magic number (compatible version) */
6159 if (fread(&magic, 1, sizeof(magic), fp) != sizeof(magic))
6160 goto read_failed;
6161 if (magic != RELCACHE_INIT_FILEMAGIC)
6162 goto read_failed;
6163
6164 for (relno = 0;; relno++)
6165 {
6166 Size len;
6167 size_t nread;
6168 Relation rel;
6169 Form_pg_class relform;
6170 bool has_not_null;
6171
6172 /* first read the relation descriptor length */
6173 nread = fread(&len, 1, sizeof(len), fp);
6174 if (nread != sizeof(len))
6175 {
6176 if (nread == 0)
6177 break; /* end of file */
6178 goto read_failed;
6179 }
6180

Callers 2

Calls 13

AllocateFileFunction · 0.85
CreateTemplateTupleDescFunction · 0.85
InitIndexAmRoutineFunction · 0.85
MemoryContextAllocFunction · 0.85
MemoryContextAllocZeroFunction · 0.85
RelationInitLockInfoFunction · 0.85
RelationInitPhysicalAddrFunction · 0.85
FreeFileFunction · 0.85
pallocFunction · 0.50
repallocFunction · 0.50
palloc0Function · 0.50

Tested by

no test coverage detected