@@ -943,6 +943,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
943
943
uint32 second_pass_bytes = 0 ;
944
944
inode_t * * inodes = (inode_t * * )palloc (RELSEG_SIZE * sizeof (inode_t * ));
945
945
bool remove_backups = true;
946
+ bool got_lock = false;
946
947
int second_pass_whole = 0 ;
947
948
int n_pages , n_pages1 ;
948
949
TimestampTz startTime , secondTime , endTime ;
@@ -998,6 +999,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
998
999
retry :
999
1000
/* temporary lock file for fetching map snapshot */
1000
1001
cfs_gc_lock (lock );
1002
+ got_lock = true;
1001
1003
1002
1004
/* Reread variables after locking file */
1003
1005
physSize = pg_atomic_read_u32 (& map -> hdr .physSize );
@@ -1013,6 +1015,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1013
1015
}
1014
1016
/* may unlock until second phase */
1015
1017
cfs_gc_unlock (lock );
1018
+ got_lock = false;
1016
1019
1017
1020
if (!cfs_copy_inodes (inodes , n_pages , fd , fd2 , & writeback , & newSize ,
1018
1021
file_path , file_bck_path ))
@@ -1034,6 +1037,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1034
1037
secondTime = GetCurrentTimestamp ();
1035
1038
1036
1039
cfs_gc_lock (lock );
1040
+ got_lock = true;
1037
1041
1038
1042
/* Reread variables after locking file */
1039
1043
n_pages1 = n_pages ;
@@ -1087,6 +1091,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1087
1091
if (second_pass_whole == 1 && physSize < CFS_RETRY_GC_THRESHOLD )
1088
1092
{
1089
1093
cfs_gc_unlock (lock );
1094
+ got_lock = false;
1090
1095
/* sleep, cause there is possibly checkpoint is on a way */
1091
1096
pg_usleep (CFS_LOCK_MAX_TIMEOUT );
1092
1097
second_pass = 0 ;
@@ -1285,7 +1290,8 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1285
1290
else
1286
1291
remove_backups = true; /* we don't need backups anymore */
1287
1292
1288
- cfs_gc_unlock (lock );
1293
+ if (got_lock )
1294
+ cfs_gc_unlock (lock );
1289
1295
1290
1296
/* remove map backup file */
1291
1297
if (remove_backups && unlink (map_bck_path ))
0 commit comments