@@ -987,13 +987,16 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
987
987
cfs_state -> gc_stat .processedFiles += 1 ;
988
988
cfs_gc_processed_segments += 1 ;
989
989
990
+ retry :
990
991
/* temporary lock file for fetching map snapshot */
991
992
cfs_gc_lock (lock );
992
993
993
994
/* Reread variables after locking file */
995
+ physSize = pg_atomic_read_u32 (& map -> hdr .physSize );
994
996
virtSize = pg_atomic_read_u32 (& map -> hdr .virtSize );
995
997
n_pages = virtSize / BLCKSZ ;
996
- retry :
998
+ if (physSize >= CFS_RED_LINE )
999
+ goto forceWhole ;
997
1000
for (i = 0 ; i < n_pages ; i ++ )
998
1001
{
999
1002
newMap -> inodes [i ] = map -> inodes [i ];
@@ -1026,10 +1029,9 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1026
1029
1027
1030
/* Reread variables after locking file */
1028
1031
n_pages1 = n_pages ;
1032
+ physSize = pg_atomic_read_u32 (& map -> hdr .physSize );
1029
1033
virtSize = pg_atomic_read_u32 (& map -> hdr .virtSize );
1030
1034
n_pages = virtSize / BLCKSZ ;
1031
- second_pass = 0 ;
1032
- second_pass_bytes = 0 ;
1033
1035
1034
1036
for (i = 0 ; i < n_pages ; i ++ )
1035
1037
{
@@ -1074,10 +1076,16 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1074
1076
memset (newMap -> inodes , 0 , sizeof (newMap -> inodes ));
1075
1077
elog (LOG , "CFS: retry %d whole gc file %s" , second_pass_whole ,
1076
1078
file_path );
1077
- if (second_pass_whole == 1 )
1079
+ if (second_pass_whole == 1 && physSize < CFS_RETRY_GC_THRESHOLD )
1078
1080
{
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 ;
1079
1086
goto retry ;
1080
1087
}
1088
+ forceWhole :
1081
1089
for (i = 0 ; i < n_pages ; i ++ )
1082
1090
{
1083
1091
newMap -> inodes [i ] = map -> inodes [i ];
@@ -1275,7 +1283,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1275
1283
{
1276
1284
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"
1277
1285
,
1278
- MyProcPid , file_path , physSize , newSize , virtSize , usedSize , (double )virtSize /newSize ,
1286
+ MyProcPid , file_path , physSize , newSize , virtSize , newUsed , (double )virtSize /newSize ,
1279
1287
secs * USECS_PER_SEC + usecs , second_pass , second_pass_bytes ,
1280
1288
secs2 * USECS_PER_SEC + usecs2 );
1281
1289
}
0 commit comments