@@ -987,13 +987,13 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
987987cfs_state -> gc_stat .processedFiles += 1 ;
988988cfs_gc_processed_segments += 1 ;
989989
990+ retry :
990991/* temporary lock file for fetching map snapshot */
991992cfs_gc_lock (lock );
992993
993994/* Reread variables after locking file */
994995virtSize = pg_atomic_read_u32 (& map -> hdr .virtSize );
995996n_pages = virtSize /BLCKSZ ;
996- retry :
997997for (i = 0 ;i < n_pages ;i ++ )
998998{
999999newMap -> inodes [i ]= map -> inodes [i ];
@@ -1026,10 +1026,9 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10261026
10271027/* Reread variables after locking file */
10281028n_pages1 = n_pages ;
1029+ physSize = pg_atomic_read_u32 (& map -> hdr .physSize );
10291030virtSize = pg_atomic_read_u32 (& map -> hdr .virtSize );
10301031n_pages = virtSize /BLCKSZ ;
1031- second_pass = 0 ;
1032- second_pass_bytes = 0 ;
10331032
10341033for (i = 0 ;i < n_pages ;i ++ )
10351034{
@@ -1074,8 +1073,13 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10741073memset (newMap -> inodes ,0 ,sizeof (newMap -> inodes ));
10751074elog (LOG ,"CFS: retry %d whole gc file %s" ,second_pass_whole ,
10761075file_path );
1077- if (second_pass_whole == 1 )
1076+ if (second_pass_whole == 1 && physSize < CFS_IMPLICIT_GC_THRESHOLD )
10781077{
1078+ cfs_gc_unlock (lock );
1079+ /* sleep, cause there is possibly checkpoint is on a way */
1080+ pg_usleep (CFS_LOCK_MAX_TIMEOUT );
1081+ second_pass = 0 ;
1082+ second_pass_bytes = 0 ;
10791083gotoretry ;
10801084}
10811085for (i = 0 ;i < n_pages ;i ++ )