1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-01-23 11:45:36 +02:00

Add lock free algorithm for load balancing.

This commit is contained in:
stalkerg 2016-09-02 20:38:39 +03:00
parent 6ce7163a8a
commit 3491b43404
2 changed files with 7 additions and 10 deletions

View File

@ -315,6 +315,8 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
{
total_files_num++;
}
__sync_lock_release(&file->lock);
}
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));
arg->from_root = pgdata;
arg->to_root = path;
arg->files = parray_new();
arg->files = backup_files_list;
arg->prev_files = prev_files;
arg->lsn = lsn;
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;
/* Run threads */
@ -935,6 +929,8 @@ backup_files(void *arg)
struct stat buf;
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 (tv.tv_sec < file->mtime)

View File

@ -56,11 +56,12 @@ typedef struct pgFile
that the file existed but was not backed up
because not modified since last backup. */
pg_crc32 crc; /* CRC value of the file, regular file only */
char *linked; /* path of the linked file */
char *linked; /* path of the linked file */
bool is_datafile; /* true if the file is PostgreSQL data file */
char *path; /* path of the file */
char *ptrack_path;
int segno; /* Segment number for ptrack */
volatile uint32 lock;
datapagemap_t pagemap;
} pgFile;