Skip to content

Commit

Permalink
Use updated parse_filename_for_nontemp_relation() interface.
Browse files Browse the repository at this point in the history
And place changes under \#if PG_VERSION_NUM >= 170000.
  Caused by:
  - 5c47c6546c413d5eb51c1626070a807026e6139d (PostgreSQL)
    Refactor parse_filename_for_nontemp_relation to parse more.
  - f1352d7  (ptrack extension)
    Ptrack 2.0 initial release
Tags: ptrack
  • Loading branch information
antamel authored and funny-falcon committed Jan 31, 2024
1 parent d427f73 commit 89bbbfc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 12 additions & 0 deletions engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,13 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid,
BlockNumber blkno,
nblocks = 0;
struct stat stat_buf;
#if PG_VERSION_NUM >= 170000
RelFileNumber relNumber;
unsigned segno;
#else
int oidchars;
char oidbuf[OIDCHARS + 1];
#endif

/* Do not track temporary relations */
if (looks_like_temp_rel_name(filename))
Expand All @@ -519,12 +524,19 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid,
nodeDb(nodeOf(rnode)) = dbOid;
nodeSpc(nodeOf(rnode)) = tablespaceOid;

#if PG_VERSION_NUM >= 170000
if (!parse_filename_for_nontemp_relation(filename, &relNumber, &forknum, &segno))
return;

nodeRel(nodeOf(rnode)) = relNumber;
#else
if (!parse_filename_for_nontemp_relation(filename, &oidchars, &forknum))
return;

memcpy(oidbuf, filename, oidchars);
oidbuf[oidchars] = '\0';
nodeRel(nodeOf(rnode)) = atooid(oidbuf);
#endif

/* Compute number of blocks based on file size */
if (stat(filepath, &stat_buf) == 0)
Expand Down
15 changes: 14 additions & 1 deletion ptrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,38 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
/* Regular file inside database directory, otherwise skip it */
if (dbOid != InvalidOid || spcOid == GLOBALTABLESPACE_OID)
{
#if PG_VERSION_NUM >= 170000
RelFileNumber relNumber;
unsigned segno;
#else
int oidchars;
char oidbuf[OIDCHARS + 1];
#endif
char *segpath;
PtrackFileList_i *pfl = palloc0(sizeof(PtrackFileList_i));

/*
* Check that filename seems to be a regular relation file.
*/
#if PG_VERSION_NUM >= 170000
if (!parse_filename_for_nontemp_relation(de->d_name, &relNumber, &pfl->forknum, &segno))
continue;
#else
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars, &pfl->forknum))
continue;

#endif
/* Parse segno */
segpath = strstr(de->d_name, ".");
pfl->segno = segpath != NULL ? atoi(segpath + 1) : 0;

/* Fill the pfl in */
#if PG_VERSION_NUM >= 170000
nodeRel(pfl->relnode) = relNumber;
#else
memcpy(oidbuf, de->d_name, oidchars);
oidbuf[oidchars] = '\0';
nodeRel(pfl->relnode) = atooid(oidbuf);
#endif
nodeDb(pfl->relnode) = dbOid;
nodeSpc(pfl->relnode) = spcOid == InvalidOid ? DEFAULTTABLESPACE_OID : spcOid;
pfl->path = GetRelationPath(dbOid, nodeSpc(pfl->relnode),
Expand Down

0 comments on commit 89bbbfc

Please sign in to comment.