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

Commit 306ec73

Browse files
committed
Merge branch 'PGPROEE9_6_CFS_385' into PGPROEE9_6
2 parents e7a3243 + 22f9e7f commit 306ec73

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

src/backend/storage/file/cfs.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,16 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
987987
cfs_state->gc_stat.processedFiles += 1;
988988
cfs_gc_processed_segments += 1;
989989

990+
retry:
990991
/* temporary lock file for fetching map snapshot */
991992
cfs_gc_lock(lock);
992993

993994
/* Reread variables after locking file */
995+
physSize = pg_atomic_read_u32(&map->hdr.physSize);
994996
virtSize = pg_atomic_read_u32(&map->hdr.virtSize);
995997
n_pages = virtSize / BLCKSZ;
996-
retry:
998+
if (physSize >= CFS_RED_LINE)
999+
goto forceWhole;
9971000
for (i = 0; i < n_pages; i++)
9981001
{
9991002
newMap->inodes[i] = map->inodes[i];
@@ -1026,10 +1029,9 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10261029

10271030
/* Reread variables after locking file */
10281031
n_pages1 = n_pages;
1032+
physSize = pg_atomic_read_u32(&map->hdr.physSize);
10291033
virtSize = pg_atomic_read_u32(&map->hdr.virtSize);
10301034
n_pages = virtSize / BLCKSZ;
1031-
second_pass = 0;
1032-
second_pass_bytes = 0;
10331035

10341036
for (i = 0; i < n_pages; i++)
10351037
{
@@ -1074,10 +1076,16 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10741076
memset(newMap->inodes, 0, sizeof(newMap->inodes));
10751077
elog(LOG, "CFS: retry %d whole gc file %s", second_pass_whole,
10761078
file_path);
1077-
if (second_pass_whole == 1)
1079+
if (second_pass_whole == 1 && physSize < CFS_RETRY_GC_THRESHOLD)
10781080
{
1081+
cfs_gc_unlock(lock);
1082+
/* sleep, cause there is possibly checkpoint is on a way */
1083+
pg_usleep(CFS_LOCK_MAX_TIMEOUT);
1084+
second_pass = 0;
1085+
second_pass_bytes = 0;
10791086
goto retry;
10801087
}
1088+
forceWhole:
10811089
for (i = 0; i < n_pages; i++)
10821090
{
10831091
newMap->inodes[i] = map->inodes[i];
@@ -1275,7 +1283,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
12751283
{
12761284
elog(LOG, "CFS GC worker %d: defragment file %s: old size %u, new size %u, logical size %u, used %u, compression ratio %f, time %ld usec; second pass: pages %u, bytes %u, time %ld"
12771285
,
1278-
MyProcPid, file_path, physSize, newSize, virtSize, usedSize, (double)virtSize/newSize,
1286+
MyProcPid, file_path, physSize, newSize, virtSize, newUsed, (double)virtSize/newSize,
12791287
secs*USECS_PER_SEC + usecs, second_pass, second_pass_bytes,
12801288
secs2*USECS_PER_SEC + usecs2);
12811289
}

src/backend/storage/smgr/md.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
451451
void
452452
mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo)
453453
{
454+
bool cfs_gc_locked = false;
454455
/*
455456
* We have to clean out any pending fsync requests for the doomed
456457
* relation, else the next mdsync() will fail. There can't be any such
@@ -461,14 +462,33 @@ mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo)
461462
if (!RelFileNodeBackendIsTemp(rnode))
462463
ForgetRelationFsyncRequests(rnode.node, forkNum);
463464

464-
/* Now do the per-fork work */
465-
if (forkNum == InvalidForkNumber)
465+
if (md_use_compression(rnode, forkNum == InvalidForkNumber ? MAIN_FORKNUM : forkNum))
466466
{
467-
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
467+
cfs_gc_locked = true;
468+
cfs_control_gc_lock();
469+
}
470+
471+
PG_TRY();
472+
{
473+
/* Now do the per-fork work */
474+
if (forkNum == InvalidForkNumber)
475+
{
476+
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
477+
mdunlinkfork(rnode, forkNum, isRedo);
478+
}
479+
else
468480
mdunlinkfork(rnode, forkNum, isRedo);
481+
}
469482
}
470-
else
471-
mdunlinkfork(rnode, forkNum, isRedo);
483+
PG_CATCH();
484+
{
485+
if (cfs_gc_locked)
486+
cfs_control_gc_unlock();
487+
PG_RE_THROW();
488+
}
489+
PG_END_TRY();
490+
if (cfs_gc_locked)
491+
cfs_control_gc_unlock();
472492
}
473493

474494
static void

src/include/storage/cfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef uint64 inode_t;
5353
#define CFS_INODE_CLEAN_FLAG ((inode_t)1 << 63)
5454

5555
#define CFS_IMPLICIT_GC_THRESHOLD 0x80000000U /* 2Gb */
56+
#define CFS_RETRY_GC_THRESHOLD 0x60000000U /* 1.5Gb */
5657
#define CFS_RED_LINE 0xC0000000U /* 3Gb */
5758

5859
size_t cfs_compress(void* dst, size_t dst_size, void const* src, size_t src_size);

0 commit comments

Comments
 (0)