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

Commit839090d

Browse files
committed
PGPRO-102 #comment Add cfs_gc_activity function
1 parentc1a6f4f commit839090d

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

‎src/backend/storage/file/cfs.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ void cfs_decrypt(void* block, uint32 offs, uint32 size)
279279
voidcfs_initialize()
280280
{
281281
cfs_state= (CfsState*)ShmemAlloc(sizeof(CfsState));
282+
memset(&cfs_state->gc_stat,0,sizeofcfs_state->gc_stat);
282283
pg_atomic_init_flag(&cfs_state->gc_started);
283284
cfs_state->n_workers=0;
284285
cfs_state->gc_enabled= true;
@@ -492,7 +493,9 @@ static bool cfs_gc_file(char* map_path)
492493
usedSize=pg_atomic_read_u32(&map->usedSize);
493494
physSize=pg_atomic_read_u32(&map->physSize);
494495
virtSize=pg_atomic_read_u32(&map->virtSize);
495-
496+
497+
cfs_state->gc_stat.scannedFiles+=1;
498+
496499
if ((physSize-usedSize)*100>physSize*cfs_gc_threshold)/* do we need to perform defragmentation? */
497500
{
498501
longdelay=CFS_LOCK_MIN_TIMEOUT;
@@ -577,7 +580,8 @@ static bool cfs_gc_file(char* map_path)
577580
if (fd2<0) {
578581
gotoCleanup;
579582
}
580-
583+
cfs_state->gc_stat.processedFiles+=1;
584+
581585
for (i=0;i<n_pages;i++) {
582586
intsize=CFS_INODE_SIZE(*inodes[i]);
583587
if (size!=0) {
@@ -587,7 +591,7 @@ static bool cfs_gc_file(char* map_path)
587591
Assert(size <=BLCKSZ);
588592
rc=lseek(fd,offs,SEEK_SET);
589593
Assert(rc==offs);
590-
594+
591595
if (!cfs_read_file(fd,block,size)) {
592596
elog(LOG,"Failed to read file %s: %m",file_path);
593597
gotoCleanup;
@@ -597,6 +601,9 @@ static bool cfs_gc_file(char* map_path)
597601
elog(LOG,"Failed to write file %s: %m",file_bck_path);
598602
gotoCleanup;
599603
}
604+
cfs_state->gc_stat.processedBytes+=size;
605+
cfs_state->gc_stat.processedPages+=1;
606+
600607
offs=newSize;
601608
newSize+=size;
602609
*inodes[i]=CFS_INODE(size,offs);
@@ -832,6 +839,7 @@ PG_FUNCTION_INFO_V1(cfs_enable_gc);
832839
PG_FUNCTION_INFO_V1(cfs_version);
833840
PG_FUNCTION_INFO_V1(cfs_estimate);
834841
PG_FUNCTION_INFO_V1(cfs_compression_ratio);
842+
PG_FUNCTION_INFO_V1(cfs_gc_activity);
835843

836844
Datumcfs_start_gc(PG_FUNCTION_ARGS)
837845
{
@@ -974,3 +982,7 @@ Datum cfs_compression_ratio(PG_FUNCTION_ARGS)
974982
PG_RETURN_FLOAT8((double)virtSize/physSize);
975983
}
976984

985+
Datumcfs_gc_activity(PG_FUNCTION_ARGS)
986+
{
987+
PG_RETURN_INT64(cfs_state->gc_stat.processedBytes);
988+
}

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,6 +5350,8 @@ DATA(insert OID = 6103 ( cfs_estimate PGNSP PGUID 12 1 0 0 0 f f f f t f v
53505350
DESCR("Estimate relation compression ratio");
53515351
DATA(insert OID = 6019 ( cfs_compression_ratio PGNSP PGUID 12 1 0 0 0 f f f f t f v s 1 0 701 "2205" _null_ _null_ _null_ _null_ _null_ cfs_compression_ratio _null_ _null_ _null_ ));
53525352
DESCR("Compression ration of relation");
5353+
DATA(insert OID = 6020 ( cfs_gc_activity PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 20 "" _null_ _null_ _null_ _null_ _null_ cfs_gc_activity _null_ _null_ _null_ ));
5354+
DESCR("Number of bytes proceeded by CFS garbage collectors since system start");
53535355

53545356
/* distance functions */
53555357
DATA(insert OID = 3343 ( int2_distPGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 21 "21 21"_null_ _null_ _null_ _null_ _null_int2_dist_null_ _null_ _null_ ));

‎src/include/storage/cfs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,26 @@ size_t cfs_compress(void* dst, size_t dst_size, void const* src, size_t src_size
3939
size_tcfs_decompress(void*dst,size_tdst_size,voidconst*src,size_tsrc_size);
4040
charconst*cfs_algorithm(void);
4141

42+
/*
43+
* This structure is concurrently updated by several workers,
44+
* but since we collect this information only for statistic - do not use atomics here
45+
* Some inaccuracy is less critical than extra synchronization overhead.
46+
*/
47+
typedefstruct
48+
{
49+
uint64scannedFiles;
50+
uint64processedFiles;
51+
uint64processedPages;
52+
uint64processedBytes;
53+
}CfsStatistic;
54+
4255
typedefstruct
4356
{
4457
pg_atomic_flaggc_started;
4558
intn_workers;
4659
intmax_iterations;
4760
boolgc_enabled;
61+
CfsStatisticgc_stat;
4862
uint8rc4_init_state[CFS_CIPHER_KEY_SIZE];
4963
}CfsState;
5064

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp