Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit595ce54

Browse files
author
Daniel Shelepanov
committed
[PBCKP-278] Review fixes, including:
* Refactoring: get_cfs_relation_decompressed_size => get_cfs_relation_file_decompressed_size* The file status returned by file_is_in_cfs_tablespace moved to an outer scopetags: cfs,ptrack
1 parentd4e7b32 commit595ce54

File tree

5 files changed

+54
-36
lines changed

5 files changed

+54
-36
lines changed

‎engine.c‎

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include"port/pg_crc32c.h"
3939
#ifdefPGPRO_EE
4040
/* For file_is_in_cfs_tablespace() only. */
41-
#include"replication/basebackup.h"
41+
#include"common/cfs_common.h"
4242
#endif
4343
#include"storage/copydir.h"
4444
#ifPG_VERSION_NUM >=120000
@@ -99,34 +99,21 @@ ptrack_write_chunk(int fd, pg_crc32c *crc, char *chunk, size_t size)
9999
* Determines a file type which is one of the following:
100100
* * regular relation file
101101
* * regular relation file which is a part of a multifile relation
102-
* * free space map
103-
* * visibility map
104-
* * compressed file map
102+
* * everythong else
105103
*/
106104
FileType
107105
file_type_from_path(constchar*filename) {
108106
ssize_tlen=strlen(filename);
109107
boolmet_dot;
108+
met_dot= false;
110109

111-
// For further length checks we assume that the filename is at least
112-
// 1 character longer than the corresponding extension. For example,
113-
// strlen("_vm") == 3 therefore we assume that the filename can't be
114-
// shorter than 4 bytes, for example: "5_vm".
115-
// visibility map
116-
if(len >=4&&strcmp(&filename[len-3],"_vm")==0)
117-
returnFileTypeVM;
118-
119-
// free space map
120-
if(len >=5&&strcmp(&filename[len-4],"_fsm")==0)
121-
returnFileTypeFSM;
122-
123-
// compressed file map
110+
// For this length checks we assume that the filename is at least
111+
// 1 character longer than the corresponding extension ".cfm":
112+
// strlen(".cfm") == 4 therefore we assume that the filename can't be
113+
// shorter than 5 bytes, for example: "5.cfm".
124114
if(len >=5&&strcmp(&filename[len-4],".cfm")==0)
125115
returnFileTypeCFM;
126116

127-
// regular and multipart regular files
128-
met_dot= false;
129-
130117
// we expect filename to be ****/12345 or ****/12345.12
131118
for(ssize_ti=len-1;i >=0&&filename[i]!='/';i--) {
132119
if(isdigit(filename[i])!=0)
@@ -152,7 +139,7 @@ file_type_from_path(const char *filename) {
152139
* was not compressed.
153140
*/
154141
off_t
155-
get_cfs_relation_decompressed_size(RelFileNodeBackendrnode,constchar*fullpath,ForkNumberforknum) {
142+
get_cfs_relation_file_decompressed_size(RelFileNodeBackendrnode,constchar*fullpath,ForkNumberforknum) {
156143
Filefd;
157144
intcompressor;
158145
off_tsize;
@@ -577,8 +564,13 @@ assign_ptrack_map_size(int newval, void *extra)
577564
* For use in functions that copy directories bypassing buffer manager.
578565
*/
579566
staticvoid
567+
#ifdefPGPRO_EE
568+
ptrack_mark_file(OiddbOid,OidtablespaceOid,
569+
constchar*filepath,constchar*filename,boolis_cfs)
570+
#else
580571
ptrack_mark_file(OiddbOid,OidtablespaceOid,
581572
constchar*filepath,constchar*filename)
573+
#endif
582574
{
583575
RelFileNodeBackendrnode;
584576
ForkNumberforknum;
@@ -590,8 +582,6 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid,
590582
#ifdefPGPRO_EE
591583
FileTypefile_type;
592584
off_trel_size;
593-
boolis_cfs;
594-
is_cfs=file_is_in_cfs_tablespace(filepath);
595585
#endif
596586

597587
/* Do not track temporary relations */
@@ -614,8 +604,9 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid,
614604
#ifdefPGPRO_EE
615605
file_type=file_type_from_path(filepath);
616606

617-
if(is_cfs&&file_type!=FileTypeCFM) {
618-
rel_size=get_cfs_relation_decompressed_size(rnode,filepath,forknum);
607+
if(is_cfs&& (file_type==FileTypeMain
608+
||file_type==FileTypeMainMulti)) {
609+
rel_size=get_cfs_relation_file_decompressed_size(rnode,filepath,forknum);
619610

620611
if(rel_size== (off_t)-1) {
621612
elog(WARNING,"ptrack: could not open cfs-compressed relation file: %s",filepath);
@@ -645,14 +636,22 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
645636
{
646637
DIR*dir;
647638
structdirent*de;
639+
#ifdefPGPRO_EE
640+
boolis_cfs;
641+
#endif
648642

643+
// TODO: file_is_in_cfs_tablespace(path);
649644
/* Do not walk during bootstrap and if ptrack is disabled */
650645
if (ptrack_map_size==0
651646
||DataDir==NULL
652647
||IsBootstrapProcessingMode()
653648
||InitializingParallelWorker)
654649
return;
655650

651+
#ifdefPGPRO_EE
652+
is_cfs=file_is_in_cfs_tablespace(path);
653+
#endif
654+
656655
dir=AllocateDir(path);
657656

658657
while ((de=ReadDirExtended(dir,path,LOG))!=NULL)
@@ -680,7 +679,11 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
680679
}
681680

682681
if (S_ISREG(fst.st_mode))
682+
#ifdefPGPRO_EE
683+
ptrack_mark_file(dbOid,tablespaceOid,subpath,de->d_name,is_cfs);
684+
#else
683685
ptrack_mark_file(dbOid,tablespaceOid,subpath,de->d_name);
686+
#endif
684687
}
685688

686689
FreeDir(dir);/* we ignore any error here */

‎engine.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ typedef enum {
7777
FileTypeUnknown,
7878
FileTypeMain,
7979
FileTypeMainMulti,
80-
FileTypeFSM,
81-
FileTypeVM,
8280
FileTypeCFM
8381
}FileType;
8482

@@ -122,7 +120,7 @@ extern void ptrack_mark_block(RelFileNodeBackend smgr_rnode,
122120

123121
externFileTypefile_type_from_path(constchar*path);
124122
#ifdefPGPRO_EE
125-
externoff_tget_cfs_relation_decompressed_size(RelFileNodeBackendrnode,
123+
externoff_tget_cfs_relation_file_decompressed_size(RelFileNodeBackendrnode,
126124
constchar*fullpath,ForkNumberforknum);
127125
#endif
128126

‎ptrack.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
294294
{
295295
DIR*dir;
296296
structdirent*de;
297+
#ifdefPGPRO_EE
298+
boolis_cfs;
299+
is_cfs=file_is_in_cfs_tablespace(path);
300+
#endif
297301

298302
dir=AllocateDir(path);
299303

@@ -348,6 +352,9 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
348352
else
349353
pfl->segno=0;
350354

355+
#ifdefPGPRO_EE
356+
pfl->is_cfs_compressed=is_cfs;
357+
#endif
351358
memcpy(oidbuf,de->d_name,oidchars);
352359
oidbuf[oidchars]='\0';
353360
nodeRel(pfl->relnode)=atooid(oidbuf);
@@ -396,7 +403,7 @@ ptrack_filelist_getnext(PtScanCtx * ctx)
396403
ListCell*cell;
397404
char*fullpath;
398405
structstatfst;
399-
off_trel_st_size;
406+
off_trel_st_size=0;
400407
#ifdefPGPRO_EE
401408
RelFileNodeBackendrnodebackend;
402409
#endif
@@ -450,10 +457,11 @@ ptrack_filelist_getnext(PtScanCtx * ctx)
450457
rnodebackend.node=ctx->bid.relnode;
451458
rnodebackend.backend=InvalidBackendId;
452459

453-
rel_st_size=get_cfs_relation_decompressed_size(rnodebackend,fullpath,pfl->forknum);
454-
#else
455-
rel_st_size=fst.st_size;
460+
if(pfl->is_cfs_compressed)
461+
rel_st_size=get_cfs_relation_file_decompressed_size(rnodebackend,fullpath,pfl->forknum);
462+
else
456463
#endif
464+
rel_st_size=fst.st_size;
457465

458466
if (pfl->segno>0)
459467
{

‎ptrack.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ typedef struct PtrackFileList_i
7878
ForkNumberforknum;
7979
intsegno;
8080
char*path;
81+
#ifdefPGPRO_EE
82+
boolis_cfs_compressed;
83+
#endif
8184
}PtrackFileList_i;
8285

8386
#endif/* PTRACK_H */

‎t/002_cfs_compatibility.pl‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ BEGIN
107107
# obtaining init lsn for further usage in ptrack_get_pagemapset
108108
my$init_lsn =$node->safe_psql('postgres','select ptrack_init_lsn()');
109109

110+
# forcing copydir() hook by altering dbs tablespaces
111+
$node->safe_psql('postgres',"alter database testing_cfs set tablespace cfs_tblspc2;");
112+
$node->safe_psql('postgres',"alter database testing_no_cfs set tablespace no_cfs_tblspc2;");
113+
110114
# obtaining relpath for cfs table
111115
my$cfs_relpath =$node->safe_psql('testing_cfs',"select pg_relation_filepath('testing');");
112116

113117
# obtaining relpath for no-cfs table
114118
my$no_cfs_relpath =$node->safe_psql('testing_no_cfs',"select pg_relation_filepath('testing_no');");
115119

116-
# forcing copydir() hook by altering dbs tablespaces
117-
$node->safe_psql('postgres',"alter database testing_cfs set tablespace cfs_tblspc2;");
118-
$node->safe_psql('postgres',"alter database testing_no_cfs set tablespace no_cfs_tblspc2;");
119-
120120
# select the pagecount sums and compare them (should be equal)
121121
my$pagecount_sum_cfs =$node->safe_psql('postgres',
122122
"select sum(pagecount) from ptrack_get_pagemapset('$init_lsn'::pg_lsn) where path like '%$cfs_relpath%';");
@@ -129,6 +129,12 @@ BEGIN
129129
$node->safe_psql('postgres',"alter database testing_cfs set tablespace cfs_tblspc1;");
130130
$node->safe_psql('postgres',"alter database testing_no_cfs set tablespace no_cfs_tblspc1;");
131131

132+
# obtaining new relpath for cfs table
133+
$cfs_relpath =$node->safe_psql('testing_cfs',"select pg_relation_filepath('testing');");
134+
135+
# obtaining new relpath for no-cfs table
136+
$no_cfs_relpath =$node->safe_psql('testing_no_cfs',"select pg_relation_filepath('testing_no');");
137+
132138
# select the pagecount sums and compare them (again, they should be equal)
133139
$pagecount_sum_cfs =$node->safe_psql('postgres',
134140
"select sum(pagecount) from ptrack_get_pagemapset('$init_lsn'::pg_lsn) where path like '%$cfs_relpath%';");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp