Skip to content

Commit 839090d

Browse files
committed
PGPRO-102 #comment Add cfs_gc_activity function
1 parent c1a6f4f commit 839090d

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
void cfs_initialize()
280280
{
281281
cfs_state = (CfsState*)ShmemAlloc(sizeof(CfsState));
282+
memset(&cfs_state->gc_stat, 0, sizeof cfs_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
long delay = CFS_LOCK_MIN_TIMEOUT;
@@ -577,7 +580,8 @@ static bool cfs_gc_file(char* map_path)
577580
if (fd2 < 0) {
578581
goto Cleanup;
579582
}
580-
583+
cfs_state->gc_stat.processedFiles += 1;
584+
581585
for (i = 0; i < n_pages; i++) {
582586
int size = 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
goto Cleanup;
@@ -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
goto Cleanup;
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
Datum cfs_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+
Datum cfs_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_dist PGNSP 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_t cfs_decompress(void* dst, size_t dst_size, void const* src, size_t src_size);
4040
char const* 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+
typedef struct
48+
{
49+
uint64 scannedFiles;
50+
uint64 processedFiles;
51+
uint64 processedPages;
52+
uint64 processedBytes;
53+
} CfsStatistic;
54+
4255
typedef struct
4356
{
4457
pg_atomic_flag gc_started;
4558
int n_workers;
4659
int max_iterations;
4760
bool gc_enabled;
61+
CfsStatistic gc_stat;
4862
uint8 rc4_init_state[CFS_CIPHER_KEY_SIZE];
4963
} CfsState;
5064

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy