Clean up some residual confusion between OIDs and RelFileNumbers.

Commit b0a55e4329 missed a few places
where we are referring to the number used as a part of the relation
filename as an "OID". We now want to call that a "RelFileNumber".

Some of these places actually made it sound like the OID in question
is pg_class.oid rather than pg_class.relfilenode, which is especially
good to clean up.

Dilip Kumar with some editing by me.
This commit is contained in:
Robert Haas 2022-07-28 10:08:10 -04:00
parent 9e4f914b5e
commit 851f4cc75c
4 changed files with 35 additions and 32 deletions

View File

@ -254,7 +254,7 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
BlockNumber nblocks; BlockNumber nblocks;
BlockNumber blkno; BlockNumber blkno;
Buffer buf; Buffer buf;
Oid relfilenumber; RelFileNumber relfilenumber;
Page page; Page page;
List *rlocatorlist = NIL; List *rlocatorlist = NIL;
LockRelId relid; LockRelId relid;
@ -401,7 +401,7 @@ ScanSourceDatabasePgClassTuple(HeapTupleData *tuple, Oid tbid, Oid dbid,
{ {
CreateDBRelInfo *relinfo; CreateDBRelInfo *relinfo;
Form_pg_class classForm; Form_pg_class classForm;
Oid relfilenumber = InvalidRelFileNumber; RelFileNumber relfilenumber = InvalidRelFileNumber;
classForm = (Form_pg_class) GETSTRUCT(tuple); classForm = (Form_pg_class) GETSTRUCT(tuple);

View File

@ -1172,7 +1172,8 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
int excludeIdx; int excludeIdx;
bool excludeFound; bool excludeFound;
ForkNumber relForkNum; /* Type of fork if file is a relation */ ForkNumber relForkNum; /* Type of fork if file is a relation */
int relOidChars; /* Chars in filename that are the rel oid */ int relnumchars; /* Chars in filename that are the
* relnumber */
/* Skip special stuff */ /* Skip special stuff */
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
@ -1222,23 +1223,24 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
/* Exclude all forks for unlogged tables except the init fork */ /* Exclude all forks for unlogged tables except the init fork */
if (isDbDir && if (isDbDir &&
parse_filename_for_nontemp_relation(de->d_name, &relOidChars, parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
&relForkNum)) &relForkNum))
{ {
/* Never exclude init forks */ /* Never exclude init forks */
if (relForkNum != INIT_FORKNUM) if (relForkNum != INIT_FORKNUM)
{ {
char initForkFile[MAXPGPATH]; char initForkFile[MAXPGPATH];
char relOid[OIDCHARS + 1]; char relNumber[OIDCHARS + 1];
/* /*
* If any other type of fork, check if there is an init fork * If any other type of fork, check if there is an init fork
* with the same OID. If so, the file can be excluded. * with the same RelFileNumber. If so, the file can be
* excluded.
*/ */
memcpy(relOid, de->d_name, relOidChars); memcpy(relNumber, de->d_name, relnumchars);
relOid[relOidChars] = '\0'; relNumber[relnumchars] = '\0';
snprintf(initForkFile, sizeof(initForkFile), "%s/%s_init", snprintf(initForkFile, sizeof(initForkFile), "%s/%s_init",
path, relOid); path, relNumber);
if (lstat(initForkFile, &statbuf) == 0) if (lstat(initForkFile, &statbuf) == 0)
{ {

View File

@ -195,11 +195,11 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL) while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
{ {
ForkNumber forkNum; ForkNumber forkNum;
int oidchars; int relnumchars;
unlogged_relation_entry ent; unlogged_relation_entry ent;
/* Skip anything that doesn't look like a relation data file. */ /* Skip anything that doesn't look like a relation data file. */
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars, if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
&forkNum)) &forkNum))
continue; continue;
@ -235,11 +235,11 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL) while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
{ {
ForkNumber forkNum; ForkNumber forkNum;
int oidchars; int relnumchars;
unlogged_relation_entry ent; unlogged_relation_entry ent;
/* Skip anything that doesn't look like a relation data file. */ /* Skip anything that doesn't look like a relation data file. */
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars, if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
&forkNum)) &forkNum))
continue; continue;
@ -285,13 +285,13 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL) while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
{ {
ForkNumber forkNum; ForkNumber forkNum;
int oidchars; int relnumchars;
char oidbuf[OIDCHARS + 1]; char relnumbuf[OIDCHARS + 1];
char srcpath[MAXPGPATH * 2]; char srcpath[MAXPGPATH * 2];
char dstpath[MAXPGPATH]; char dstpath[MAXPGPATH];
/* Skip anything that doesn't look like a relation data file. */ /* Skip anything that doesn't look like a relation data file. */
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars, if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
&forkNum)) &forkNum))
continue; continue;
@ -304,10 +304,10 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
dbspacedirname, de->d_name); dbspacedirname, de->d_name);
/* Construct destination pathname. */ /* Construct destination pathname. */
memcpy(oidbuf, de->d_name, oidchars); memcpy(relnumbuf, de->d_name, relnumchars);
oidbuf[oidchars] = '\0'; relnumbuf[relnumchars] = '\0';
snprintf(dstpath, sizeof(dstpath), "%s/%s%s", snprintf(dstpath, sizeof(dstpath), "%s/%s%s",
dbspacedirname, oidbuf, de->d_name + oidchars + 1 + dbspacedirname, relnumbuf, de->d_name + relnumchars + 1 +
strlen(forkNames[INIT_FORKNUM])); strlen(forkNames[INIT_FORKNUM]));
/* OK, we're ready to perform the actual copy. */ /* OK, we're ready to perform the actual copy. */
@ -328,12 +328,12 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL) while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
{ {
ForkNumber forkNum; ForkNumber forkNum;
int oidchars; int relnumchars;
char oidbuf[OIDCHARS + 1]; char relnumbuf[OIDCHARS + 1];
char mainpath[MAXPGPATH]; char mainpath[MAXPGPATH];
/* Skip anything that doesn't look like a relation data file. */ /* Skip anything that doesn't look like a relation data file. */
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars, if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
&forkNum)) &forkNum))
continue; continue;
@ -342,10 +342,10 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
continue; continue;
/* Construct main fork pathname. */ /* Construct main fork pathname. */
memcpy(oidbuf, de->d_name, oidchars); memcpy(relnumbuf, de->d_name, relnumchars);
oidbuf[oidchars] = '\0'; relnumbuf[relnumchars] = '\0';
snprintf(mainpath, sizeof(mainpath), "%s/%s%s", snprintf(mainpath, sizeof(mainpath), "%s/%s%s",
dbspacedirname, oidbuf, de->d_name + oidchars + 1 + dbspacedirname, relnumbuf, de->d_name + relnumchars + 1 +
strlen(forkNames[INIT_FORKNUM])); strlen(forkNames[INIT_FORKNUM]));
fsync_fname(mainpath, false); fsync_fname(mainpath, false);
@ -372,13 +372,13 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
* for a non-temporary relation and false otherwise. * for a non-temporary relation and false otherwise.
* *
* NB: If this function returns true, the caller is entitled to assume that * NB: If this function returns true, the caller is entitled to assume that
* *oidchars has been set to the a value no more than OIDCHARS, and thus * *relnumchars has been set to a value no more than OIDCHARS, and thus
* that a buffer of OIDCHARS+1 characters is sufficient to hold the OID * that a buffer of OIDCHARS+1 characters is sufficient to hold the
* portion of the filename. This is critical to protect against a possible * RelFileNumber portion of the filename. This is critical to protect against
* buffer overrun. * a possible buffer overrun.
*/ */
bool bool
parse_filename_for_nontemp_relation(const char *name, int *oidchars, parse_filename_for_nontemp_relation(const char *name, int *relnumchars,
ForkNumber *fork) ForkNumber *fork)
{ {
int pos; int pos;
@ -388,7 +388,7 @@ parse_filename_for_nontemp_relation(const char *name, int *oidchars,
; ;
if (pos == 0 || pos > OIDCHARS) if (pos == 0 || pos > OIDCHARS)
return false; return false;
*oidchars = pos; *relnumchars = pos;
/* Check for a fork name. */ /* Check for a fork name. */
if (name[pos] != '_') if (name[pos] != '_')

View File

@ -20,7 +20,8 @@
extern void ResetUnloggedRelations(int op); extern void ResetUnloggedRelations(int op);
extern bool parse_filename_for_nontemp_relation(const char *name, extern bool parse_filename_for_nontemp_relation(const char *name,
int *oidchars, ForkNumber *fork); int *relnumchars,
ForkNumber *fork);
#define UNLOGGED_RELATION_CLEANUP 0x0001 #define UNLOGGED_RELATION_CLEANUP 0x0001
#define UNLOGGED_RELATION_INIT 0x0002 #define UNLOGGED_RELATION_INIT 0x0002