Skip to content

Commit a3b9d1e

Browse files
committed
PGPRO-427: Add lock for datapagemap_add
1 parent 70257b3 commit a3b9d1e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backup.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const char *progname = "pg_probackup";
4646
/* list of files contained in backup */
4747
static parray *backup_files_list = NULL;
4848

49+
/* We need critical section for datapagemap_add() in case of using threads */
50+
static pthread_mutex_t backup_pagemap_mutex = PTHREAD_MUTEX_INITIALIZER;
51+
4952
/*
5053
* We need to wait end of WAL streaming before execute pg_stop_backup().
5154
*/
@@ -2333,8 +2336,17 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
23332336
* backup would simply copy it as-is.
23342337
*/
23352338
if (file_item)
2339+
{
2340+
/* We need critical section only we use more than one threads */
2341+
if (num_threads > 1)
2342+
pthread_mutex_lock(&backup_pagemap_mutex);
2343+
23362344
datapagemap_add(&(*file_item)->pagemap, blkno_inseg);
23372345

2346+
if (num_threads > 1)
2347+
pthread_mutex_unlock(&backup_pagemap_mutex);
2348+
}
2349+
23382350
pg_free(path);
23392351
}
23402352

0 commit comments

Comments
 (0)