diff options
| author | Robert Haas | 2022-07-06 15:39:09 +0000 |
|---|---|---|
| committer | Robert Haas | 2022-07-06 15:39:09 +0000 |
| commit | b0a55e43299c4ea2a9a8c757f9c26352407d0ccc (patch) | |
| tree | 2c22c2965f9976ae4469595cd28df13db6b943c2 /src/include | |
| parent | 7775c748db1257523ecbed1060dadb608bdff6de (diff) | |
Change internal RelFileNode references to RelFileNumber or RelFileLocator.
We have been using the term RelFileNode to refer to either (1) the
integer that is used to name the sequence of files for a certain relation
within the directory set aside for that tablespace/database combination;
or (2) that value plus the OIDs of the tablespace and database; or
occasionally (3) the whole series of files created for a relation
based on those values. Using the same name for more than one thing is
confusing.
Replace RelFileNode with RelFileNumber when we're talking about just the
single number, i.e. (1) from above, and with RelFileLocator when we're
talking about all the things that are needed to locate a relation's files
on disk, i.e. (2) from above. In the places where we refer to (3) as
a relfilenode, instead refer to "relation storage".
Since there is a ton of SQL code in the world that knows about
pg_class.relfilenode, don't change the name of that column, or of other
SQL-facing things that derive their name from it.
On the other hand, do adjust closely-related internal terminology. For
example, the structure member names dbNode and spcNode appear to be
derived from the fact that the structure itself was called RelFileNode,
so change those to dbOid and spcOid. Likewise, various variables with
names like rnode and relnode get renamed appropriately, according to
how they're being used in context.
Hopefully, this is clearer than before. It is also preparation for
future patches that intend to widen the relfilenumber fields from its
current width of 32 bits. Variables that store a relfilenumber are now
declared as type RelFileNumber rather than type Oid; right now, these
are the same, but that can now more easily be changed.
Dilip Kumar, per an idea from me. Reviewed also by Andres Freund.
I fixed some whitespace issues, changed a couple of words in a
comment, and made one other minor correction.
Discussion: http://postgr.es/m/CA+TgmoamOtXbVAQf9hWFzonUo6bhhjS6toZQd7HZ-pmojtAmag@mail.gmail.com
Discussion: http://postgr.es/m/CA+Tgmobp7+7kmi4gkq7Y+4AM9fTvL+O1oQ4-5gFTT+6Ng-dQ=g@mail.gmail.com
Discussion: http://postgr.es/m/CAFiTN-vTe79M8uDH1yprOU64MNFE+R3ODRuA+JWf27JbhY4hJw@mail.gmail.com
Diffstat (limited to 'src/include')
42 files changed, 305 insertions, 290 deletions
diff --git a/src/include/access/brin_xlog.h b/src/include/access/brin_xlog.h index 95bfc7e857..012a9afdf4 100644 --- a/src/include/access/brin_xlog.h +++ b/src/include/access/brin_xlog.h @@ -18,7 +18,7 @@ #include "lib/stringinfo.h" #include "storage/bufpage.h" #include "storage/itemptr.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "utils/relcache.h" diff --git a/src/include/access/ginxlog.h b/src/include/access/ginxlog.h index 21de389d79..7f985039bb 100644 --- a/src/include/access/ginxlog.h +++ b/src/include/access/ginxlog.h @@ -110,7 +110,7 @@ typedef struct typedef struct ginxlogSplit { - RelFileNode node; + RelFileLocator locator; BlockNumber rrlink; /* right link, or root's blocknumber if root * split */ BlockNumber leftChildBlkno; /* valid on a non-leaf split */ @@ -167,7 +167,7 @@ typedef struct ginxlogDeletePage */ typedef struct ginxlogUpdateMeta { - RelFileNode node; + RelFileLocator locator; GinMetaPageData metadata; BlockNumber prevTail; BlockNumber newRightlink; diff --git a/src/include/access/gistxlog.h b/src/include/access/gistxlog.h index 4537e67eba..9bbe4c2622 100644 --- a/src/include/access/gistxlog.h +++ b/src/include/access/gistxlog.h @@ -97,7 +97,7 @@ typedef struct gistxlogPageDelete */ typedef struct gistxlogPageReuse { - RelFileNode node; + RelFileLocator locator; BlockNumber block; FullTransactionId latestRemovedFullXid; } gistxlogPageReuse; diff --git a/src/include/access/heapam_xlog.h b/src/include/access/heapam_xlog.h index 2d8a7f6270..1705e736be 100644 --- a/src/include/access/heapam_xlog.h +++ b/src/include/access/heapam_xlog.h @@ -19,7 +19,7 @@ #include "lib/stringinfo.h" #include "storage/buf.h" #include "storage/bufpage.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "utils/relcache.h" @@ -370,9 +370,9 @@ typedef struct xl_heap_new_cid CommandId combocid; /* just for debugging */ /* - * Store the relfilenode/ctid pair to facilitate lookups. + * Store the relfilelocator/ctid pair to facilitate lookups. */ - RelFileNode target_node; + RelFileLocator target_locator; ItemPointerData target_tid; } xl_heap_new_cid; @@ -415,7 +415,7 @@ extern bool heap_prepare_freeze_tuple(HeapTupleHeader tuple, MultiXactId *relminmxid_out); extern void heap_execute_freeze_tuple(HeapTupleHeader tuple, xl_heap_freeze_tuple *xlrec_tp); -extern XLogRecPtr log_heap_visible(RelFileNode rnode, Buffer heap_buffer, +extern XLogRecPtr log_heap_visible(RelFileLocator rlocator, Buffer heap_buffer, Buffer vm_buffer, TransactionId cutoff_xid, uint8 flags); #endif /* HEAPAM_XLOG_H */ diff --git a/src/include/access/nbtxlog.h b/src/include/access/nbtxlog.h index de362d3cb9..d79489efe4 100644 --- a/src/include/access/nbtxlog.h +++ b/src/include/access/nbtxlog.h @@ -180,12 +180,12 @@ typedef struct xl_btree_dedup * This is what we need to know about page reuse within btree. This record * only exists to generate a conflict point for Hot Standby. * - * Note that we must include a RelFileNode in the record because we don't + * Note that we must include a RelFileLocator in the record because we don't * actually register the buffer with the record. */ typedef struct xl_btree_reuse_page { - RelFileNode node; + RelFileLocator locator; BlockNumber block; FullTransactionId latestRemovedFullXid; } xl_btree_reuse_page; diff --git a/src/include/access/rewriteheap.h b/src/include/access/rewriteheap.h index 3e27790b3f..353cbb2924 100644 --- a/src/include/access/rewriteheap.h +++ b/src/include/access/rewriteheap.h @@ -15,7 +15,7 @@ #include "access/htup.h" #include "storage/itemptr.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "utils/relcache.h" /* struct definition is private to rewriteheap.c */ @@ -34,8 +34,8 @@ extern bool rewrite_heap_dead_tuple(RewriteState state, HeapTuple oldTuple); */ typedef struct LogicalRewriteMappingData { - RelFileNode old_node; - RelFileNode new_node; + RelFileLocator old_locator; + RelFileLocator new_locator; ItemPointerData old_tid; ItemPointerData new_tid; } LogicalRewriteMappingData; diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index fe869c6c18..9df4e7cb0a 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -560,32 +560,32 @@ typedef struct TableAmRoutine */ /* - * This callback needs to create a new relation filenode for `rel`, with + * This callback needs to create new relation storage for `rel`, with * appropriate durability behaviour for `persistence`. * * Note that only the subset of the relcache filled by * RelationBuildLocalRelation() can be relied upon and that the relation's * catalog entries will either not yet exist (new relation), or will still - * reference the old relfilenode. + * reference the old relfilelocator. * * As output *freezeXid, *minmulti must be set to the values appropriate * for pg_class.{relfrozenxid, relminmxid}. For AMs that don't need those * fields to be filled they can be set to InvalidTransactionId and * InvalidMultiXactId, respectively. * - * See also table_relation_set_new_filenode(). + * See also table_relation_set_new_filelocator(). */ - void (*relation_set_new_filenode) (Relation rel, - const RelFileNode *newrnode, - char persistence, - TransactionId *freezeXid, - MultiXactId *minmulti); + void (*relation_set_new_filelocator) (Relation rel, + const RelFileLocator *newrlocator, + char persistence, + TransactionId *freezeXid, + MultiXactId *minmulti); /* * This callback needs to remove all contents from `rel`'s current - * relfilenode. No provisions for transactional behaviour need to be made. - * Often this can be implemented by truncating the underlying storage to - * its minimal size. + * relfilelocator. No provisions for transactional behaviour need to be + * made. Often this can be implemented by truncating the underlying + * storage to its minimal size. * * See also table_relation_nontransactional_truncate(). */ @@ -598,7 +598,7 @@ typedef struct TableAmRoutine * storage, unless it contains references to the tablespace internally. */ void (*relation_copy_data) (Relation rel, - const RelFileNode *newrnode); + const RelFileLocator *newrlocator); /* See table_relation_copy_for_cluster() */ void (*relation_copy_for_cluster) (Relation NewTable, @@ -1348,7 +1348,7 @@ table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate) * RelationGetBufferForTuple. See that method for more information. * * TABLE_INSERT_FROZEN should only be specified for inserts into - * relfilenodes created during the current subtransaction and when + * relation storage created during the current subtransaction and when * there are no prior snapshots or pre-existing portals open. * This causes rows to be frozen, which is an MVCC violation and * requires explicit options chosen by user. @@ -1577,33 +1577,34 @@ table_finish_bulk_insert(Relation rel, int options) */ /* - * Create storage for `rel` in `newrnode`, with persistence set to + * Create storage for `rel` in `newrlocator`, with persistence set to * `persistence`. * * This is used both during relation creation and various DDL operations to - * create a new relfilenode that can be filled from scratch. When creating - * new storage for an existing relfilenode, this should be called before the + * create new rel storage that can be filled from scratch. When creating + * new storage for an existing relfilelocator, this should be called before the * relcache entry has been updated. * * *freezeXid, *minmulti are set to the xid / multixact horizon for the table * that pg_class.{relfrozenxid, relminmxid} have to be set to. */ static inline void -table_relation_set_new_filenode(Relation rel, - const RelFileNode *newrnode, - char persistence, - TransactionId *freezeXid, - MultiXactId *minmulti) +table_relation_set_new_filelocator(Relation rel, + const RelFileLocator *newrlocator, + char persistence, + TransactionId *freezeXid, + MultiXactId *minmulti) { - rel->rd_tableam->relation_set_new_filenode(rel, newrnode, persistence, - freezeXid, minmulti); + rel->rd_tableam->relation_set_new_filelocator(rel, newrlocator, + persistence, freezeXid, + minmulti); } /* * Remove all table contents from `rel`, in a non-transactional manner. * Non-transactional meaning that there's no need to support rollbacks. This - * commonly only is used to perform truncations for relfilenodes created in the - * current transaction. + * commonly only is used to perform truncations for relation storage created in + * the current transaction. */ static inline void table_relation_nontransactional_truncate(Relation rel) @@ -1612,15 +1613,15 @@ table_relation_nontransactional_truncate(Relation rel) } /* - * Copy data from `rel` into the new relfilenode `newrnode`. The new - * relfilenode may not have storage associated before this function is + * Copy data from `rel` into the new relfilelocator `newrlocator`. The new + * relfilelocator may not have storage associated before this function is * called. This is only supposed to be used for low level operations like * changing a relation's tablespace. */ static inline void -table_relation_copy_data(Relation rel, const RelFileNode *newrnode) +table_relation_copy_data(Relation rel, const RelFileLocator *newrlocator) { - rel->rd_tableam->relation_copy_data(rel, newrnode); + rel->rd_tableam->relation_copy_data(rel, newrlocator); } /* diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 4794941df3..7d2b35213d 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -19,7 +19,7 @@ #include "datatype/timestamp.h" #include "lib/stringinfo.h" #include "nodes/pg_list.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "storage/sinval.h" /* @@ -174,7 +174,7 @@ typedef struct SavedTransactionCharacteristics */ #define XACT_XINFO_HAS_DBINFO (1U << 0) #define XACT_XINFO_HAS_SUBXACTS (1U << 1) -#define XACT_XINFO_HAS_RELFILENODES (1U << 2) +#define XACT_XINFO_HAS_RELFILELOCATORS (1U << 2) #define XACT_XINFO_HAS_INVALS (1U << 3) #define XACT_XINFO_HAS_TWOPHASE (1U << 4) #define XACT_XINFO_HAS_ORIGIN (1U << 5) @@ -252,12 +252,12 @@ typedef struct xl_xact_subxacts } xl_xact_subxacts; #define MinSizeOfXactSubxacts offsetof(xl_xact_subxacts, subxacts) -typedef struct xl_xact_relfilenodes +typedef struct xl_xact_relfilelocators { int nrels; /* number of relations */ - RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]; -} xl_xact_relfilenodes; -#define MinSizeOfXactRelfilenodes offsetof(xl_xact_relfilenodes, xnodes) + RelFileLocator xlocators[FLEXIBLE_ARRAY_MEMBER]; +} xl_xact_relfilelocators; +#define MinSizeOfXactRelfileLocators offsetof(xl_xact_relfilelocators, xlocators) /* * A transactionally dropped statistics entry. @@ -305,7 +305,7 @@ typedef struct xl_xact_commit /* xl_xact_xinfo follows if XLOG_XACT_HAS_INFO */ /* xl_xact_dbinfo follows if XINFO_HAS_DBINFO */ /* xl_xact_subxacts follows if XINFO_HAS_SUBXACT */ - /* xl_xact_relfilenodes follows if XINFO_HAS_RELFILENODES */ + /* xl_xact_relfilelocators follows if XINFO_HAS_RELFILELOCATORS */ /* xl_xact_stats_items follows if XINFO_HAS_DROPPED_STATS */ /* xl_xact_invals follows if XINFO_HAS_INVALS */ /* xl_xact_twophase follows if XINFO_HAS_TWOPHASE */ @@ -321,7 +321,7 @@ typedef struct xl_xact_abort /* xl_xact_xinfo follows if XLOG_XACT_HAS_INFO */ /* xl_xact_dbinfo follows if XINFO_HAS_DBINFO */ /* xl_xact_subxacts follows if XINFO_HAS_SUBXACT */ - /* xl_xact_relfilenodes follows if XINFO_HAS_RELFILENODES */ + /* xl_xact_relfilelocators follows if XINFO_HAS_RELFILELOCATORS */ /* xl_xact_stats_items follows if XINFO_HAS_DROPPED_STATS */ /* No invalidation messages needed. */ /* xl_xact_twophase follows if XINFO_HAS_TWOPHASE */ @@ -367,7 +367,7 @@ typedef struct xl_xact_parsed_commit TransactionId *subxacts; int nrels; - RelFileNode *xnodes; + RelFileLocator *xlocators; int nstats; xl_xact_stats_item *stats; @@ -378,7 +378,7 @@ typedef struct xl_xact_parsed_commit TransactionId twophase_xid; /* only for 2PC */ char twophase_gid[GIDSIZE]; /* only for 2PC */ int nabortrels; /* only for 2PC */ - RelFileNode *abortnodes; /* only for 2PC */ + RelFileLocator *abortlocators; /* only for 2PC */ int nabortstats; /* only for 2PC */ xl_xact_stats_item *abortstats; /* only for 2PC */ @@ -400,7 +400,7 @@ typedef struct xl_xact_parsed_abort TransactionId *subxacts; int nrels; - RelFileNode *xnodes; + RelFileLocator *xlocators; int nstats; xl_xact_stats_item *stats; @@ -483,7 +483,7 @@ extern int xactGetCommittedChildren(TransactionId **ptr); extern XLogRecPtr XactLogCommitRecord(TimestampTz commit_time, int nsubxacts, TransactionId *subxacts, - int nrels, RelFileNode *rels, + int nrels, RelFileLocator *rels, int nstats, xl_xact_stats_item *stats, int nmsgs, SharedInvalidationMessage *msgs, @@ -494,7 +494,7 @@ extern XLogRecPtr XactLogCommitRecord(TimestampTz commit_time, extern XLogRecPtr XactLogAbortRecord(TimestampTz abort_time, int nsubxacts, TransactionId *subxacts, - int nrels, RelFileNode *rels, + int nrels, RelFileLocator *rels, int nstats, xl_xact_stats_item *stats, int xactflags, TransactionId twophase_xid, diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h index fae0bef8f5..3524c396dc 100644 --- a/src/include/access/xlog_internal.h +++ b/src/include/access/xlog_internal.h @@ -25,7 +25,7 @@ #include "lib/stringinfo.h" #include "pgtime.h" #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" /* diff --git a/src/include/access/xloginsert.h b/src/include/access/xloginsert.h index 5fc340c434..c04f77b173 100644 --- a/src/include/access/xloginsert.h +++ b/src/include/access/xloginsert.h @@ -15,7 +15,7 @@ #include "access/xlogdefs.h" #include "storage/block.h" #include "storage/buf.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "utils/relcache.h" /* @@ -45,16 +45,16 @@ extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info); extern void XLogEnsureRecordSpace(int max_block_id, int ndatas); extern void XLogRegisterData(char *data, int len); extern void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags); -extern void XLogRegisterBlock(uint8 block_id, RelFileNode *rnode, +extern void XLogRegisterBlock(uint8 block_id, RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blknum, char *page, uint8 flags); extern void XLogRegisterBufData(uint8 block_id, char *data, int len); extern void XLogResetInsertion(void); extern bool XLogCheckBufferNeedsBackup(Buffer buffer); -extern XLogRecPtr log_newpage(RelFileNode *rnode, ForkNumber forkNum, +extern XLogRecPtr log_newpage(RelFileLocator *rlocator, ForkNumber forkNum, BlockNumber blk, char *page, bool page_std); -extern void log_newpages(RelFileNode *rnode, ForkNumber forkNum, int num_pages, +extern void log_newpages(RelFileLocator *rlocator, ForkNumber forkNum, int num_pages, BlockNumber *blknos, char **pages, bool page_std); extern XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std); extern void log_newpage_range(Relation rel, ForkNumber forkNum, diff --git a/src/include/access/xlogreader.h b/src/include/access/xlogreader.h index e73ea4a840..5395f155aa 100644 --- a/src/include/access/xlogreader.h +++ b/src/include/access/xlogreader.h @@ -122,7 +122,7 @@ typedef struct bool in_use; /* Identify the block this refers to */ - RelFileNode rnode; + RelFileLocator rlocator; ForkNumber forknum; BlockNumber blkno; @@ -430,10 +430,10 @@ extern FullTransactionId XLogRecGetFullXid(XLogReaderState *record); extern bool RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page); extern char *XLogRecGetBlockData(XLogReaderState *record, uint8 block_id, Size *len); extern void XLogRecGetBlockTag(XLogReaderState *record, uint8 block_id, - RelFileNode *rnode, ForkNumber *forknum, + RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum); extern bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, - RelFileNode *rnode, ForkNumber *forknum, + RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer); diff --git a/src/include/access/xlogrecord.h b/src/include/access/xlogrecord.h index 052ac6817a..835151ec92 100644 --- a/src/include/access/xlogrecord.h +++ b/src/include/access/xlogrecord.h @@ -15,7 +15,7 @@ #include "access/xlogdefs.h" #include "port/pg_crc32c.h" #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" /* * The overall layout of an XLOG record is: @@ -97,7 +97,7 @@ typedef struct XLogRecordBlockHeader * image) */ /* If BKPBLOCK_HAS_IMAGE, an XLogRecordBlockImageHeader struct follows */ - /* If BKPBLOCK_SAME_REL is not set, a RelFileNode follows */ + /* If BKPBLOCK_SAME_REL is not set, a RelFileLocator follows */ /* BlockNumber follows */ } XLogRecordBlockHeader; @@ -175,7 +175,7 @@ typedef struct XLogRecordBlockCompressHeader (SizeOfXLogRecordBlockHeader + \ SizeOfXLogRecordBlockImageHeader + \ SizeOfXLogRecordBlockCompressHeader + \ - sizeof(RelFileNode) + \ + sizeof(RelFileLocator) + \ sizeof(BlockNumber)) /* @@ -187,7 +187,8 @@ typedef struct XLogRecordBlockCompressHeader #define BKPBLOCK_HAS_IMAGE 0x10 /* block data is an XLogRecordBlockImage */ #define BKPBLOCK_HAS_DATA 0x20 #define BKPBLOCK_WILL_INIT 0x40 /* redo will re-init the page */ -#define BKPBLOCK_SAME_REL 0x80 /* RelFileNode omitted, same as previous */ +#define BKPBLOCK_SAME_REL 0x80 /* RelFileLocator omitted, same as + * previous */ /* * XLogRecordDataHeaderShort/Long are used for the "main data" portion of diff --git a/src/include/access/xlogutils.h b/src/include/access/xlogutils.h index c9d0b75a01..ef182977bf 100644 --- a/src/include/access/xlogutils.h +++ b/src/include/access/xlogutils.h @@ -60,9 +60,9 @@ extern PGDLLIMPORT HotStandbyState standbyState; extern bool XLogHaveInvalidPages(void); extern void XLogCheckInvalidPages(void); -extern void XLogDropRelation(RelFileNode rnode, ForkNumber forknum); +extern void XLogDropRelation(RelFileLocator rlocator, ForkNumber forknum); extern void XLogDropDatabase(Oid dbid); -extern void XLogTruncateRelation(RelFileNode rnode, ForkNumber forkNum, +extern void XLogTruncateRelation(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber nblocks); /* Result codes for XLogReadBufferForRedo[Extended] */ @@ -89,11 +89,11 @@ extern XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record, ReadBufferMode mode, bool get_cleanup_lock, Buffer *buf); -extern Buffer XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, +extern Buffer XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode, Buffer recent_buffer); -extern Relation CreateFakeRelcacheEntry(RelFileNode rnode); +extern Relation CreateFakeRelcacheEntry(RelFileLocator rlocator); extern void FreeFakeRelcacheEntry(Relation fakerel); extern int read_local_xlog_page(XLogReaderState *state, diff --git a/src/include/catalog/binary_upgrade.h b/src/include/catalog/binary_upgrade.h index 0b6944b29c..fd934427ad 100644 --- a/src/include/catalog/binary_upgrade.h +++ b/src/include/catalog/binary_upgrade.h @@ -22,11 +22,11 @@ extern PGDLLIMPORT Oid binary_upgrade_next_mrng_pg_type_oid; extern PGDLLIMPORT Oid binary_upgrade_next_mrng_array_pg_type_oid; extern PGDLLIMPORT Oid binary_upgrade_next_heap_pg_class_oid; -extern PGDLLIMPORT Oid binary_upgrade_next_heap_pg_class_relfilenode; +extern PGDLLIMPORT RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber; extern PGDLLIMPORT Oid binary_upgrade_next_index_pg_class_oid; -extern PGDLLIMPORT Oid binary_upgrade_next_index_pg_class_relfilenode; +extern PGDLLIMPORT RelFileNumber binary_upgrade_next_index_pg_class_relfilenumber; extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_class_oid; -extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_class_relfilenode; +extern PGDLLIMPORT RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber; extern PGDLLIMPORT Oid binary_upgrade_next_pg_enum_oid; extern PGDLLIMPORT Oid binary_upgrade_next_pg_authid_oid; diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index 60c1215362..e1c85f9855 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -38,7 +38,8 @@ extern bool IsPinnedObject(Oid classId, Oid objectId); extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn); -extern Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, - char relpersistence); +extern RelFileNumber GetNewRelFileNumber(Oid reltablespace, + Relation pg_class, + char relpersistence); #endif /* CATALOG_H */ diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h index 07c5b88f0e..5774c46471 100644 --- a/src/include/catalog/heap.h +++ b/src/include/catalog/heap.h @@ -50,7 +50,7 @@ extern Relation heap_create(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, - Oid relfilenode, + RelFileNumber relfilenumber, Oid accessmtd, TupleDesc tupDesc, char relkind, diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index a1d6e3b645..1bdb00a521 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -71,7 +71,7 @@ extern Oid index_create(Relation heapRelation, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, - Oid relFileNode, + RelFileNumber relFileNumber, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h index 59f3404ac6..9964c312aa 100644 --- a/src/include/catalog/storage.h +++ b/src/include/catalog/storage.h @@ -15,23 +15,23 @@ #define STORAGE_H #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "storage/smgr.h" #include "utils/relcache.h" /* GUC variables */ extern PGDLLIMPORT int wal_skip_threshold; -extern SMgrRelation RelationCreateStorage(RelFileNode rnode, +extern SMgrRelation RelationCreateStorage(RelFileLocator rlocator, char relpersistence, bool register_delete); extern void RelationDropStorage(Relation rel); -extern void RelationPreserveStorage(RelFileNode rnode, bool atCommit); +extern void RelationPreserveStorage(RelFileLocator rlocator, bool atCommit); extern void RelationPreTruncate(Relation rel); extern void RelationTruncate(Relation rel, BlockNumber nblocks); extern void RelationCopyStorage(SMgrRelation src, SMgrRelation dst, ForkNumber forkNum, char relpersistence); -extern bool RelFileNodeSkippingWAL(RelFileNode rnode); +extern bool RelFileLocatorSkippingWAL(RelFileLocator rlocator); extern Size EstimatePendingSyncsSpace(void); extern void SerializePendingSyncs(Size maxSize, char *startAddress); extern void RestorePendingSyncs(char *startAddress); @@ -42,7 +42,7 @@ extern void RestorePendingSyncs(char *startAddress); */ extern void smgrDoPendingDeletes(bool isCommit); extern void smgrDoPendingSyncs(bool isCommit, bool isParallelWorker); -extern int smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr); +extern int smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr); extern void AtSubCommit_smgr(void); extern void AtSubAbort_smgr(void); extern void PostPrepare_smgr(void); diff --git a/src/include/catalog/storage_xlog.h b/src/include/catalog/storage_xlog.h index 622de22b03..44a5e2043b 100644 --- a/src/include/catalog/storage_xlog.h +++ b/src/include/catalog/storage_xlog.h @@ -17,7 +17,7 @@ #include "access/xlogreader.h" #include "lib/stringinfo.h" #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" /* * Declarations for smgr-related XLOG records @@ -32,7 +32,7 @@ typedef struct xl_smgr_create { - RelFileNode rnode; + RelFileLocator rlocator; ForkNumber forkNum; } xl_smgr_create; @@ -46,11 +46,11 @@ typedef struct xl_smgr_create typedef struct xl_smgr_truncate { BlockNumber blkno; - RelFileNode rnode; + RelFileLocator rlocator; int flags; } xl_smgr_truncate; -extern void log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum); +extern void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum); extern void smgr_redo(XLogReaderState *record); extern void smgr_desc(StringInfo buf, XLogReaderState *record); diff --git a/src/include/commands/sequence.h b/src/include/commands/sequence.h index 9da2300810..d38c0e2388 100644 --- a/src/include/commands/sequence.h +++ b/src/include/commands/sequence.h @@ -19,7 +19,7 @@ #include "lib/stringinfo.h" #include "nodes/parsenodes.h" #include "parser/parse_node.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" typedef struct FormData_pg_sequence_data @@ -47,7 +47,7 @@ typedef FormData_pg_sequence_data *Form_pg_sequence_data; typedef struct xl_seq_rec { - RelFileNode node; + RelFileLocator locator; /* SEQUENCE TUPLE DATA FOLLOWS AT THE END */ } xl_seq_rec; diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h index 5d4037f26e..0c48654b96 100644 --- a/src/include/commands/tablecmds.h +++ b/src/include/commands/tablecmds.h @@ -66,7 +66,7 @@ extern void SetRelationHasSubclass(Oid relationId, bool relhassubclass); extern bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId); extern void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, - Oid newRelFileNode); + RelFileNumber newRelFileNumber); extern ObjectAddress renameatt(RenameStmt *stmt); diff --git a/src/include/commands/tablespace.h b/src/include/commands/tablespace.h index 24b647332d..1f80907112 100644 --- a/src/include/commands/tablespace.h +++ b/src/include/commands/tablespace.h @@ -50,7 +50,7 @@ extern void DropTableSpace(DropTableSpaceStmt *stmt); extern ObjectAddress RenameTableSpace(const char *oldname, const char *newname); extern Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt); -extern void TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo); +extern void TablespaceCreateDbspace(Oid spcOid, Oid dbOid, bool isRedo); extern Oid GetDefaultTablespace(char relpersistence, bool partitioned); diff --git a/src/include/common/relpath.h b/src/include/common/relpath.h index 13849a3790..3ab713247f 100644 --- a/src/include/common/relpath.h +++ b/src/include/common/relpath.h @@ -64,27 +64,27 @@ extern int forkname_chars(const char *str, ForkNumber *fork); /* * Stuff for computing filesystem pathnames for relations. */ -extern char *GetDatabasePath(Oid dbNode, Oid spcNode); +extern char *GetDatabasePath(Oid dbOid, Oid spcOid); -extern char *GetRelationPath(Oid dbNode, Oid spcNode, Oid relNode, +extern char *GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int backendId, ForkNumber forkNumber); /* * Wrapper macros for GetRelationPath. Beware of multiple - * evaluation of the RelFileNode or RelFileNodeBackend argument! + * evaluation of the RelFileLocator or RelFileLocatorBackend argument! */ -/* First argument is a RelFileNode */ -#define relpathbackend(rnode, backend, forknum) \ - GetRelationPath((rnode).dbNode, (rnode).spcNode, (rnode).relNode, \ +/* First argument is a RelFileLocator */ +#define relpathbackend(rlocator, backend, forknum) \ + GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \ backend, forknum) -/* First argument is a RelFileNode */ -#define relpathperm(rnode, forknum) \ - relpathbackend(rnode, InvalidBackendId, forknum) +/* First argument is a RelFileLocator */ +#define relpathperm(rlocator, forknum) \ + relpathbackend(rlocator, InvalidBackendId, forknum) -/* First argument is a RelFileNodeBackend */ -#define relpath(rnode, forknum) \ - relpathbackend((rnode).node, (rnode).backend, forknum) +/* First argument is a RelFileLocatorBackend */ +#define relpath(rlocator, forknum) \ + relpathbackend((rlocator).locator, (rlocator).backend, forknum) #endif /* RELPATH_H */ diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index f93d866548..5f6d65b5c4 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3248,10 +3248,10 @@ typedef struct IndexStmt List *excludeOpNames; /* exclusion operator names, or NIL if none */ char *idxcomment; /* comment to apply to index, or NULL */ Oid indexOid; /* OID of an existing index, if any */ - Oid oldNode; /* relfilenode of existing storage, if any */ - SubTransactionId oldCreateSubid; /* rd_createSubid of oldNode */ - SubTransactionId oldFirstRelfilenodeSubid; /* rd_firstRelfilenodeSubid of - * oldNode */ + RelFileNumber oldNumber; /* relfilenumber of existing storage, if any */ + SubTransactionId oldCreateSubid; /* rd_createSubid of oldNumber */ + SubTransactionId oldFirstRelfilelocatorSubid; /* rd_firstRelfilelocatorSubid + * of oldNumber */ bool unique; /* is index unique? */ bool nulls_not_distinct; /* null treatment for UNIQUE constraints */ bool primary; /* is index a primary key? */ diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h index fdb61b7cf5..c9774fa010 100644 --- a/src/include/postgres_ext.h +++ b/src/include/postgres_ext.h @@ -46,6 +46,13 @@ typedef unsigned int Oid; /* Define a signed 64-bit integer type for use in client API declarations. */ typedef PG_INT64_TYPE pg_int64; +/* + * RelFileNumber data type identifies the specific relation file name. + */ +typedef Oid RelFileNumber; +#define InvalidRelFileNumber ((RelFileNumber) InvalidOid) +#define RelFileNumberIsValid(relnumber) \ + ((bool) ((relnumber) != InvalidRelFileNumber)) /* * Identifiers of error message fields. Kept here to keep common diff --git a/src/include/postmaster/bgwriter.h b/src/include/postmaster/bgwriter.h index 2511ef451e..b67fb1e52c 100644 --- a/src/include/postmaster/bgwriter.h +++ b/src/include/postmaster/bgwriter.h @@ -16,7 +16,7 @@ #define _BGWRITER_H #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "storage/smgr.h" #include "storage/sync.h" diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h index 4a01f877e5..d109d0baed 100644 --- a/src/include/replication/reorderbuffer.h +++ b/src/include/replication/reorderbuffer.h @@ -99,7 +99,7 @@ typedef struct ReorderBufferChange struct { /* relation that has been changed */ - RelFileNode relnode; + RelFileLocator rlocator; /* no previously reassembled toast chunks are necessary anymore */ bool clear_toast_afterwards; @@ -145,7 +145,7 @@ typedef struct ReorderBufferChange */ struct { - RelFileNode node; + RelFileLocator locator; ItemPointerData tid; CommandId cmin; CommandId cmax; @@ -657,7 +657,7 @@ extern void ReorderBufferAddSnapshot(ReorderBuffer *, TransactionId, XLogRecPtr extern void ReorderBufferAddNewCommandId(ReorderBuffer *, TransactionId, XLogRecPtr lsn, CommandId cid); extern void ReorderBufferAddNewTupleCids(ReorderBuffer *, TransactionId, XLogRecPtr lsn, - RelFileNode node, ItemPointerData pt, + RelFileLocator locator, ItemPointerData pt, CommandId cmin, CommandId cmax, CommandId combocid); extern void ReorderBufferAddInvalidations(ReorderBuffer *, TransactionId, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs); diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index a17e7b28a5..aded5e8f7e 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -90,30 +90,30 @@ */ typedef struct buftag { - RelFileNode rnode; /* physical relation identifier */ + RelFileLocator rlocator; /* physical relation identifier */ ForkNumber forkNum; BlockNumber blockNum; /* blknum relative to begin of reln */ } BufferTag; #define CLEAR_BUFFERTAG(a) \ ( \ - (a).rnode.spcNode = InvalidOid, \ - (a).rnode.dbNode = InvalidOid, \ - (a).rnode.relNode = InvalidOid, \ + (a).rlocator.spcOid = InvalidOid, \ + (a).rlocator.dbOid = InvalidOid, \ + (a).rlocator.relNumber = InvalidRelFileNumber, \ (a).forkNum = InvalidForkNumber, \ (a).blockNum = InvalidBlockNumber \ ) -#define INIT_BUFFERTAG(a,xx_rnode,xx_forkNum,xx_blockNum) \ +#define INIT_BUFFERTAG(a,xx_rlocator,xx_forkNum,xx_blockNum) \ ( \ - (a).rnode = (xx_rnode), \ + (a).rlocator = (xx_rlocator), \ (a).forkNum = (xx_forkNum), \ (a).blockNum = (xx_blockNum) \ ) #define BUFFERTAGS_EQUAL(a,b) \ ( \ - RelFileNodeEquals((a).rnode, (b).rnode) && \ + RelFileLocatorEquals((a).rlocator, (b).rlocator) && \ (a).blockNum == (b).blockNum && \ (a).forkNum == (b).forkNum \ ) @@ -292,7 +292,7 @@ extern PGDLLIMPORT BufferDesc *LocalBufferDescriptors; typedef struct CkptSortItem { Oid tsId; - Oid relNode; + RelFileNumber relNumber; ForkNumber forkNum; BlockNumber blockNum; int buf_id; @@ -337,9 +337,9 @@ extern PrefetchBufferResult PrefetchLocalBuffer(SMgrRelation smgr, extern BufferDesc *LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr); extern void MarkLocalBufferDirty(Buffer buffer); -extern void DropRelFileNodeLocalBuffers(RelFileNode rnode, ForkNumber forkNum, - BlockNumber firstDelBlock); -extern void DropRelFileNodeAllLocalBuffers(RelFileNode rnode); +extern void DropRelFileLocatorLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum, + BlockNumber firstDelBlock); +extern void DropRelFileLocatorAllLocalBuffers(RelFileLocator rlocator); extern void AtEOXact_LocalBuffers(bool isCommit); #endif /* BUFMGR_INTERNALS_H */ diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index 58391406f6..7bcfaac272 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -17,7 +17,7 @@ #include "storage/block.h" #include "storage/buf.h" #include "storage/bufpage.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -176,13 +176,13 @@ extern PrefetchBufferResult PrefetchSharedBuffer(struct SMgrRelationData *smgr_r BlockNumber blockNum); extern PrefetchBufferResult PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum); -extern bool ReadRecentBuffer(RelFileNode rnode, ForkNumber forkNum, +extern bool ReadRecentBuffer(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber blockNum, Buffer recent_buffer); extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum); extern Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy); -extern Buffer ReadBufferWithoutRelcache(RelFileNode rnode, +extern Buffer ReadBufferWithoutRelcache(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy, bool permanent); @@ -204,13 +204,15 @@ extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation, extern void FlushOneBuffer(Buffer buffer); extern void FlushRelationBuffers(Relation rel); extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels); -extern void CreateAndCopyRelationData(RelFileNode src_rnode, - RelFileNode dst_rnode, +extern void CreateAndCopyRelationData(RelFileLocator src_rlocator, + RelFileLocator dst_rlocator, bool permanent); extern void FlushDatabaseBuffers(Oid dbid); -extern void DropRelFileNodeBuffers(struct SMgrRelationData *smgr_reln, ForkNumber *forkNum, - int nforks, BlockNumber *firstDelBlock); -extern void DropRelFileNodesAllBuffers(struct SMgrRelationData **smgr_reln, int nnodes); +extern void DropRelFileLocatorBuffers(struct SMgrRelationData *smgr_reln, + ForkNumber *forkNum, + int nforks, BlockNumber *firstDelBlock); +extern void DropRelFileLocatorsAllBuffers(struct SMgrRelationData **smgr_reln, + int nlocators); extern void DropDatabaseBuffers(Oid dbid); #define RelationGetNumberOfBlocks(reln) \ @@ -223,7 +225,7 @@ extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer); extern void PrintPinnedBufs(void); #endif extern Size BufferShmemSize(void); -extern void BufferGetTag(Buffer buffer, RelFileNode *rnode, +extern void BufferGetTag(Buffer buffer, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum); extern void MarkBufferDirtyHint(Buffer buffer, bool buffer_std); diff --git a/src/include/storage/freespace.h b/src/include/storage/freespace.h index dcc40eb801..fcb080210d 100644 --- a/src/include/storage/freespace.h +++ b/src/include/storage/freespace.h @@ -15,7 +15,7 @@ #define FREESPACE_H_ #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "utils/relcache.h" /* prototypes for public functions in freespace.c */ @@ -27,7 +27,7 @@ extern BlockNumber RecordAndGetPageWithFreeSpace(Relation rel, Size spaceNeeded); extern void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail); -extern void XLogRecordPageWithFreeSpace(RelFileNode rnode, BlockNumber heapBlk, +extern void XLogRecordPageWithFreeSpace(RelFileLocator rlocator, BlockNumber heapBlk, Size spaceAvail); extern BlockNumber FreeSpaceMapPrepareTruncateRel(Relation rel, diff --git a/src/include/storage/md.h b/src/include/storage/md.h index ffffa40db7..10aa1b0109 100644 --- a/src/include/storage/md.h +++ b/src/include/storage/md.h @@ -15,7 +15,7 @@ #define MD_H #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "storage/smgr.h" #include "storage/sync.h" @@ -25,7 +25,7 @@ extern void mdopen(SMgrRelation reln); extern void mdclose(SMgrRelation reln, ForkNumber forknum); extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo); extern bool mdexists(SMgrRelation reln, ForkNumber forknum); -extern void mdunlink(RelFileNodeBackend rnode, ForkNumber forknum, bool isRedo); +extern void mdunlink(RelFileLocatorBackend rlocator, ForkNumber forknum, bool isRedo); extern void mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync); extern bool mdprefetch(SMgrRelation reln, ForkNumber forknum, @@ -42,7 +42,7 @@ extern void mdtruncate(SMgrRelation reln, ForkNumber forknum, extern void mdimmedsync(SMgrRelation reln, ForkNumber forknum); extern void ForgetDatabaseSyncRequests(Oid dbid); -extern void DropRelationFiles(RelFileNode *delrels, int ndelrels, bool isRedo); +extern void DropRelationFiles(RelFileLocator *delrels, int ndelrels, bool isRedo); /* md sync callbacks */ extern int mdsyncfiletag(const FileTag *ftag, char *path); diff --git a/src/include/storage/relfilelocator.h b/src/include/storage/relfilelocator.h new file mode 100644 index 0000000000..10f41f3abb --- /dev/null +++ b/src/include/storage/relfilelocator.h @@ -0,0 +1,99 @@ +/*------------------------------------------------------------------------- + * + * relfilelocator.h + * Physical access information for relations. + * + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/relfilelocator.h + * + *------------------------------------------------------------------------- + */ +#ifndef RELFILELOCATOR_H +#define RELFILELOCATOR_H + +#include "common/relpath.h" +#include "storage/backendid.h" + +/* + * RelFileLocator must provide all that we need to know to physically access + * a relation, with the exception of the backend ID, which can be provided + * separately. Note, however, that a "physical" relation is comprised of + * multiple files on the filesystem, as each fork is stored as a separate + * file, and each fork can be divided into multiple segments. See md.c. + * + * spcOid identifies the tablespace of the relation. It corresponds to + * pg_tablespace.oid. + * + * dbOid identifies the database of the relation. It is zero for + * "shared" relations (those common to all databases of a cluster). + * Nonzero dbOid values correspond to pg_database.oid. + * + * relNumber identifies the specific relation. relNumber corresponds to + * pg_class.relfilenode (NOT pg_class.oid, because we need to be able + * to assign new physical files to relations in some situations). + * Notice that relNumber is only unique within a database in a particular + * tablespace. + * + * Note: spcOid must be GLOBALTABLESPACE_OID if and only if dbOid is + * zero. We support shared relations only in the "global" tablespace. + * + * Note: in pg_class we allow reltablespace == 0 to denote that the + * relation is stored in its database's "default" tablespace (as + * identified by pg_database.dattablespace). However this shorthand + * is NOT allowed in RelFileLocator structs --- the real tablespace ID + * must be supplied when setting spcOid. + * + * Note: in pg_class, relfilenode can be zero to denote that the relation + * is a "mapped" relation, whose current true filenode number is available + * from relmapper.c. Again, this case is NOT allowed in RelFileLocators. + * + * Note: various places use RelFileLocator in hashtable keys. Therefore, + * there *must not* be any unused padding bytes in this struct. That + * should be safe as long as all the fields are of type Oid. + */ +typedef struct RelFileLocator +{ + Oid spcOid; /* tablespace */ + Oid dbOid; /* database */ + RelFileNumber relNumber; /* relation */ +} RelFileLocator; + +/* + * Augmenting a relfilelocator with the backend ID provides all the information + * we need to locate the physical storage. The backend ID is InvalidBackendId + * for regular relations (those accessible to more than one backend), or the + * owning backend's ID for backend-local relations. Backend-local relations + * are always transient and removed in case of a database crash; they are + * never WAL-logged or fsync'd. + */ +typedef struct RelFileLocatorBackend +{ + RelFileLocator locator; + BackendId backend; +} RelFileLocatorBackend; + +#define RelFileLocatorBackendIsTemp(rlocator) \ + ((rlocator).backend != InvalidBackendId) + +/* + * Note: RelFileLocatorEquals and RelFileLocatorBackendEquals compare relNumber + * first since that is most likely to be different in two unequal + * RelFileLocators. It is probably redundant to compare spcOid if the other + * fields are found equal, but do it anyway to be sure. Likewise for checking + * the backend ID in RelFileLocatorBackendEquals. + */ +#define RelFileLocatorEquals(locator1, locator2) \ + ((locator1).relNumber == (locator2).relNumber && \ + (locator1).dbOid == (locator2).dbOid && \ + (locator1).spcOid == (locator2).spcOid) + +#define RelFileLocatorBackendEquals(locator1, locator2) \ + ((locator1).locator.relNumber == (locator2).locator.relNumber && \ + (locator1).locator.dbOid == (locator2).locator.dbOid && \ + (locator1).backend == (locator2).backend && \ + (locator1).locator.spcOid == (locator2).locator.spcOid) + +#endif /* RELFILELOCATOR_H */ diff --git a/src/include/storage/relfilenode.h b/src/include/storage/relfilenode.h deleted file mode 100644 index 4fdc606cc3..0000000000 --- a/src/include/storage/relfilenode.h +++ /dev/null @@ -1,99 +0,0 @@ -/*------------------------------------------------------------------------- - * - * relfilenode.h - * Physical access information for relations. - * - * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * src/include/storage/relfilenode.h - * - *------------------------------------------------------------------------- - */ -#ifndef RELFILENODE_H -#define RELFILENODE_H - -#include "common/relpath.h" -#include "storage/backendid.h" - -/* - * RelFileNode must provide all that we need to know to physically access - * a relation, with the exception of the backend ID, which can be provided - * separately. Note, however, that a "physical" relation is comprised of - * multiple files on the filesystem, as each fork is stored as a separate - * file, and each fork can be divided into multiple segments. See md.c. - * - * spcNode identifies the tablespace of the relation. It corresponds to - * pg_tablespace.oid. - * - * dbNode identifies the database of the relation. It is zero for - * "shared" relations (those common to all databases of a cluster). - * Nonzero dbNode values correspond to pg_database.oid. - * - * relNode identifies the specific relation. relNode corresponds to - * pg_class.relfilenode (NOT pg_class.oid, because we need to be able - * to assign new physical files to relations in some situations). - * Notice that relNode is only unique within a database in a particular - * tablespace. - * - * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is - * zero. We support shared relations only in the "global" tablespace. - * - * Note: in pg_class we allow reltablespace == 0 to denote that the - * relation is stored in its database's "default" tablespace (as - * identified by pg_database.dattablespace). However this shorthand - * is NOT allowed in RelFileNode structs --- the real tablespace ID - * must be supplied when setting spcNode. - * - * Note: in pg_class, relfilenode can be zero to denote that the relation - * is a "mapped" relation, whose current true filenode number is available - * from relmapper.c. Again, this case is NOT allowed in RelFileNodes. - * - * Note: various places use RelFileNode in hashtable keys. Therefore, - * there *must not* be any unused padding bytes in this struct. That - * should be safe as long as all the fields are of type Oid. - */ -typedef struct RelFileNode -{ - Oid spcNode; /* tablespace */ - Oid dbNode; /* database */ - Oid relNode; /* relation */ -} RelFileNode; - -/* - * Augmenting a relfilenode with the backend ID provides all the information - * we need to locate the physical storage. The backend ID is InvalidBackendId - * for regular relations (those accessible to more than one backend), or the - * owning backend's ID for backend-local relations. Backend-local relations - * are always transient and removed in case of a database crash; they are - * never WAL-logged or fsync'd. - */ -typedef struct RelFileNodeBackend -{ - RelFileNode node; - BackendId backend; -} RelFileNodeBackend; - -#define RelFileNodeBackendIsTemp(rnode) \ - ((rnode).backend != InvalidBackendId) - -/* - * Note: RelFileNodeEquals and RelFileNodeBackendEquals compare relNode first - * since that is most likely to be different in two unequal RelFileNodes. It - * is probably redundant to compare spcNode if the other fields are found equal, - * but do it anyway to be sure. Likewise for checking the backend ID in - * RelFileNodeBackendEquals. - */ -#define RelFileNodeEquals(node1, node2) \ - ((node1).relNode == (node2).relNode && \ - (node1).dbNode == (node2).dbNode && \ - (node1).spcNode == (node2).spcNode) - -#define RelFileNodeBackendEquals(node1, node2) \ - ((node1).node.relNode == (node2).node.relNode && \ - (node1).node.dbNode == (node2).node.dbNode && \ - (node1).backend == (node2).backend && \ - (node1).node.spcNode == (node2).node.spcNode) - -#endif /* RELFILENODE_H */ diff --git a/src/include/storage/sinval.h b/src/include/storage/sinval.h index e7cd45658c..aca0347a3d 100644 --- a/src/include/storage/sinval.h +++ b/src/include/storage/sinval.h @@ -16,7 +16,7 @@ #include <signal.h> -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" /* * We support several types of shared-invalidation messages: @@ -90,7 +90,7 @@ typedef struct int8 id; /* type field --- must be first */ int8 backend_hi; /* high bits of backend ID, if temprel */ uint16 backend_lo; /* low bits of backend ID, if temprel */ - RelFileNode rnode; /* spcNode, dbNode, relNode */ + RelFileLocator rlocator; /* spcOid, dbOid, relNumber */ } SharedInvalSmgrMsg; #define SHAREDINVALRELMAP_ID (-4) diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h index 6b63c60fbd..a07715356b 100644 --- a/src/include/storage/smgr.h +++ b/src/include/storage/smgr.h @@ -16,7 +16,7 @@ #include "lib/ilist.h" #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" /* * smgr.c maintains a table of SMgrRelation objects, which are essentially @@ -38,8 +38,8 @@ */ typedef struct SMgrRelationData { - /* rnode is the hashtable lookup key, so it must be first! */ - RelFileNodeBackend smgr_rnode; /* relation physical identifier */ + /* rlocator is the hashtable lookup key, so it must be first! */ + RelFileLocatorBackend smgr_rlocator; /* relation physical identifier */ /* pointer to owning pointer, or NULL if none */ struct SMgrRelationData **smgr_owner; @@ -75,16 +75,16 @@ typedef struct SMgrRelationData typedef SMgrRelationData *SMgrRelation; #define SmgrIsTemp(smgr) \ - RelFileNodeBackendIsTemp((smgr)->smgr_rnode) + RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator) extern void smgrinit(void); -extern SMgrRelation smgropen(RelFileNode rnode, BackendId backend); +extern SMgrRelation smgropen(RelFileLocator rlocator, BackendId backend); extern bool smgrexists(SMgrRelation reln, ForkNumber forknum); extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln); extern void smgrclearowner(SMgrRelation *owner, SMgrRelation reln); extern void smgrclose(SMgrRelation reln); extern void smgrcloseall(void); -extern void smgrclosenode(RelFileNodeBackend rnode); +extern void smgrcloserellocator(RelFileLocatorBackend rlocator); extern void smgrrelease(SMgrRelation reln); extern void smgrreleaseall(void); extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo); diff --git a/src/include/storage/standby.h b/src/include/storage/standby.h index 6a7763264b..dacef92f44 100644 --- a/src/include/storage/standby.h +++ b/src/include/storage/standby.h @@ -17,7 +17,7 @@ #include "datatype/timestamp.h" #include "storage/lock.h" #include "storage/procsignal.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "storage/standbydefs.h" /* User-settable GUC parameters */ @@ -30,9 +30,9 @@ extern void InitRecoveryTransactionEnvironment(void); extern void ShutdownRecoveryTransactionEnvironment(void); extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, - RelFileNode node); + RelFileLocator locator); extern void ResolveRecoveryConflictWithSnapshotFullXid(FullTransactionId latestRemovedFullXid, - RelFileNode node); + RelFileLocator locator); extern void ResolveRecoveryConflictWithTablespace(Oid tsid); extern void ResolveRecoveryConflictWithDatabase(Oid dbid); diff --git a/src/include/storage/sync.h b/src/include/storage/sync.h index 9737e1eb67..049af878de 100644 --- a/src/include/storage/sync.h +++ b/src/include/storage/sync.h @@ -13,7 +13,7 @@ #ifndef SYNC_H #define SYNC_H -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" /* * Type of sync request. These are used to manage the set of pending @@ -51,7 +51,7 @@ typedef struct FileTag { int16 handler; /* SyncRequestHandler value, saving space */ int16 forknum; /* ForkNumber, saving space */ - RelFileNode rnode; + RelFileLocator rlocator; uint32 segno; } FileTag; diff --git a/src/include/utils/inval.h b/src/include/utils/inval.h index 0e0323b91a..23748b72ca 100644 --- a/src/include/utils/inval.h +++ b/src/include/utils/inval.h @@ -15,7 +15,7 @@ #define INVAL_H #include "access/htup.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "utils/relcache.h" extern PGDLLIMPORT int debug_discard_caches; @@ -48,7 +48,7 @@ extern void CacheInvalidateRelcacheByTuple(HeapTuple classTuple); extern void CacheInvalidateRelcacheByRelid(Oid relid); -extern void CacheInvalidateSmgr(RelFileNodeBackend rnode); +extern void CacheInvalidateSmgr(RelFileLocatorBackend rlocator); extern void CacheInvalidateRelmap(Oid databaseId); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 1896a9a06d..8231fba9a3 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -23,7 +23,7 @@ #include "partitioning/partdefs.h" #include "rewrite/prs2lock.h" #include "storage/block.h" -#include "storage/relfilenode.h" +#include "storage/relfilelocator.h" #include "storage/smgr.h" #include "utils/relcache.h" #include "utils/reltrigger.h" @@ -53,7 +53,7 @@ typedef LockInfoData *LockInfo; typedef struct RelationData { - RelFileNode rd_node; /* relation physical identifier */ + RelFileLocator rd_locator; /* relation physical identifier */ SMgrRelation rd_smgr; /* cached file handle, or NULL */ int rd_refcnt; /* reference count */ BackendId rd_backend; /* owning backend id, if temporary relation */ @@ -66,44 +66,45 @@ typedef struct RelationData /*---------- * rd_createSubid is the ID of the highest subtransaction the rel has - * survived into or zero if the rel or its rd_node was created before the - * current top transaction. (IndexStmt.oldNode leads to the case of a new - * rel with an old rd_node.) rd_firstRelfilenodeSubid is the ID of the - * highest subtransaction an rd_node change has survived into or zero if - * rd_node matches the value it had at the start of the current top + * survived into or zero if the rel or its storage was created before the + * current top transaction. (IndexStmt.oldNumber leads to the case of a new + * rel with an old rd_locator.) rd_firstRelfilelocatorSubid is the ID of the + * highest subtransaction an rd_locator change has survived into or zero if + * rd_locator matches the value it had at the start of the current top * transaction. (Rolling back the subtransaction that - * rd_firstRelfilenodeSubid denotes would restore rd_node to the value it + * rd_firstRelfilelocatorSubid denotes would restore rd_locator to the value it * had at the start of the current top transaction. Rolling back any * lower subtransaction would not.) Their accuracy is critical to * RelationNeedsWAL(). * - * rd_newRelfilenodeSubid is the ID of the highest subtransaction the - * most-recent relfilenode change has survived into or zero if not changed + * rd_newRelfilelocatorSubid is the ID of the highest subtransaction the + * most-recent relfilenumber change has survived into or zero if not changed * in the current transaction (or we have forgotten changing it). This * field is accurate when non-zero, but it can be zero when a relation has - * multiple new relfilenodes within a single transaction, with one of them + * multiple new relfilenumbers within a single transaction, with one of them * occurring in a subsequently aborted subtransaction, e.g. * BEGIN; * TRUNCATE t; * SAVEPOINT save; * TRUNCATE t; * ROLLBACK TO save; - * -- rd_newRelfilenodeSubid is now forgotten + * -- rd_newRelfilelocatorSubid is now forgotten * * If every rd_*Subid field is zero, they are read-only outside - * relcache.c. Files that trigger rd_node changes by updating + * relcache.c. Files that trigger rd_locator changes by updating * pg_class.reltablespace and/or pg_class.relfilenode call - * RelationAssumeNewRelfilenode() to update rd_*Subid. + * RelationAssumeNewRelfilelocator() to update rd_*Subid. * * rd_droppedSubid is the ID of the highest subtransaction that a drop of * the rel has survived into. In entries visible outside relcache.c, this * is always zero. */ SubTransactionId rd_createSubid; /* rel was created in current xact */ - SubTransactionId rd_newRelfilenodeSubid; /* highest subxact changing - * rd_node to current value */ - SubTransactionId rd_firstRelfilenodeSubid; /* highest subxact changing - * rd_node to any value */ + SubTransactionId rd_newRelfilelocatorSubid; /* highest subxact changing + * rd_locator to current value */ + SubTransactionId rd_firstRelfilelocatorSubid; /* highest subxact + * changing rd_locator to + * any value */ SubTransactionId rd_droppedSubid; /* dropped with another Subid set */ Form_pg_class rd_rel; /* RELATION tuple */ @@ -531,12 +532,12 @@ typedef struct ViewOptions /* * RelationIsMapped - * True if the relation uses the relfilenode map. Note multiple eval + * True if the relation uses the relfilenumber map. Note multiple eval * of argument! */ #define RelationIsMapped(relation) \ (RELKIND_HAS_STORAGE((relation)->rd_rel->relkind) && \ - ((relation)->rd_rel->relfilenode == InvalidOid)) + ((relation)->rd_rel->relfilenode == InvalidRelFileNumber)) /* * RelationGetSmgr @@ -555,7 +556,7 @@ static inline SMgrRelation RelationGetSmgr(Relation rel) { if (unlikely(rel->rd_smgr == NULL)) - smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_node, rel->rd_backend)); + smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_locator, rel->rd_backend)); return rel->rd_smgr; } @@ -607,12 +608,12 @@ RelationGetSmgr(Relation rel) * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New - * RelFileNode" in src/backend/access/transam/README. + * RelFileLocator" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ (RelationIsPermanent(relation) && (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ - relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) + relation->rd_firstRelfilelocatorSubid == InvalidSubTransactionId))) /* * RelationUsesLocalBuffers diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index c93d8654bb..ba35d6b3b3 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -103,7 +103,7 @@ extern Relation RelationBuildLocalRelation(const char *relname, TupleDesc tupDesc, Oid relid, Oid accessmtd, - Oid relfilenode, + RelFileNumber relfilenumber, Oid reltablespace, bool shared_relation, bool mapped_relation, @@ -111,10 +111,10 @@ extern Relation RelationBuildLocalRelation(const char *relname, char relkind); /* - * Routines to manage assignment of new relfilenode to a relation + * Routines to manage assignment of new relfilenumber to a relation */ -extern void RelationSetNewRelfilenode(Relation relation, char persistence); -extern void RelationAssumeNewRelfilenode(Relation relation); +extern void RelationSetNewRelfilenumber(Relation relation, char persistence); +extern void RelationAssumeNewRelfilelocator(Relation relation); /* * Routines for flushing/rebuilding relcache entries in various scenarios diff --git a/src/include/utils/relfilenodemap.h b/src/include/utils/relfilenumbermap.h index 77d8046505..c149a937e9 100644 --- a/src/include/utils/relfilenodemap.h +++ b/src/include/utils/relfilenumbermap.h @@ -1,18 +1,19 @@ /*------------------------------------------------------------------------- * - * relfilenodemap.h - * relfilenode to oid mapping cache. + * relfilenumbermap.h + * relfilenumber to oid mapping cache. * * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * src/include/utils/relfilenodemap.h + * src/include/utils/relfilenumbermap.h * *------------------------------------------------------------------------- */ -#ifndef RELFILENODEMAP_H -#define RELFILENODEMAP_H +#ifndef RELFILENUMBERMAP_H +#define RELFILENUMBERMAP_H -extern Oid RelidByRelfilenode(Oid reltablespace, Oid relfilenode); +extern Oid RelidByRelfilenumber(Oid reltablespace, + RelFileNumber relfilenumber); -#endif /* RELFILENODEMAP_H */ +#endif /* RELFILENUMBERMAP_H */ diff --git a/src/include/utils/relmapper.h b/src/include/utils/relmapper.h index 557f77e35a..2bb2e255fd 100644 --- a/src/include/utils/relmapper.h +++ b/src/include/utils/relmapper.h @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------- * * relmapper.h - * Catalog-to-filenode mapping + * Catalog-to-filenumber mapping * * * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group @@ -35,14 +35,15 @@ typedef struct xl_relmap_update #define MinSizeOfRelmapUpdate offsetof(xl_relmap_update, data) -extern Oid RelationMapOidToFilenode(Oid relationId, bool shared); +extern RelFileNumber RelationMapOidToFilenumber(Oid relationId, bool shared); -extern Oid RelationMapFilenodeToOid(Oid relationId, bool shared); -extern Oid RelationMapOidToFilenodeForDatabase(char *dbpath, Oid relationId); +extern Oid RelationMapFilenumberToOid(RelFileNumber relationId, bool shared); +extern RelFileNumber RelationMapOidToFilenumberForDatabase(char *dbpath, + Oid relationId); extern void RelationMapCopy(Oid dbid, Oid tsid, char *srcdbpath, char *dstdbpath); -extern void RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared, - bool immediate); +extern void RelationMapUpdateMap(Oid relationId, RelFileNumber fileNumber, + bool shared, bool immediate); extern void RelationMapRemoveMapping(Oid relationId); |
