diff options
author | Robert Haas | 2022-09-28 13:45:27 +0000 |
---|---|---|
committer | Robert Haas | 2022-09-28 13:55:28 +0000 |
commit | a448e49bcbe40fb72e1ed85af910dd216d45bad8 (patch) | |
tree | 2815aed4f5e89bdea91cdd35ec89facaa846e438 /src/include | |
parent | 6af082723277eeca74f2da65e7759666bf7c7f9c (diff) |
Revert 56-bit relfilenode change and follow-up commits.
There are still some alignment-related failures in the buildfarm,
which might or might not be able to be fixed quickly, but I've also
just realized that it increased the size of many WAL records by 4 bytes
because a block reference contains a RelFileLocator. The effect of that
hasn't been studied or discussed, so revert for now.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/access/transam.h | 40 | ||||
-rw-r--r-- | src/include/access/xlog.h | 1 | ||||
-rw-r--r-- | src/include/catalog/catalog.h | 3 | ||||
-rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_class.h | 16 | ||||
-rw-r--r-- | src/include/catalog/pg_control.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.dat | 10 | ||||
-rw-r--r-- | src/include/common/relpath.h | 7 | ||||
-rw-r--r-- | src/include/fe_utils/option_utils.h | 2 | ||||
-rw-r--r-- | src/include/storage/buf_internals.h | 55 | ||||
-rw-r--r-- | src/include/storage/relfilelocator.h | 12 | ||||
-rw-r--r-- | src/include/storage/sinval.h | 7 |
12 files changed, 34 insertions, 123 deletions
diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 2aaad2b9d51..775471d2a7d 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -15,7 +15,6 @@ #define TRANSAM_H #include "access/xlogdefs.h" -#include "common/relpath.h" /* ---------------- @@ -197,33 +196,6 @@ FullTransactionIdAdvance(FullTransactionId *dest) #define FirstUnpinnedObjectId 12000 #define FirstNormalObjectId 16384 -/* ---------- - * RelFileNumbers are normally assigned sequentially beginning with - * FirstNormalRelFileNumber, but for system tables the initial RelFileNumber - * is equal to the table OID. This scheme allows pg_upgrade to work: we expect - * that the new cluster will contain only system tables, and that none of those - * will have previously been rewritten, so any RelFileNumber which is in use - * in both the old and new clusters will be used for the same relation in both - * places. - * - * This is important because pg_upgrade can't reactively move conflicting - * relations out of the way. If it tries to set the RelFileNumber for a - * relation to some value that's already in use by a different relation, the - * upgrade will just fail. It's OK if the same RelFileNumber is used for the - * same relation, though, since then nothing needs to be changed. - * ---------- - */ -#define FirstNormalRelFileNumber ((RelFileNumber) 100000) - -#define CHECK_RELFILENUMBER_RANGE(relfilenumber) \ -do { \ - if ((relfilenumber) < 0 || (relfilenumber) > MAX_RELFILENUMBER) \ - ereport(ERROR, \ - errcode(ERRCODE_INVALID_PARAMETER_VALUE), \ - errmsg("relfilenumber %llu is out of range", \ - (unsigned long long) (relfilenumber))); \ -} while (0) - /* * VariableCache is a data structure in shared memory that is used to track * OID and XID assignment state. For largely historical reasons, there is @@ -243,15 +215,6 @@ typedef struct VariableCacheData uint32 oidCount; /* OIDs available before must do XLOG work */ /* - * These fields are protected by RelFileNumberGenLock. - */ - RelFileNumber nextRelFileNumber; /* next relfilenumber to assign */ - RelFileNumber loggedRelFileNumber; /* last logged relfilenumber */ - RelFileNumber flushedRelFileNumber; /* last flushed relfilenumber */ - XLogRecPtr loggedRelFileNumberRecPtr; /* xlog record pointer w.r.t. - * loggedRelFileNumber */ - - /* * These fields are protected by XidGenLock. */ FullTransactionId nextXid; /* next XID to assign */ @@ -330,9 +293,6 @@ extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, extern void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid); extern bool ForceTransactionIdLimitUpdate(void); extern Oid GetNewObjectId(void); -extern RelFileNumber GetNewRelFileNumber(Oid reltablespace, - char relpersistence); -extern void SetNextRelFileNumber(RelFileNumber relnumber); extern void StopGeneratingPinnedObjectIds(void); #ifdef USE_ASSERT_CHECKING diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 53375865dfd..dce265098e3 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -236,7 +236,6 @@ extern void CreateCheckPoint(int flags); extern bool CreateRestartPoint(int flags); extern WALAvailability GetWALAvailability(XLogRecPtr targetLSN); extern void XLogPutNextOid(Oid nextOid); -extern XLogRecPtr LogNextRelFileNumber(RelFileNumber nextrelnumber); extern XLogRecPtr XLogRestorePoint(const char *rpName); extern void UpdateFullPageWrites(void); extern void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p); diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index b45253045e7..e1c85f98550 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -38,5 +38,8 @@ extern bool IsPinnedObject(Oid classId, Oid objectId); extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn); +extern RelFileNumber GetNewRelFileNumber(Oid reltablespace, + Relation pg_class, + char relpersistence); #endif /* CATALOG_H */ diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 8ba25e4dc8e..95e7c249ed8 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -57,6 +57,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202209271 +#define CATALOG_VERSION_NO 202209261 #endif diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 4768e5ebda5..e1f4eefa220 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -34,13 +34,6 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* oid */ Oid oid; - /* access method; 0 if not a table / index */ - Oid relam BKI_DEFAULT(heap) BKI_LOOKUP_OPT(pg_am); - - /* identifier of physical storage file */ - /* relfilenode == 0 means it is a "mapped" relation, see relmapper.c */ - int64 relfilenode BKI_DEFAULT(0); - /* class name */ NameData relname; @@ -56,6 +49,13 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* class owner */ Oid relowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid); + /* access method; 0 if not a table / index */ + Oid relam BKI_DEFAULT(heap) BKI_LOOKUP_OPT(pg_am); + + /* identifier of physical storage file */ + /* relfilenode == 0 means it is a "mapped" relation, see relmapper.c */ + Oid relfilenode BKI_DEFAULT(0); + /* identifier of table space for relation (0 means default for database) */ Oid reltablespace BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_tablespace); @@ -154,7 +154,7 @@ typedef FormData_pg_class *Form_pg_class; DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, on pg_class using btree(oid oid_ops)); DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, on pg_class using btree(relname name_ops, relnamespace oid_ops)); -DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, on pg_class using btree(reltablespace oid_ops, relfilenode int8_ops)); +DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, on pg_class using btree(reltablespace oid_ops, relfilenode oid_ops)); #ifdef EXPOSE_TO_CLIENT_CODE diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h index 096222f1fe5..06368e23667 100644 --- a/src/include/catalog/pg_control.h +++ b/src/include/catalog/pg_control.h @@ -41,7 +41,6 @@ typedef struct CheckPoint * timeline (equals ThisTimeLineID otherwise) */ bool fullPageWrites; /* current full_page_writes */ FullTransactionId nextXid; /* next free transaction ID */ - RelFileNumber nextRelFileNumber; /* next relfilenumber */ Oid nextOid; /* next free OID */ MultiXactId nextMulti; /* next free MultiXactId */ MultiXactOffset nextMultiOffset; /* next free MultiXact offset */ @@ -79,7 +78,6 @@ typedef struct CheckPoint #define XLOG_FPI 0xB0 /* 0xC0 is used in Postgres 9.5-11 */ #define XLOG_OVERWRITE_CONTRECORD 0xD0 -#define XLOG_NEXT_RELFILENUMBER 0xE0 /* diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 8b72f8a215b..a07e737a337 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -7329,11 +7329,11 @@ proname => 'pg_indexes_size', provolatile => 'v', prorettype => 'int8', proargtypes => 'regclass', prosrc => 'pg_indexes_size' }, { oid => '2999', descr => 'filenode identifier of relation', - proname => 'pg_relation_filenode', provolatile => 's', prorettype => 'int8', + proname => 'pg_relation_filenode', provolatile => 's', prorettype => 'oid', proargtypes => 'regclass', prosrc => 'pg_relation_filenode' }, { oid => '3454', descr => 'relation OID for filenode and tablespace', proname => 'pg_filenode_relation', provolatile => 's', - prorettype => 'regclass', proargtypes => 'oid int8', + prorettype => 'regclass', proargtypes => 'oid oid', prosrc => 'pg_filenode_relation' }, { oid => '3034', descr => 'file path of relation', proname => 'pg_relation_filepath', provolatile => 's', prorettype => 'text', @@ -11125,15 +11125,15 @@ prosrc => 'binary_upgrade_set_missing_value' }, { oid => '4545', descr => 'for use by pg_upgrade', proname => 'binary_upgrade_set_next_heap_relfilenode', provolatile => 'v', - proparallel => 'u', prorettype => 'void', proargtypes => 'int8', + proparallel => 'u', prorettype => 'void', proargtypes => 'oid', prosrc => 'binary_upgrade_set_next_heap_relfilenode' }, { oid => '4546', descr => 'for use by pg_upgrade', proname => 'binary_upgrade_set_next_index_relfilenode', provolatile => 'v', - proparallel => 'u', prorettype => 'void', proargtypes => 'int8', + proparallel => 'u', prorettype => 'void', proargtypes => 'oid', prosrc => 'binary_upgrade_set_next_index_relfilenode' }, { oid => '4547', descr => 'for use by pg_upgrade', proname => 'binary_upgrade_set_next_toast_relfilenode', provolatile => 'v', - proparallel => 'u', prorettype => 'void', proargtypes => 'int8', + proparallel => 'u', prorettype => 'void', proargtypes => 'oid', prosrc => 'binary_upgrade_set_next_toast_relfilenode' }, { oid => '4548', descr => 'for use by pg_upgrade', proname => 'binary_upgrade_set_next_pg_tablespace_oid', provolatile => 'v', diff --git a/src/include/common/relpath.h b/src/include/common/relpath.h index 2d3b52fe0b8..4bbd94393c8 100644 --- a/src/include/common/relpath.h +++ b/src/include/common/relpath.h @@ -22,12 +22,10 @@ /* * RelFileNumber data type identifies the specific relation file name. */ -typedef uint64 RelFileNumber; -#define InvalidRelFileNumber ((RelFileNumber) 0) +typedef Oid RelFileNumber; +#define InvalidRelFileNumber ((RelFileNumber) InvalidOid) #define RelFileNumberIsValid(relnumber) \ ((bool) ((relnumber) != InvalidRelFileNumber)) -#define atorelnumber(x) ((RelFileNumber) strtou64((x), NULL, 10)) -#define MAX_RELFILENUMBER UINT64CONST(0x00FFFFFFFFFFFFFF) /* * Name of major-version-specific tablespace subdirectories @@ -37,7 +35,6 @@ typedef uint64 RelFileNumber; /* Characters to allow for an OID in a relation path */ #define OIDCHARS 10 /* max chars printed by %u */ -#define RELNUMBERCHARS 20 /* max chars printed by UINT64_FORMAT */ /* * Stuff for fork names. diff --git a/src/include/fe_utils/option_utils.h b/src/include/fe_utils/option_utils.h index 2508a6193b0..03c09fd13a4 100644 --- a/src/include/fe_utils/option_utils.h +++ b/src/include/fe_utils/option_utils.h @@ -22,7 +22,5 @@ extern void handle_help_version_opts(int argc, char *argv[], extern bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result); -extern bool option_parse_relfilenumber(const char *optarg, - const char *optname); #endif /* OPTION_UTILS_H */ diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index d4dc9eb3429..406db6be783 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -92,66 +92,29 @@ typedef struct buftag { Oid spcOid; /* tablespace oid */ Oid dbOid; /* database oid */ - - /* - * relForkDetails[] stores the fork number in the high 8 bits of the first - * integer; the remaining 56 bits are used to store the relfilenmber. - * Expanding the relfilenumber to a full 64 bits would require widening - * the BufferTag, which is undesirable for performance reasons. We use - * two 32-bit values here rather than a single 64-bit value to avoid - * padding the struct out to a multiple of 8 bytes. - */ - uint32 relForkDetails[2]; + RelFileNumber relNumber; /* relation file number */ + ForkNumber forkNum; /* fork number */ BlockNumber blockNum; /* blknum relative to begin of reln */ } BufferTag; -/* High relNumber bits in relForkDetails[0] */ -#define BUFTAG_RELNUM_HIGH_BITS 24 - -/* Low relNumber bits in relForkDetails[1] */ -#define BUFTAG_RELNUM_LOW_BITS 32 - -/* Mask to fetch high bits of relNumber from relForkDetails[0] */ -#define BUFTAG_RELNUM_HIGH_MASK ((1U << BUFTAG_RELNUM_HIGH_BITS) - 1) - -/* Mask to fetch low bits of relNumber from relForkDetails[1] */ -#define BUFTAG_RELNUM_LOW_MASK 0XFFFFFFFF - static inline RelFileNumber BufTagGetRelNumber(const BufferTag *tag) { - uint64 relnum; - - relnum = ((uint64) tag->relForkDetails[0]) & BUFTAG_RELNUM_HIGH_MASK; - relnum = (relnum << BUFTAG_RELNUM_LOW_BITS) | tag->relForkDetails[1]; - - Assert(relnum <= MAX_RELFILENUMBER); - return (RelFileNumber) relnum; + return tag->relNumber; } static inline ForkNumber BufTagGetForkNum(const BufferTag *tag) { - ForkNumber ret; - - StaticAssertStmt(MAX_FORKNUM <= INT8_MAX, - "MAX_FORKNUM can't be greater than INT8_MAX"); - - ret = (ForkNumber) (tag->relForkDetails[0] >> BUFTAG_RELNUM_HIGH_BITS); - return ret; + return tag->forkNum; } static inline void BufTagSetRelForkDetails(BufferTag *tag, RelFileNumber relnumber, ForkNumber forknum) { - Assert(relnumber <= MAX_RELFILENUMBER); - Assert(forknum <= MAX_FORKNUM); - - tag->relForkDetails[0] = (relnumber >> BUFTAG_RELNUM_LOW_BITS) & - BUFTAG_RELNUM_HIGH_MASK; - tag->relForkDetails[0] |= (forknum << BUFTAG_RELNUM_HIGH_BITS); - tag->relForkDetails[1] = relnumber & BUFTAG_RELNUM_LOW_MASK; + tag->relNumber = relnumber; + tag->forkNum = forknum; } static inline RelFileLocator @@ -190,9 +153,9 @@ BufferTagsEqual(const BufferTag *tag1, const BufferTag *tag2) { return (tag1->spcOid == tag2->spcOid) && (tag1->dbOid == tag2->dbOid) && - (tag1->relForkDetails[0] == tag2->relForkDetails[0]) && - (tag1->relForkDetails[1] == tag2->relForkDetails[1]) && - (tag1->blockNum == tag2->blockNum); + (tag1->relNumber == tag2->relNumber) && + (tag1->blockNum == tag2->blockNum) && + (tag1->forkNum == tag2->forkNum); } static inline bool diff --git a/src/include/storage/relfilelocator.h b/src/include/storage/relfilelocator.h index ef904644fa4..10f41f3abb3 100644 --- a/src/include/storage/relfilelocator.h +++ b/src/include/storage/relfilelocator.h @@ -32,11 +32,10 @@ * Nonzero dbOid values correspond to pg_database.oid. * * relNumber identifies the specific relation. relNumber corresponds to - * pg_class.relfilenode. Notice that relNumber values are assigned by - * GetNewRelFileNumber(), which will only ever assign the same value once - * during the lifetime of a cluster. However, since CREATE DATABASE duplicates - * the relfilenumbers of the template database, the values are in practice only - * unique within a database, not globally. + * 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. @@ -76,9 +75,6 @@ typedef struct RelFileLocatorBackend BackendId backend; } RelFileLocatorBackend; -#define SizeOfRelFileLocatorBackend \ - (offsetof(RelFileLocatorBackend, backend) + sizeof(BackendId)) - #define RelFileLocatorBackendIsTemp(rlocator) \ ((rlocator).backend != InvalidBackendId) diff --git a/src/include/storage/sinval.h b/src/include/storage/sinval.h index 4a267be935c..aca0347a3d3 100644 --- a/src/include/storage/sinval.h +++ b/src/include/storage/sinval.h @@ -86,14 +86,11 @@ typedef struct typedef struct { - /* note: field layout chosen to pack into 20 bytes */ + /* note: field layout chosen to pack into 16 bytes */ 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 */ - Oid dbOid; - Oid spcOid; - uint32 relNumber_hi; /* avoid 8 byte alignment requirement */ - uint32 relNumber_lo; + RelFileLocator rlocator; /* spcOid, dbOid, relNumber */ } SharedInvalSmgrMsg; #define SHAREDINVALRELMAP_ID (-4) |