Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 851f4cc

Browse files
committed
Clean up some residual confusion between OIDs and RelFileNumbers.
Commit b0a55e4 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.
1 parent 9e4f914 commit 851f4cc

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

src/backend/commands/dbcommands.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
254254
BlockNumber nblocks;
255255
BlockNumber blkno;
256256
Buffer buf;
257-
Oid relfilenumber;
257+
RelFileNumber relfilenumber;
258258
Page page;
259259
List *rlocatorlist = NIL;
260260
LockRelId relid;
@@ -401,7 +401,7 @@ ScanSourceDatabasePgClassTuple(HeapTupleData *tuple, Oid tbid, Oid dbid,
401401
{
402402
CreateDBRelInfo *relinfo;
403403
Form_pg_class classForm;
404-
Oid relfilenumber = InvalidRelFileNumber;
404+
RelFileNumber relfilenumber = InvalidRelFileNumber;
405405

406406
classForm = (Form_pg_class) GETSTRUCT(tuple);
407407

src/backend/replication/basebackup.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,8 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
11721172
int excludeIdx;
11731173
bool excludeFound;
11741174
ForkNumber relForkNum; /* Type of fork if file is a relation */
1175-
int relOidChars; /* Chars in filename that are the rel oid */
1175+
int relnumchars; /* Chars in filename that are the
1176+
* relnumber */
11761177

11771178
/* Skip special stuff */
11781179
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,
12221223

12231224
/* Exclude all forks for unlogged tables except the init fork */
12241225
if (isDbDir &&
1225-
parse_filename_for_nontemp_relation(de->d_name, &relOidChars,
1226+
parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
12261227
&relForkNum))
12271228
{
12281229
/* Never exclude init forks */
12291230
if (relForkNum != INIT_FORKNUM)
12301231
{
12311232
char initForkFile[MAXPGPATH];
1232-
char relOid[OIDCHARS + 1];
1233+
char relNumber[OIDCHARS + 1];
12331234

12341235
/*
12351236
* If any other type of fork, check if there is an init fork
1236-
* with the same OID. If so, the file can be excluded.
1237+
* with the same RelFileNumber. If so, the file can be
1238+
* excluded.
12371239
*/
1238-
memcpy(relOid, de->d_name, relOidChars);
1239-
relOid[relOidChars] = '\0';
1240+
memcpy(relNumber, de->d_name, relnumchars);
1241+
relNumber[relnumchars] = '\0';
12401242
snprintf(initForkFile, sizeof(initForkFile), "%s/%s_init",
1241-
path, relOid);
1243+
path, relNumber);
12421244

12431245
if (lstat(initForkFile, &statbuf) == 0)
12441246
{

src/backend/storage/file/reinit.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
195195
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
196196
{
197197
ForkNumber forkNum;
198-
int oidchars;
198+
int relnumchars;
199199
unlogged_relation_entry ent;
200200

201201
/* Skip anything that doesn't look like a relation data file. */
202-
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars,
202+
if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
203203
&forkNum))
204204
continue;
205205

@@ -235,11 +235,11 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
235235
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
236236
{
237237
ForkNumber forkNum;
238-
int oidchars;
238+
int relnumchars;
239239
unlogged_relation_entry ent;
240240

241241
/* Skip anything that doesn't look like a relation data file. */
242-
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars,
242+
if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
243243
&forkNum))
244244
continue;
245245

@@ -285,13 +285,13 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
285285
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
286286
{
287287
ForkNumber forkNum;
288-
int oidchars;
289-
char oidbuf[OIDCHARS + 1];
288+
int relnumchars;
289+
char relnumbuf[OIDCHARS + 1];
290290
char srcpath[MAXPGPATH * 2];
291291
char dstpath[MAXPGPATH];
292292

293293
/* Skip anything that doesn't look like a relation data file. */
294-
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars,
294+
if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
295295
&forkNum))
296296
continue;
297297

@@ -304,10 +304,10 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
304304
dbspacedirname, de->d_name);
305305

306306
/* Construct destination pathname. */
307-
memcpy(oidbuf, de->d_name, oidchars);
308-
oidbuf[oidchars] = '\0';
307+
memcpy(relnumbuf, de->d_name, relnumchars);
308+
relnumbuf[relnumchars] = '\0';
309309
snprintf(dstpath, sizeof(dstpath), "%s/%s%s",
310-
dbspacedirname, oidbuf, de->d_name + oidchars + 1 +
310+
dbspacedirname, relnumbuf, de->d_name + relnumchars + 1 +
311311
strlen(forkNames[INIT_FORKNUM]));
312312

313313
/* OK, we're ready to perform the actual copy. */
@@ -328,12 +328,12 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
328328
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
329329
{
330330
ForkNumber forkNum;
331-
int oidchars;
332-
char oidbuf[OIDCHARS + 1];
331+
int relnumchars;
332+
char relnumbuf[OIDCHARS + 1];
333333
char mainpath[MAXPGPATH];
334334

335335
/* Skip anything that doesn't look like a relation data file. */
336-
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars,
336+
if (!parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
337337
&forkNum))
338338
continue;
339339

@@ -342,10 +342,10 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
342342
continue;
343343

344344
/* Construct main fork pathname. */
345-
memcpy(oidbuf, de->d_name, oidchars);
346-
oidbuf[oidchars] = '\0';
345+
memcpy(relnumbuf, de->d_name, relnumchars);
346+
relnumbuf[relnumchars] = '\0';
347347
snprintf(mainpath, sizeof(mainpath), "%s/%s%s",
348-
dbspacedirname, oidbuf, de->d_name + oidchars + 1 +
348+
dbspacedirname, relnumbuf, de->d_name + relnumchars + 1 +
349349
strlen(forkNames[INIT_FORKNUM]));
350350

351351
fsync_fname(mainpath, false);
@@ -372,13 +372,13 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
372372
* for a non-temporary relation and false otherwise.
373373
*
374374
* NB: If this function returns true, the caller is entitled to assume that
375-
* *oidchars has been set to the a value no more than OIDCHARS, and thus
376-
* that a buffer of OIDCHARS+1 characters is sufficient to hold the OID
377-
* portion of the filename. This is critical to protect against a possible
378-
* buffer overrun.
375+
* *relnumchars has been set to a value no more than OIDCHARS, and thus
376+
* that a buffer of OIDCHARS+1 characters is sufficient to hold the
377+
* RelFileNumber portion of the filename. This is critical to protect against
378+
* a possible buffer overrun.
379379
*/
380380
bool
381-
parse_filename_for_nontemp_relation(const char *name, int *oidchars,
381+
parse_filename_for_nontemp_relation(const char *name, int *relnumchars,
382382
ForkNumber *fork)
383383
{
384384
int pos;
@@ -388,7 +388,7 @@ parse_filename_for_nontemp_relation(const char *name, int *oidchars,
388388
;
389389
if (pos == 0 || pos > OIDCHARS)
390390
return false;
391-
*oidchars = pos;
391+
*relnumchars = pos;
392392

393393
/* Check for a fork name. */
394394
if (name[pos] != '_')

src/include/storage/reinit.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
extern void ResetUnloggedRelations(int op);
2222
extern bool parse_filename_for_nontemp_relation(const char *name,
23-
int *oidchars, ForkNumber *fork);
23+
int *relnumchars,
24+
ForkNumber *fork);
2425

2526
#define UNLOGGED_RELATION_CLEANUP 0x0001
2627
#define UNLOGGED_RELATION_INIT 0x0002

0 commit comments

Comments
 (0)