diff options
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r-- | src/backend/utils/cache/Makefile | 2 | ||||
-rw-r--r-- | src/backend/utils/cache/inval.c | 16 | ||||
-rw-r--r-- | src/backend/utils/cache/relcache.c | 186 | ||||
-rw-r--r-- | src/backend/utils/cache/relfilenumbermap.c (renamed from src/backend/utils/cache/relfilenodemap.c) | 102 | ||||
-rw-r--r-- | src/backend/utils/cache/relmapper.c | 88 |
5 files changed, 198 insertions, 196 deletions
diff --git a/src/backend/utils/cache/Makefile b/src/backend/utils/cache/Makefile index 38e46d274b2..5105018cb79 100644 --- a/src/backend/utils/cache/Makefile +++ b/src/backend/utils/cache/Makefile @@ -21,7 +21,7 @@ OBJS = \ partcache.o \ plancache.o \ relcache.o \ - relfilenodemap.o \ + relfilenumbermap.o \ relmapper.o \ spccache.o \ syscache.o \ diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index af000d4f488..eb5782f82a4 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -661,11 +661,11 @@ LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg) * We could have smgr entries for relations of other databases, so no * short-circuit test is possible here. */ - RelFileNodeBackend rnode; + RelFileLocatorBackend rlocator; - rnode.node = msg->sm.rnode; - rnode.backend = (msg->sm.backend_hi << 16) | (int) msg->sm.backend_lo; - smgrclosenode(rnode); + rlocator.locator = msg->sm.rlocator; + rlocator.backend = (msg->sm.backend_hi << 16) | (int) msg->sm.backend_lo; + smgrcloserellocator(rlocator); } else if (msg->id == SHAREDINVALRELMAP_ID) { @@ -1459,14 +1459,14 @@ CacheInvalidateRelcacheByRelid(Oid relid) * Thus, the maximum possible backend ID is 2^23-1. */ void -CacheInvalidateSmgr(RelFileNodeBackend rnode) +CacheInvalidateSmgr(RelFileLocatorBackend rlocator) { SharedInvalidationMessage msg; msg.sm.id = SHAREDINVALSMGR_ID; - msg.sm.backend_hi = rnode.backend >> 16; - msg.sm.backend_lo = rnode.backend & 0xffff; - msg.sm.rnode = rnode.node; + msg.sm.backend_hi = rlocator.backend >> 16; + msg.sm.backend_lo = rlocator.backend & 0xffff; + msg.sm.rlocator = rlocator.locator; /* check AddCatcacheInvalidationMessage() for an explanation */ VALGRIND_MAKE_MEM_DEFINED(&msg, sizeof(msg)); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index f502df91dca..bdb771d278f 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -369,7 +369,7 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic) /* * The caller might need a tuple that's newer than the one the historic * snapshot; currently the only case requiring to do so is looking up the - * relfilenode of non mapped system relations during decoding. That + * relfilenumber of non mapped system relations during decoding. That * snapshot can't change in the midst of a relcache build, so there's no * need to register the snapshot. */ @@ -1133,8 +1133,8 @@ retry: relation->rd_refcnt = 0; relation->rd_isnailed = false; relation->rd_createSubid = InvalidSubTransactionId; - relation->rd_newRelfilenodeSubid = InvalidSubTransactionId; - relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + relation->rd_newRelfilelocatorSubid = InvalidSubTransactionId; + relation->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; relation->rd_droppedSubid = InvalidSubTransactionId; switch (relation->rd_rel->relpersistence) { @@ -1300,7 +1300,7 @@ retry: } /* - * Initialize the physical addressing info (RelFileNode) for a relcache entry + * Initialize the physical addressing info (RelFileLocator) for a relcache entry * * Note: at the physical level, relations in the pg_global tablespace must * be treated as shared, even if relisshared isn't set. Hence we do not @@ -1309,20 +1309,20 @@ retry: static void RelationInitPhysicalAddr(Relation relation) { - Oid oldnode = relation->rd_node.relNode; + RelFileNumber oldnumber = relation->rd_locator.relNumber; /* these relations kinds never have storage */ if (!RELKIND_HAS_STORAGE(relation->rd_rel->relkind)) return; if (relation->rd_rel->reltablespace) - relation->rd_node.spcNode = relation->rd_rel->reltablespace; + relation->rd_locator.spcOid = relation->rd_rel->reltablespace; else - relation->rd_node.spcNode = MyDatabaseTableSpace; - if (relation->rd_node.spcNode == GLOBALTABLESPACE_OID) - relation->rd_node.dbNode = InvalidOid; + relation->rd_locator.spcOid = MyDatabaseTableSpace; + if (relation->rd_locator.spcOid == GLOBALTABLESPACE_OID) + relation->rd_locator.dbOid = InvalidOid; else - relation->rd_node.dbNode = MyDatabaseId; + relation->rd_locator.dbOid = MyDatabaseId; if (relation->rd_rel->relfilenode) { @@ -1356,30 +1356,30 @@ RelationInitPhysicalAddr(Relation relation) heap_freetuple(phys_tuple); } - relation->rd_node.relNode = relation->rd_rel->relfilenode; + relation->rd_locator.relNumber = relation->rd_rel->relfilenode; } else { /* Consult the relation mapper */ - relation->rd_node.relNode = - RelationMapOidToFilenode(relation->rd_id, - relation->rd_rel->relisshared); - if (!OidIsValid(relation->rd_node.relNode)) + relation->rd_locator.relNumber = + RelationMapOidToFilenumber(relation->rd_id, + relation->rd_rel->relisshared); + if (!RelFileNumberIsValid(relation->rd_locator.relNumber)) elog(ERROR, "could not find relation mapping for relation \"%s\", OID %u", RelationGetRelationName(relation), relation->rd_id); } /* * For RelationNeedsWAL() to answer correctly on parallel workers, restore - * rd_firstRelfilenodeSubid. No subtransactions start or end while in + * rd_firstRelfilelocatorSubid. No subtransactions start or end while in * parallel mode, so the specific SubTransactionId does not matter. */ - if (IsParallelWorker() && oldnode != relation->rd_node.relNode) + if (IsParallelWorker() && oldnumber != relation->rd_locator.relNumber) { - if (RelFileNodeSkippingWAL(relation->rd_node)) - relation->rd_firstRelfilenodeSubid = TopSubTransactionId; + if (RelFileLocatorSkippingWAL(relation->rd_locator)) + relation->rd_firstRelfilelocatorSubid = TopSubTransactionId; else - relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + relation->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; } } @@ -1889,8 +1889,8 @@ formrdesc(const char *relationName, Oid relationReltype, */ relation->rd_isnailed = true; relation->rd_createSubid = InvalidSubTransactionId; - relation->rd_newRelfilenodeSubid = InvalidSubTransactionId; - relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + relation->rd_newRelfilelocatorSubid = InvalidSubTransactionId; + relation->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; relation->rd_droppedSubid = InvalidSubTransactionId; relation->rd_backend = InvalidBackendId; relation->rd_islocaltemp = false; @@ -1978,11 +1978,11 @@ formrdesc(const char *relationName, Oid relationReltype, /* * All relations made with formrdesc are mapped. This is necessarily so - * because there is no other way to know what filenode they currently + * because there is no other way to know what filenumber they currently * have. In bootstrap mode, add them to the initial relation mapper data, - * specifying that the initial filenode is the same as the OID. + * specifying that the initial filenumber is the same as the OID. */ - relation->rd_rel->relfilenode = InvalidOid; + relation->rd_rel->relfilenode = InvalidRelFileNumber; if (IsBootstrapProcessingMode()) RelationMapUpdateMap(RelationGetRelid(relation), RelationGetRelid(relation), @@ -2180,7 +2180,7 @@ RelationClose(Relation relation) #ifdef RELCACHE_FORCE_RELEASE if (RelationHasReferenceCountZero(relation) && relation->rd_createSubid == InvalidSubTransactionId && - relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId) + relation->rd_firstRelfilelocatorSubid == InvalidSubTransactionId) RelationClearRelation(relation, false); #endif } @@ -2352,7 +2352,7 @@ RelationReloadNailed(Relation relation) { /* * If it's a nailed-but-not-mapped index, then we need to re-read the - * pg_class row to see if its relfilenode changed. + * pg_class row to see if its relfilenumber changed. */ RelationReloadIndexInfo(relation); } @@ -2700,8 +2700,8 @@ RelationClearRelation(Relation relation, bool rebuild) Assert(newrel->rd_isnailed == relation->rd_isnailed); /* creation sub-XIDs must be preserved */ SWAPFIELD(SubTransactionId, rd_createSubid); - SWAPFIELD(SubTransactionId, rd_newRelfilenodeSubid); - SWAPFIELD(SubTransactionId, rd_firstRelfilenodeSubid); + SWAPFIELD(SubTransactionId, rd_newRelfilelocatorSubid); + SWAPFIELD(SubTransactionId, rd_firstRelfilelocatorSubid); SWAPFIELD(SubTransactionId, rd_droppedSubid); /* un-swap rd_rel pointers, swap contents instead */ SWAPFIELD(Form_pg_class, rd_rel); @@ -2791,12 +2791,12 @@ static void RelationFlushRelation(Relation relation) { if (relation->rd_createSubid != InvalidSubTransactionId || - relation->rd_firstRelfilenodeSubid != InvalidSubTransactionId) + relation->rd_firstRelfilelocatorSubid != InvalidSubTransactionId) { /* * New relcache entries are always rebuilt, not flushed; else we'd * forget the "new" status of the relation. Ditto for the - * new-relfilenode status. + * new-relfilenumber status. * * The rel could have zero refcnt here, so temporarily increment the * refcnt to ensure it's safe to rebuild it. We can assume that the @@ -2835,7 +2835,7 @@ RelationForgetRelation(Oid rid) Assert(relation->rd_droppedSubid == InvalidSubTransactionId); if (relation->rd_createSubid != InvalidSubTransactionId || - relation->rd_firstRelfilenodeSubid != InvalidSubTransactionId) + relation->rd_firstRelfilelocatorSubid != InvalidSubTransactionId) { /* * In the event of subtransaction rollback, we must not forget @@ -2894,7 +2894,7 @@ RelationCacheInvalidateEntry(Oid relationId) * * Apart from debug_discard_caches, this is currently used only to recover * from SI message buffer overflow, so we do not touch relations having - * new-in-transaction relfilenodes; they cannot be targets of cross-backend + * new-in-transaction relfilenumbers; they cannot be targets of cross-backend * SI updates (and our own updates now go through a separate linked list * that isn't limited by the SI message buffer size). * @@ -2909,7 +2909,7 @@ RelationCacheInvalidateEntry(Oid relationId) * so hash_seq_search will complete safely; (b) during the second pass we * only hold onto pointers to nondeletable entries. * - * The two-phase approach also makes it easy to update relfilenodes for + * The two-phase approach also makes it easy to update relfilenumbers for * mapped relations before we do anything else, and to ensure that the * second pass processes nailed-in-cache items before other nondeletable * items. This should ensure that system catalogs are up to date before @@ -2948,12 +2948,12 @@ RelationCacheInvalidate(bool debug_discard) /* * Ignore new relations; no other backend will manipulate them before - * we commit. Likewise, before replacing a relation's relfilenode, we - * shall have acquired AccessExclusiveLock and drained any applicable - * pending invalidations. + * we commit. Likewise, before replacing a relation's relfilelocator, + * we shall have acquired AccessExclusiveLock and drained any + * applicable pending invalidations. */ if (relation->rd_createSubid != InvalidSubTransactionId || - relation->rd_firstRelfilenodeSubid != InvalidSubTransactionId) + relation->rd_firstRelfilelocatorSubid != InvalidSubTransactionId) continue; relcacheInvalsReceived++; @@ -2967,8 +2967,8 @@ RelationCacheInvalidate(bool debug_discard) else { /* - * If it's a mapped relation, immediately update its rd_node in - * case its relfilenode changed. We must do this during phase 1 + * If it's a mapped relation, immediately update its rd_locator in + * case its relfilenumber changed. We must do this during phase 1 * in case the relation is consulted during rebuild of other * relcache entries in phase 2. It's safe since consulting the * map doesn't involve any access to relcache entries. @@ -3078,14 +3078,14 @@ AssertPendingSyncConsistency(Relation relation) RelationIsPermanent(relation) && ((relation->rd_createSubid != InvalidSubTransactionId && RELKIND_HAS_STORAGE(relation->rd_rel->relkind)) || - relation->rd_firstRelfilenodeSubid != InvalidSubTransactionId); + relation->rd_firstRelfilelocatorSubid != InvalidSubTransactionId); - Assert(relcache_verdict == RelFileNodeSkippingWAL(relation->rd_node)); + Assert(relcache_verdict == RelFileLocatorSkippingWAL(relation->rd_locator)); if (relation->rd_droppedSubid != InvalidSubTransactionId) Assert(!relation->rd_isvalid && (relation->rd_createSubid != InvalidSubTransactionId || - relation->rd_firstRelfilenodeSubid != InvalidSubTransactionId)); + relation->rd_firstRelfilelocatorSubid != InvalidSubTransactionId)); } /* @@ -3282,8 +3282,8 @@ AtEOXact_cleanup(Relation relation, bool isCommit) * also lets RelationClearRelation() drop the relcache entry. */ relation->rd_createSubid = InvalidSubTransactionId; - relation->rd_newRelfilenodeSubid = InvalidSubTransactionId; - relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + relation->rd_newRelfilelocatorSubid = InvalidSubTransactionId; + relation->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; relation->rd_droppedSubid = InvalidSubTransactionId; if (clear_relcache) @@ -3397,8 +3397,8 @@ AtEOSubXact_cleanup(Relation relation, bool isCommit, { /* allow the entry to be removed */ relation->rd_createSubid = InvalidSubTransactionId; - relation->rd_newRelfilenodeSubid = InvalidSubTransactionId; - relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + relation->rd_newRelfilelocatorSubid = InvalidSubTransactionId; + relation->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; relation->rd_droppedSubid = InvalidSubTransactionId; RelationClearRelation(relation, false); return; @@ -3419,23 +3419,23 @@ AtEOSubXact_cleanup(Relation relation, bool isCommit, } /* - * Likewise, update or drop any new-relfilenode-in-subtransaction record + * Likewise, update or drop any new-relfilenumber-in-subtransaction record * or drop record. */ - if (relation->rd_newRelfilenodeSubid == mySubid) + if (relation->rd_newRelfilelocatorSubid == mySubid) { if (isCommit) - relation->rd_newRelfilenodeSubid = parentSubid; + relation->rd_newRelfilelocatorSubid = parentSubid; else - relation->rd_newRelfilenodeSubid = InvalidSubTransactionId; + relation->rd_newRelfilelocatorSubid = InvalidSubTransactionId; } - if (relation->rd_firstRelfilenodeSubid == mySubid) + if (relation->rd_firstRelfilelocatorSubid == mySubid) { if (isCommit) - relation->rd_firstRelfilenodeSubid = parentSubid; + relation->rd_firstRelfilelocatorSubid = parentSubid; else - relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + relation->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; } if (relation->rd_droppedSubid == mySubid) @@ -3459,7 +3459,7 @@ RelationBuildLocalRelation(const char *relname, TupleDesc tupDesc, Oid relid, Oid accessmtd, - Oid relfilenode, + RelFileNumber relfilenumber, Oid reltablespace, bool shared_relation, bool mapped_relation, @@ -3533,8 +3533,8 @@ RelationBuildLocalRelation(const char *relname, /* it's being created in this transaction */ rel->rd_createSubid = GetCurrentSubTransactionId(); - rel->rd_newRelfilenodeSubid = InvalidSubTransactionId; - rel->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + rel->rd_newRelfilelocatorSubid = InvalidSubTransactionId; + rel->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; rel->rd_droppedSubid = InvalidSubTransactionId; /* @@ -3616,8 +3616,8 @@ RelationBuildLocalRelation(const char *relname, /* * Insert relation physical and logical identifiers (OIDs) into the right - * places. For a mapped relation, we set relfilenode to zero and rely on - * RelationInitPhysicalAddr to consult the map. + * places. For a mapped relation, we set relfilenumber to zero and rely + * on RelationInitPhysicalAddr to consult the map. */ rel->rd_rel->relisshared = shared_relation; @@ -3630,12 +3630,12 @@ RelationBuildLocalRelation(const char *relname, if (mapped_relation) { - rel->rd_rel->relfilenode = InvalidOid; + rel->rd_rel->relfilenode = InvalidRelFileNumber; /* Add it to the active mapping information */ - RelationMapUpdateMap(relid, relfilenode, shared_relation, true); + RelationMapUpdateMap(relid, relfilenumber, shared_relation, true); } else - rel->rd_rel->relfilenode = relfilenode; + rel->rd_rel->relfilenode = relfilenumber; RelationInitLockInfo(rel); /* see lmgr.c */ @@ -3683,13 +3683,13 @@ RelationBuildLocalRelation(const char *relname, /* - * RelationSetNewRelfilenode + * RelationSetNewRelfilenumber * - * Assign a new relfilenode (physical file name), and possibly a new + * Assign a new relfilenumber (physical file name), and possibly a new * persistence setting, to the relation. * * This allows a full rewrite of the relation to be done with transactional - * safety (since the filenode assignment can be rolled back). Note however + * safety (since the filenumber assignment can be rolled back). Note however * that there is no simple way to access the relation's old data for the * remainder of the current transaction. This limits the usefulness to cases * such as TRUNCATE or rebuilding an index from scratch. @@ -3697,19 +3697,19 @@ RelationBuildLocalRelation(const char *relname, * Caller must already hold exclusive lock on the relation. */ void -RelationSetNewRelfilenode(Relation relation, char persistence) +RelationSetNewRelfilenumber(Relation relation, char persistence) { - Oid newrelfilenode; + RelFileNumber newrelfilenumber; Relation pg_class; HeapTuple tuple; Form_pg_class classform; MultiXactId minmulti = InvalidMultiXactId; TransactionId freezeXid = InvalidTransactionId; - RelFileNode newrnode; + RelFileLocator newrlocator; - /* Allocate a new relfilenode */ - newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace, NULL, - persistence); + /* Allocate a new relfilenumber */ + newrelfilenumber = GetNewRelFileNumber(relation->rd_rel->reltablespace, + NULL, persistence); /* * Get a writable copy of the pg_class tuple for the given relation. @@ -3729,28 +3729,28 @@ RelationSetNewRelfilenode(Relation relation, char persistence) RelationDropStorage(relation); /* - * Create storage for the main fork of the new relfilenode. If it's a + * Create storage for the main fork of the new relfilenumber. If it's a * table-like object, call into the table AM to do so, which'll also * create the table's init fork if needed. * - * NOTE: If relevant for the AM, any conflict in relfilenode value will be - * caught here, if GetNewRelFileNode messes up for any reason. + * NOTE: If relevant for the AM, any conflict in relfilenumber value will + * be caught here, if GetNewRelFileNumber messes up for any reason. */ - newrnode = relation->rd_node; - newrnode.relNode = newrelfilenode; + newrlocator = relation->rd_locator; + newrlocator.relNumber = newrelfilenumber; if (RELKIND_HAS_TABLE_AM(relation->rd_rel->relkind)) { - table_relation_set_new_filenode(relation, &newrnode, - persistence, - &freezeXid, &minmulti); + table_relation_set_new_filelocator(relation, &newrlocator, + persistence, + &freezeXid, &minmulti); } else if (RELKIND_HAS_STORAGE(relation->rd_rel->relkind)) { /* handle these directly, at least for now */ SMgrRelation srel; - srel = RelationCreateStorage(newrnode, persistence, true); + srel = RelationCreateStorage(newrlocator, persistence, true); smgrclose(srel); } else @@ -3789,7 +3789,7 @@ RelationSetNewRelfilenode(Relation relation, char persistence) /* Do the deed */ RelationMapUpdateMap(RelationGetRelid(relation), - newrelfilenode, + newrelfilenumber, relation->rd_rel->relisshared, false); @@ -3799,7 +3799,7 @@ RelationSetNewRelfilenode(Relation relation, char persistence) else { /* Normal case, update the pg_class entry */ - classform->relfilenode = newrelfilenode; + classform->relfilenode = newrelfilenumber; /* relpages etc. never change for sequences */ if (relation->rd_rel->relkind != RELKIND_SEQUENCE) @@ -3825,27 +3825,27 @@ RelationSetNewRelfilenode(Relation relation, char persistence) */ CommandCounterIncrement(); - RelationAssumeNewRelfilenode(relation); + RelationAssumeNewRelfilelocator(relation); } /* - * RelationAssumeNewRelfilenode + * RelationAssumeNewRelfilelocator * * Code that modifies pg_class.reltablespace or pg_class.relfilenode must call * this. The call shall precede any code that might insert WAL records whose - * replay would modify bytes in the new RelFileNode, and the call shall follow - * any WAL modifying bytes in the prior RelFileNode. See struct RelationData. + * replay would modify bytes in the new RelFileLocator, and the call shall follow + * any WAL modifying bytes in the prior RelFileLocator. See struct RelationData. * Ideally, call this as near as possible to the CommandCounterIncrement() * that makes the pg_class change visible (before it or after it); that * minimizes the chance of future development adding a forbidden WAL insertion - * between RelationAssumeNewRelfilenode() and CommandCounterIncrement(). + * between RelationAssumeNewRelfilelocator() and CommandCounterIncrement(). */ void -RelationAssumeNewRelfilenode(Relation relation) +RelationAssumeNewRelfilelocator(Relation relation) { - relation->rd_newRelfilenodeSubid = GetCurrentSubTransactionId(); - if (relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId) - relation->rd_firstRelfilenodeSubid = relation->rd_newRelfilenodeSubid; + relation->rd_newRelfilelocatorSubid = GetCurrentSubTransactionId(); + if (relation->rd_firstRelfilelocatorSubid == InvalidSubTransactionId) + relation->rd_firstRelfilelocatorSubid = relation->rd_newRelfilelocatorSubid; /* Flag relation as needing eoxact cleanup (to clear these fields) */ EOXactListAdd(relation); @@ -6254,8 +6254,8 @@ load_relcache_init_file(bool shared) rel->rd_fkeyvalid = false; rel->rd_fkeylist = NIL; rel->rd_createSubid = InvalidSubTransactionId; - rel->rd_newRelfilenodeSubid = InvalidSubTransactionId; - rel->rd_firstRelfilenodeSubid = InvalidSubTransactionId; + rel->rd_newRelfilelocatorSubid = InvalidSubTransactionId; + rel->rd_firstRelfilelocatorSubid = InvalidSubTransactionId; rel->rd_droppedSubid = InvalidSubTransactionId; rel->rd_amcache = NULL; rel->pgstat_info = NULL; diff --git a/src/backend/utils/cache/relfilenodemap.c b/src/backend/utils/cache/relfilenumbermap.c index 70c323c720d..c4245d5ccdd 100644 --- a/src/backend/utils/cache/relfilenodemap.c +++ b/src/backend/utils/cache/relfilenumbermap.c @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------- * - * relfilenodemap.c - * relfilenode to oid mapping cache. + * relfilenumbermap.c + * relfilenumber to oid mapping cache. * * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * src/backend/utils/cache/relfilenodemap.c + * src/backend/utils/cache/relfilenumbermap.c * *------------------------------------------------------------------------- */ @@ -25,42 +25,42 @@ #include "utils/hsearch.h" #include "utils/inval.h" #include "utils/rel.h" -#include "utils/relfilenodemap.h" +#include "utils/relfilenumbermap.h" #include "utils/relmapper.h" -/* Hash table for information about each relfilenode <-> oid pair */ -static HTAB *RelfilenodeMapHash = NULL; +/* Hash table for information about each relfilenumber <-> oid pair */ +static HTAB *RelfilenumberMapHash = NULL; -/* built first time through in InitializeRelfilenodeMap */ -static ScanKeyData relfilenode_skey[2]; +/* built first time through in InitializeRelfilenumberMap */ +static ScanKeyData relfilenumber_skey[2]; typedef struct { Oid reltablespace; - Oid relfilenode; -} RelfilenodeMapKey; + RelFileNumber relfilenumber; +} RelfilenumberMapKey; typedef struct { - RelfilenodeMapKey key; /* lookup key - must be first */ + RelfilenumberMapKey key; /* lookup key - must be first */ Oid relid; /* pg_class.oid */ -} RelfilenodeMapEntry; +} RelfilenumberMapEntry; /* - * RelfilenodeMapInvalidateCallback + * RelfilenumberMapInvalidateCallback * Flush mapping entries when pg_class is updated in a relevant fashion. */ static void -RelfilenodeMapInvalidateCallback(Datum arg, Oid relid) +RelfilenumberMapInvalidateCallback(Datum arg, Oid relid) { HASH_SEQ_STATUS status; - RelfilenodeMapEntry *entry; + RelfilenumberMapEntry *entry; /* callback only gets registered after creating the hash */ - Assert(RelfilenodeMapHash != NULL); + Assert(RelfilenumberMapHash != NULL); - hash_seq_init(&status, RelfilenodeMapHash); - while ((entry = (RelfilenodeMapEntry *) hash_seq_search(&status)) != NULL) + hash_seq_init(&status, RelfilenumberMapHash); + while ((entry = (RelfilenumberMapEntry *) hash_seq_search(&status)) != NULL) { /* * If relid is InvalidOid, signaling a complete reset, we must remove @@ -71,7 +71,7 @@ RelfilenodeMapInvalidateCallback(Datum arg, Oid relid) entry->relid == InvalidOid || /* negative cache entry */ entry->relid == relid) /* individual flushed relation */ { - if (hash_search(RelfilenodeMapHash, + if (hash_search(RelfilenumberMapHash, (void *) &entry->key, HASH_REMOVE, NULL) == NULL) @@ -81,11 +81,11 @@ RelfilenodeMapInvalidateCallback(Datum arg, Oid relid) } /* - * InitializeRelfilenodeMap + * InitializeRelfilenumberMap * Initialize cache, either on first use or after a reset. */ static void -InitializeRelfilenodeMap(void) +InitializeRelfilenumberMap(void) { HASHCTL ctl; int i; @@ -95,50 +95,50 @@ InitializeRelfilenodeMap(void) CreateCacheMemoryContext(); /* build skey */ - MemSet(&relfilenode_skey, 0, sizeof(relfilenode_skey)); + MemSet(&relfilenumber_skey, 0, sizeof(relfilenumber_skey)); for (i = 0; i < 2; i++) { fmgr_info_cxt(F_OIDEQ, - &relfilenode_skey[i].sk_func, + &relfilenumber_skey[i].sk_func, CacheMemoryContext); - relfilenode_skey[i].sk_strategy = BTEqualStrategyNumber; - relfilenode_skey[i].sk_subtype = InvalidOid; - relfilenode_skey[i].sk_collation = InvalidOid; + relfilenumber_skey[i].sk_strategy = BTEqualStrategyNumber; + relfilenumber_skey[i].sk_subtype = InvalidOid; + relfilenumber_skey[i].sk_collation = InvalidOid; } - relfilenode_skey[0].sk_attno = Anum_pg_class_reltablespace; - relfilenode_skey[1].sk_attno = Anum_pg_class_relfilenode; + relfilenumber_skey[0].sk_attno = Anum_pg_class_reltablespace; + relfilenumber_skey[1].sk_attno = Anum_pg_class_relfilenode; /* - * Only create the RelfilenodeMapHash now, so we don't end up partially + * Only create the RelfilenumberMapHash now, so we don't end up partially * initialized when fmgr_info_cxt() above ERRORs out with an out of memory * error. */ - ctl.keysize = sizeof(RelfilenodeMapKey); - ctl.entrysize = sizeof(RelfilenodeMapEntry); + ctl.keysize = sizeof(RelfilenumberMapKey); + ctl.entrysize = sizeof(RelfilenumberMapEntry); ctl.hcxt = CacheMemoryContext; - RelfilenodeMapHash = - hash_create("RelfilenodeMap cache", 64, &ctl, + RelfilenumberMapHash = + hash_create("RelfilenumberMap cache", 64, &ctl, HASH_ELEM | HASH_BLOBS | HASH_CONTEXT); /* Watch for invalidation events. */ - CacheRegisterRelcacheCallback(RelfilenodeMapInvalidateCallback, + CacheRegisterRelcacheCallback(RelfilenumberMapInvalidateCallback, (Datum) 0); } /* - * Map a relation's (tablespace, filenode) to a relation's oid and cache the - * result. + * Map a relation's (tablespace, relfilenumber) to a relation's oid and cache + * the result. * * Returns InvalidOid if no relation matching the criteria could be found. */ Oid -RelidByRelfilenode(Oid reltablespace, Oid relfilenode) +RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber) { - RelfilenodeMapKey key; - RelfilenodeMapEntry *entry; + RelfilenumberMapKey key; + RelfilenumberMapEntry *entry; bool found; SysScanDesc scandesc; Relation relation; @@ -146,8 +146,8 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) ScanKeyData skey[2]; Oid relid; - if (RelfilenodeMapHash == NULL) - InitializeRelfilenodeMap(); + if (RelfilenumberMapHash == NULL) + InitializeRelfilenumberMap(); /* pg_class will show 0 when the value is actually MyDatabaseTableSpace */ if (reltablespace == MyDatabaseTableSpace) @@ -155,7 +155,7 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) MemSet(&key, 0, sizeof(key)); key.reltablespace = reltablespace; - key.relfilenode = relfilenode; + key.relfilenumber = relfilenumber; /* * Check cache and return entry if one is found. Even if no target @@ -164,7 +164,7 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) * since querying invalid values isn't supposed to be a frequent thing, * but it's basically free. */ - entry = hash_search(RelfilenodeMapHash, (void *) &key, HASH_FIND, &found); + entry = hash_search(RelfilenumberMapHash, (void *) &key, HASH_FIND, &found); if (found) return entry->relid; @@ -179,7 +179,7 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) /* * Ok, shared table, check relmapper. */ - relid = RelationMapFilenodeToOid(relfilenode, true); + relid = RelationMapFilenumberToOid(relfilenumber, true); } else { @@ -192,11 +192,11 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) relation = table_open(RelationRelationId, AccessShareLock); /* copy scankey to local copy, it will be modified during the scan */ - memcpy(skey, relfilenode_skey, sizeof(skey)); + memcpy(skey, relfilenumber_skey, sizeof(skey)); /* set scan arguments */ skey[0].sk_argument = ObjectIdGetDatum(reltablespace); - skey[1].sk_argument = ObjectIdGetDatum(relfilenode); + skey[1].sk_argument = ObjectIdGetDatum(relfilenumber); scandesc = systable_beginscan(relation, ClassTblspcRelfilenodeIndexId, @@ -213,12 +213,12 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) if (found) elog(ERROR, - "unexpected duplicate for tablespace %u, relfilenode %u", - reltablespace, relfilenode); + "unexpected duplicate for tablespace %u, relfilenumber %u", + reltablespace, relfilenumber); found = true; Assert(classform->reltablespace == reltablespace); - Assert(classform->relfilenode == relfilenode); + Assert(classform->relfilenode == relfilenumber); relid = classform->oid; } @@ -227,7 +227,7 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) /* check for tables that are mapped but not shared */ if (!found) - relid = RelationMapFilenodeToOid(relfilenode, false); + relid = RelationMapFilenumberToOid(relfilenumber, false); } /* @@ -235,7 +235,7 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) * caused cache invalidations to be executed which would have deleted a * new entry if we had entered it above. */ - entry = hash_search(RelfilenodeMapHash, (void *) &key, HASH_ENTER, &found); + entry = hash_search(RelfilenumberMapHash, (void *) &key, HASH_ENTER, &found); if (found) elog(ERROR, "corrupted hashtable"); entry->relid = relid; diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c index 2a330cf3ba4..8e5595b468a 100644 --- a/src/backend/utils/cache/relmapper.c +++ b/src/backend/utils/cache/relmapper.c @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------- * * relmapper.c - * Catalog-to-filenode mapping + * Catalog-to-filenumber mapping * * For most tables, the physical file underlying the table is specified by * pg_class.relfilenode. However, that obviously won't work for pg_class @@ -11,7 +11,7 @@ * update other databases' pg_class entries when relocating a shared catalog. * Therefore, for these special catalogs (henceforth referred to as "mapped * catalogs") we rely on a separately maintained file that shows the mapping - * from catalog OIDs to filenode numbers. Each database has a map file for + * from catalog OIDs to filenumbers. Each database has a map file for * its local mapped catalogs, and there is a separate map file for shared * catalogs. Mapped catalogs have zero in their pg_class.relfilenode entries. * @@ -79,7 +79,7 @@ typedef struct RelMapping { Oid mapoid; /* OID of a catalog */ - Oid mapfilenode; /* its filenode number */ + RelFileNumber mapfilenumber; /* its rel file number */ } RelMapping; typedef struct RelMapFile @@ -116,7 +116,7 @@ static RelMapFile local_map; * subtransactions, so one set of transaction-level changes is sufficient. * * The active_xxx variables contain updates that are valid in our transaction - * and should be honored by RelationMapOidToFilenode. The pending_xxx + * and should be honored by RelationMapOidToFilenumber. The pending_xxx * variables contain updates we have been told about that aren't active yet; * they will become active at the next CommandCounterIncrement. This setup * lets map updates act similarly to updates of pg_class rows, ie, they @@ -132,8 +132,8 @@ static RelMapFile pending_local_updates; /* non-export function prototypes */ -static void apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode, - bool add_okay); +static void apply_map_update(RelMapFile *map, Oid relationId, + RelFileNumber filenumber, bool add_okay); static void merge_map_updates(RelMapFile *map, const RelMapFile *updates, bool add_okay); static void load_relmap_file(bool shared, bool lock_held); @@ -146,19 +146,20 @@ static void perform_relmap_update(bool shared, const RelMapFile *updates); /* - * RelationMapOidToFilenode + * RelationMapOidToFilenumber * - * The raison d' etre ... given a relation OID, look up its filenode. + * The raison d' etre ... given a relation OID, look up its filenumber. * * Although shared and local relation OIDs should never overlap, the caller * always knows which we need --- so pass that information to avoid useless * searching. * - * Returns InvalidOid if the OID is not known (which should never happen, - * but the caller is in a better position to report a meaningful error). + * Returns InvalidRelFileNumber if the OID is not known (which should never + * happen, but the caller is in a better position to report a meaningful + * error). */ -Oid -RelationMapOidToFilenode(Oid relationId, bool shared) +RelFileNumber +RelationMapOidToFilenumber(Oid relationId, bool shared) { const RelMapFile *map; int32 i; @@ -170,13 +171,13 @@ RelationMapOidToFilenode(Oid relationId, bool shared) for (i = 0; i < map->num_mappings; i++) { if (relationId == map->mappings[i].mapoid) - return map->mappings[i].mapfilenode; + return map->mappings[i].mapfilenumber; } map = &shared_map; for (i = 0; i < map->num_mappings; i++) { if (relationId == map->mappings[i].mapoid) - return map->mappings[i].mapfilenode; + return map->mappings[i].mapfilenumber; } } else @@ -185,33 +186,33 @@ RelationMapOidToFilenode(Oid relationId, bool shared) for (i = 0; i < map->num_mappings; i++) { if (relationId == map->mappings[i].mapoid) - return map->mappings[i].mapfilenode; + return map->mappings[i].mapfilenumber; } map = &local_map; for (i = 0; i < map->num_mappings; i++) { if (relationId == map->mappings[i].mapoid) - return map->mappings[i].mapfilenode; + return map->mappings[i].mapfilenumber; } } - return InvalidOid; + return InvalidRelFileNumber; } /* - * RelationMapFilenodeToOid + * RelationMapFilenumberToOid * * Do the reverse of the normal direction of mapping done in - * RelationMapOidToFilenode. + * RelationMapOidToFilenumber. * * This is not supposed to be used during normal running but rather for * information purposes when looking at the filesystem or xlog. * * Returns InvalidOid if the OID is not known; this can easily happen if the - * relfilenode doesn't pertain to a mapped relation. + * relfilenumber doesn't pertain to a mapped relation. */ Oid -RelationMapFilenodeToOid(Oid filenode, bool shared) +RelationMapFilenumberToOid(RelFileNumber filenumber, bool shared) { const RelMapFile *map; int32 i; @@ -222,13 +223,13 @@ RelationMapFilenodeToOid(Oid filenode, bool shared) map = &active_shared_updates; for (i = 0; i < map->num_mappings; i++) { - if (filenode == map->mappings[i].mapfilenode) + if (filenumber == map->mappings[i].mapfilenumber) return map->mappings[i].mapoid; } map = &shared_map; for (i = 0; i < map->num_mappings; i++) { - if (filenode == map->mappings[i].mapfilenode) + if (filenumber == map->mappings[i].mapfilenumber) return map->mappings[i].mapoid; } } @@ -237,13 +238,13 @@ RelationMapFilenodeToOid(Oid filenode, bool shared) map = &active_local_updates; for (i = 0; i < map->num_mappings; i++) { - if (filenode == map->mappings[i].mapfilenode) + if (filenumber == map->mappings[i].mapfilenumber) return map->mappings[i].mapoid; } map = &local_map; for (i = 0; i < map->num_mappings; i++) { - if (filenode == map->mappings[i].mapfilenode) + if (filenumber == map->mappings[i].mapfilenumber) return map->mappings[i].mapoid; } } @@ -252,13 +253,13 @@ RelationMapFilenodeToOid(Oid filenode, bool shared) } /* - * RelationMapOidToFilenodeForDatabase + * RelationMapOidToFilenumberForDatabase * - * Like RelationMapOidToFilenode, but reads the mapping from the indicated + * Like RelationMapOidToFilenumber, but reads the mapping from the indicated * path instead of using the one for the current database. */ -Oid -RelationMapOidToFilenodeForDatabase(char *dbpath, Oid relationId) +RelFileNumber +RelationMapOidToFilenumberForDatabase(char *dbpath, Oid relationId) { RelMapFile map; int i; @@ -270,10 +271,10 @@ RelationMapOidToFilenodeForDatabase(char *dbpath, Oid relationId) for (i = 0; i < map.num_mappings; i++) { if (relationId == map.mappings[i].mapoid) - return map.mappings[i].mapfilenode; + return map.mappings[i].mapfilenumber; } - return InvalidOid; + return InvalidRelFileNumber; } /* @@ -311,13 +312,13 @@ RelationMapCopy(Oid dbid, Oid tsid, char *srcdbpath, char *dstdbpath) /* * RelationMapUpdateMap * - * Install a new relfilenode mapping for the specified relation. + * Install a new relfilenumber mapping for the specified relation. * * If immediate is true (or we're bootstrapping), the mapping is activated * immediately. Otherwise it is made pending until CommandCounterIncrement. */ void -RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared, +RelationMapUpdateMap(Oid relationId, RelFileNumber fileNumber, bool shared, bool immediate) { RelMapFile *map; @@ -362,7 +363,7 @@ RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared, map = &pending_local_updates; } } - apply_map_update(map, relationId, fileNode, true); + apply_map_update(map, relationId, fileNumber, true); } /* @@ -375,7 +376,8 @@ RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared, * add_okay = false to draw an error if not. */ static void -apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode, bool add_okay) +apply_map_update(RelMapFile *map, Oid relationId, RelFileNumber fileNumber, + bool add_okay) { int32 i; @@ -384,7 +386,7 @@ apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode, bool add_okay) { if (relationId == map->mappings[i].mapoid) { - map->mappings[i].mapfilenode = fileNode; + map->mappings[i].mapfilenumber = fileNumber; return; } } @@ -396,7 +398,7 @@ apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode, bool add_okay) if (map->num_mappings >= MAX_MAPPINGS) elog(ERROR, "ran out of space in relation map"); map->mappings[map->num_mappings].mapoid = relationId; - map->mappings[map->num_mappings].mapfilenode = fileNode; + map->mappings[map->num_mappings].mapfilenumber = fileNumber; map->num_mappings++; } @@ -415,7 +417,7 @@ merge_map_updates(RelMapFile *map, const RelMapFile *updates, bool add_okay) { apply_map_update(map, updates->mappings[i].mapoid, - updates->mappings[i].mapfilenode, + updates->mappings[i].mapfilenumber, add_okay); } } @@ -983,12 +985,12 @@ write_relmap_file(RelMapFile *newmap, bool write_wal, bool send_sinval, for (i = 0; i < newmap->num_mappings; i++) { - RelFileNode rnode; + RelFileLocator rlocator; - rnode.spcNode = tsid; - rnode.dbNode = dbid; - rnode.relNode = newmap->mappings[i].mapfilenode; - RelationPreserveStorage(rnode, false); + rlocator.spcOid = tsid; + rlocator.dbOid = dbid; + rlocator.relNumber = newmap->mappings[i].mapfilenumber; + RelationPreserveStorage(rlocator, false); } } |