From 93195400e1a91908648442a7bc3a1dc657121a5a Mon Sep 17 00:00:00 2001 From: Daniel Shelepanov Date: Fri, 2 Dec 2022 20:32:50 +0300 Subject: [PATCH 1/3] [PBCKP-278] CFS is supported only by EE12+ --- engine.c | 14 +++++++------- engine.h | 3 +++ ptrack.c | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/engine.c b/engine.c index 23c3ab8..72b7e7b 100644 --- a/engine.c +++ b/engine.c @@ -109,7 +109,7 @@ is_cfm_file_path(const char *filepath) { return strlen(filepath) >= 5 && strcmp(&filepath[len-4], ".cfm") == 0; } -#ifdef PGPRO_EE +#if CFS_SUPPORT /* * Determines the relation file size specified by fullpath as if it * was not compressed. @@ -540,7 +540,7 @@ assign_ptrack_map_size(int newval, void *extra) * For use in functions that copy directories bypassing buffer manager. */ static void -#ifdef PGPRO_EE +#if CFS_SUPPORT ptrack_mark_file(Oid dbOid, Oid tablespaceOid, const char *filepath, const char *filename, bool is_cfs) #else @@ -555,7 +555,7 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid, struct stat stat_buf; int oidchars; char oidbuf[OIDCHARS + 1]; -#ifdef PGPRO_EE +#if CFS_SUPPORT off_t rel_size; #endif @@ -576,7 +576,7 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid, oidbuf[oidchars] = '\0'; nodeRel(nodeOf(rnode)) = atooid(oidbuf); -#ifdef PGPRO_EE +#if CFS_SUPPORT // if current tablespace is cfs-compressed and md_get_compressor_internal // returns the type of the compressing algorithm for filepath, then it // needs to be de-compressed to obtain its size @@ -611,7 +611,7 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid) { DIR *dir; struct dirent *de; -#ifdef PGPRO_EE +#if CFS_SUPPORT bool is_cfs; #endif @@ -622,7 +622,7 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid) || InitializingParallelWorker) return; -#ifdef PGPRO_EE +#if CFS_SUPPORT is_cfs = file_is_in_cfs_tablespace(path); #endif @@ -653,7 +653,7 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid) } if (S_ISREG(fst.st_mode)) -#ifdef PGPRO_EE +#if CFS_SUPPORT ptrack_mark_file(dbOid, tablespaceOid, subpath, de->d_name, is_cfs); #else ptrack_mark_file(dbOid, tablespaceOid, subpath, de->d_name); diff --git a/engine.h b/engine.h index 4797a54..d76dc25 100644 --- a/engine.h +++ b/engine.h @@ -44,6 +44,9 @@ #define PTRACK_MAGIC "ptk" #define PTRACK_MAGIC_SIZE 4 +/* CFS support macro */ +#define CFS_SUPPORT (defined(PGPRO_EE) && PG_VERSION_NUM >= 120000) + /* * Header of ptrack map. */ diff --git a/ptrack.c b/ptrack.c index 933227a..ab64990 100644 --- a/ptrack.c +++ b/ptrack.c @@ -294,7 +294,7 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid) { DIR *dir; struct dirent *de; -#ifdef PGPRO_EE +#if CFS_SUPPORT bool is_cfs; is_cfs = file_is_in_cfs_tablespace(path); @@ -360,7 +360,7 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid) nodeSpc(pfl->relnode) = spcOid == InvalidOid ? DEFAULTTABLESPACE_OID : spcOid; pfl->path = GetRelationPath(dbOid, nodeSpc(pfl->relnode), nodeRel(pfl->relnode), InvalidBackendId, pfl->forknum); -#ifdef PGPRO_EE +#if CFS_SUPPORT pfl->is_cfs_compressed = is_cfs && md_get_compressor_internal(pfl->relnode, InvalidBackendId, pfl->forknum) != 0; #endif @@ -406,7 +406,7 @@ ptrack_filelist_getnext(PtScanCtx * ctx) char *fullpath; struct stat fst; off_t rel_st_size = 0; -#ifdef PGPRO_EE +#if CFS_SUPPORT RelFileNodeBackend rnodebackend; #endif @@ -455,7 +455,7 @@ ptrack_filelist_getnext(PtScanCtx * ctx) return ptrack_filelist_getnext(ctx); } -#ifdef PGPRO_EE +#if CFS_SUPPORT rnodebackend.node = ctx->bid.relnode; rnodebackend.backend = InvalidBackendId; From 2810f4c10bc1f0eb77e234ca279afb95ac68fad1 Mon Sep 17 00:00:00 2001 From: Daniel Shelepanov Date: Fri, 2 Dec 2022 21:29:03 +0300 Subject: [PATCH 2/3] [PBCKP-278] Full 16devel compatibility (so far) --- engine.c | 4 ++-- ptrack.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engine.c b/engine.c index 72b7e7b..bed5e42 100644 --- a/engine.c +++ b/engine.c @@ -120,7 +120,7 @@ get_cfs_relation_file_decompressed_size(RelFileNodeBackend rnode, const char *fu int compressor; off_t size; - compressor = md_get_compressor_internal(rnode.node, rnode.backend, forknum); + compressor = md_get_compressor_internal(nodeOf(rnode), rnode.backend, forknum); fd = PathNameOpenFile(fullpath, O_RDWR | PG_BINARY, compressor); if(fd < 0) @@ -580,7 +580,7 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid, // if current tablespace is cfs-compressed and md_get_compressor_internal // returns the type of the compressing algorithm for filepath, then it // needs to be de-compressed to obtain its size - if(is_cfs && md_get_compressor_internal(rnode.node, rnode.backend, forknum) != 0) { + if(is_cfs && md_get_compressor_internal(nodeOf(rnode), rnode.backend, forknum) != 0) { rel_size = get_cfs_relation_file_decompressed_size(rnode, filepath, forknum); if(rel_size == (off_t)-1) { diff --git a/ptrack.c b/ptrack.c index ab64990..bde2d49 100644 --- a/ptrack.c +++ b/ptrack.c @@ -456,7 +456,7 @@ ptrack_filelist_getnext(PtScanCtx * ctx) } #if CFS_SUPPORT - rnodebackend.node = ctx->bid.relnode; + nodeOf(rnodebackend) = ctx->bid.relnode; rnodebackend.backend = InvalidBackendId; if(pfl->is_cfs_compressed) { From d3b427bbecd5720f442c0a54aa75940d44365d40 Mon Sep 17 00:00:00 2001 From: Daniel Shelepanov Date: Mon, 5 Dec 2022 17:28:54 +0300 Subject: [PATCH 3/3] [PBCKP-278] minor macro fix --- engine.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine.h b/engine.h index d76dc25..3ba868c 100644 --- a/engine.h +++ b/engine.h @@ -45,7 +45,9 @@ #define PTRACK_MAGIC_SIZE 4 /* CFS support macro */ -#define CFS_SUPPORT (defined(PGPRO_EE) && PG_VERSION_NUM >= 120000) +#if defined(PGPRO_EE) && PG_VERSION_NUM >= 120000 +#define CFS_SUPPORT 1 +#endif /* * Header of ptrack map.