Skip to content

Commit 8ed3154

Browse files
author
Sokolov Yura
committed
cfs.c: fix erroneous unlocking on write error
1 parent 163a4c4 commit 8ed3154

File tree

1 file changed

+7
-1
lines changed
  • src/backend/storage/file

1 file changed

+7
-1
lines changed

src/backend/storage/file/cfs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
943943
uint32 second_pass_bytes = 0;
944944
inode_t** inodes = (inode_t**)palloc(RELSEG_SIZE*sizeof(inode_t*));
945945
bool remove_backups = true;
946+
bool got_lock = false;
946947
int second_pass_whole = 0;
947948
int n_pages, n_pages1;
948949
TimestampTz startTime, secondTime, endTime;
@@ -998,6 +999,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
998999
retry:
9991000
/* temporary lock file for fetching map snapshot */
10001001
cfs_gc_lock(lock);
1002+
got_lock = true;
10011003

10021004
/* Reread variables after locking file */
10031005
physSize = pg_atomic_read_u32(&map->hdr.physSize);
@@ -1013,6 +1015,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10131015
}
10141016
/* may unlock until second phase */
10151017
cfs_gc_unlock(lock);
1018+
got_lock = false;
10161019

10171020
if (!cfs_copy_inodes(inodes, n_pages, fd, fd2, &writeback, &newSize,
10181021
file_path, file_bck_path))
@@ -1034,6 +1037,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10341037
secondTime = GetCurrentTimestamp();
10351038

10361039
cfs_gc_lock(lock);
1040+
got_lock = true;
10371041

10381042
/* Reread variables after locking file */
10391043
n_pages1 = n_pages;
@@ -1087,6 +1091,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
10871091
if (second_pass_whole == 1 && physSize < CFS_RETRY_GC_THRESHOLD)
10881092
{
10891093
cfs_gc_unlock(lock);
1094+
got_lock = false;
10901095
/* sleep, cause there is possibly checkpoint is on a way */
10911096
pg_usleep(CFS_LOCK_MAX_TIMEOUT);
10921097
second_pass = 0;
@@ -1285,7 +1290,8 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
12851290
else
12861291
remove_backups = true; /* we don't need backups anymore */
12871292

1288-
cfs_gc_unlock(lock);
1293+
if (got_lock)
1294+
cfs_gc_unlock(lock);
12891295

12901296
/* remove map backup file */
12911297
if (remove_backups && unlink(map_bck_path))

0 commit comments

Comments
 (0)