You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-07-15 07:04:14 +02:00
Add lock free algorithm for load balancing.
This commit is contained in:
14
backup.c
14
backup.c
@ -315,6 +315,8 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
|
|||||||
{
|
{
|
||||||
total_files_num++;
|
total_files_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__sync_lock_release(&file->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_threads < 1)
|
if (num_threads < 1)
|
||||||
@ -329,20 +331,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
|
|||||||
backup_files_args *arg = pg_malloc(sizeof(backup_files_args));
|
backup_files_args *arg = pg_malloc(sizeof(backup_files_args));
|
||||||
arg->from_root = pgdata;
|
arg->from_root = pgdata;
|
||||||
arg->to_root = path;
|
arg->to_root = path;
|
||||||
arg->files = parray_new();
|
arg->files = backup_files_list;
|
||||||
arg->prev_files = prev_files;
|
arg->prev_files = prev_files;
|
||||||
arg->lsn = lsn;
|
arg->lsn = lsn;
|
||||||
backup_threads_args[i] = arg;
|
backup_threads_args[i] = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* balance load between threads */
|
|
||||||
for (i = 0; i < parray_num(backup_files_list); i++)
|
|
||||||
{
|
|
||||||
int cur_thread = i % num_threads;
|
|
||||||
parray_append(backup_threads_args[cur_thread]->files,
|
|
||||||
parray_get(backup_files_list, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
total_copy_files_increment = 0;
|
total_copy_files_increment = 0;
|
||||||
|
|
||||||
/* Run threads */
|
/* Run threads */
|
||||||
@ -935,6 +929,8 @@ backup_files(void *arg)
|
|||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
pgFile *file = (pgFile *) parray_get(arguments->files, i);
|
pgFile *file = (pgFile *) parray_get(arguments->files, i);
|
||||||
|
if (__sync_lock_test_and_set(&file->lock, 1) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* If current time is rewinded, abort this backup. */
|
/* If current time is rewinded, abort this backup. */
|
||||||
if (tv.tv_sec < file->mtime)
|
if (tv.tv_sec < file->mtime)
|
||||||
|
@ -61,6 +61,7 @@ typedef struct pgFile
|
|||||||
char *path; /* path of the file */
|
char *path; /* path of the file */
|
||||||
char *ptrack_path;
|
char *ptrack_path;
|
||||||
int segno; /* Segment number for ptrack */
|
int segno; /* Segment number for ptrack */
|
||||||
|
volatile uint32 lock;
|
||||||
datapagemap_t pagemap;
|
datapagemap_t pagemap;
|
||||||
} pgFile;
|
} pgFile;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user