Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4b609bd

Browse files
committed
Refector CFS intialization
1 parent a72d35d commit 4b609bd

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

src/backend/storage/file/cfs.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -389,23 +389,31 @@ void cfs_decrypt(const char* fname, void* block, uint32 offs, uint32 size)
389389
* Section 3: Compression implementation.
390390
* ----------------------------------------------------------------
391391
*/
392-
void cfs_initialize()
392+
int cfs_shmem_size()
393393
{
394-
cfs_state = (CfsState*)ShmemAlloc(sizeof(CfsState));
395-
memset(&cfs_state->gc_stat, 0, sizeof cfs_state->gc_stat);
396-
pg_atomic_init_flag(&cfs_state->gc_started);
397-
pg_atomic_init_u32(&cfs_state->n_active_gc, 0);
398-
cfs_state->n_workers = 0;
399-
cfs_state->gc_enabled = cfs_gc_enabled;
400-
cfs_state->max_iterations = 0;
401-
402-
if (cfs_encryption)
403-
cfs_crypto_init();
404-
405-
elog(LOG, "Start CFS version %s compression algorithm %s encryption %s",
406-
CFS_VERSION, cfs_algorithm(), cfs_encryption ? "enabled" : "disabled");
394+
return sizeof(CfsState);
407395
}
408396

397+
void cfs_initialize()
398+
{
399+
bool found;
400+
cfs_state = (CfsState*)ShmemInitStruct("CFS Control", sizeof(CfsState), &found);
401+
if (!found)
402+
{
403+
memset(&cfs_state->gc_stat, 0, sizeof cfs_state->gc_stat);
404+
pg_atomic_init_flag(&cfs_state->gc_started);
405+
pg_atomic_init_u32(&cfs_state->n_active_gc, 0);
406+
cfs_state->n_workers = 0;
407+
cfs_state->gc_enabled = cfs_gc_enabled;
408+
cfs_state->max_iterations = 0;
409+
410+
if (cfs_encryption)
411+
cfs_crypto_init();
412+
413+
elog(LOG, "Start CFS version %s compression algorithm %s encryption %s GC %s",
414+
CFS_VERSION, cfs_algorithm(), cfs_encryption ? "enabled" : "disabled", cfs_gc_enabled ? "enabled" : "disabled");
415+
}
416+
}
409417
int cfs_msync(FileMap* map)
410418
{
411419
#ifdef WIN32
@@ -566,7 +574,7 @@ void cfs_lock_file(FileMap* map, char const* file_path)
566574
char* map_bck_path = psprintf("%s.cfm.bck", file_path);
567575
char* file_bck_path = psprintf("%s.bck", file_path);
568576

569-
elog(WARNING, "CFS indicates that GC of %s was interrupted: try to perform recovery", file_path);
577+
elog(WARNING, "CFS indicates that GC of %s was interrupted: trying to perform recovery", file_path);
570578

571579
if (access(file_bck_path, R_OK) != 0)
572580
{

src/backend/storage/ipc/ipci.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "storage/procsignal.h"
4545
#include "storage/sinvaladt.h"
4646
#include "storage/spin.h"
47+
#include "storage/cfs.h"
4748
#include "utils/snapmgr.h"
4849

4950

@@ -142,6 +143,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
142143
size = add_size(size, BTreeShmemSize());
143144
size = add_size(size, SyncScanShmemSize());
144145
size = add_size(size, AsyncShmemSize());
146+
size = add_size(size, cfs_shmem_size());
145147
#ifdef EXEC_BACKEND
146148
size = add_size(size, ShmemBackendArraySize());
147149
#endif
@@ -254,7 +256,8 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
254256
BTreeShmemInit();
255257
SyncScanShmemInit();
256258
AsyncShmemInit();
257-
259+
cfs_initialize();
260+
258261
/*
259262
* Init array of Latches in SHMEM for WAITLSN
260263
*/

src/backend/storage/lmgr/lwlocknames.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ CommitTsLock 39
4747
ReplicationOriginLock 40
4848
MultiXactTruncationLock 41
4949
OldSnapshotTimeMapLock 42
50+
CfsGcLock 43

src/backend/utils/misc/guc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10859,12 +10859,14 @@ static void set_cfs_gc_enabled(bool newval, void* extra)
1085910859
{
1086010860
cfs_gc_enabled = newval;
1086110861
if (cfs_state && MyProcPid == PostmasterPid)
10862-
cfs_control_gc(newval);
10862+
{
10863+
cfs_state->gc_enabled = newval;
10864+
}
1086310865
}
1086410866

1086510867
static char const* show_cfs_gc_enabled(void)
1086610868
{
10867-
return cfs_gc_enabled ? "on" : "off";
10869+
return (cfs_state ? cfs_state->gc_enabled : cfs_gc_enabled) ? "on" : "off";
1086810870
}
1086910871

1087010872

src/include/storage/cfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ int cfs_msync(FileMap* map);
119119
FileMap* cfs_mmap(int md);
120120
int cfs_munmap(FileMap* map);
121121
void cfs_initialize(void);
122+
int cfs_shmem_size(void);
122123

123124
void cfs_encrypt(const char* fname, void* block, uint32 offs, uint32 size);
124125
void cfs_decrypt(const char* fname, void* block, uint32 offs, uint32 size);

0 commit comments

Comments
 (0)