1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-01-25 11:53:32 +02:00

use dynamically allocated array for restore_threads

This commit is contained in:
Anastasia 2018-03-13 15:24:49 +03:00
parent f0547f46a1
commit 990ccd32fc

View File

@ -349,8 +349,10 @@ restore_backup(pgBackup *backup)
char list_path[MAXPGPATH]; char list_path[MAXPGPATH];
parray *files; parray *files;
int i; int i;
pthread_t restore_threads[num_threads]; /* arrays with meta info for multi threaded backup */
restore_files_args *restore_threads_args[num_threads]; pthread_t *restore_threads;
restore_files_args *restore_threads_args;
if (backup->status != BACKUP_STATUS_OK) if (backup->status != BACKUP_STATUS_OK)
elog(ERROR, "Backup %s cannot be restored because it is not valid", elog(ERROR, "Backup %s cannot be restored because it is not valid",
@ -394,6 +396,9 @@ restore_backup(pgBackup *backup)
pgFileFree(parray_remove(files, i)); pgFileFree(parray_remove(files, i));
} }
restore_threads = (pthread_t *) palloc(sizeof(pthread_t)*num_threads);
restore_threads_args = (restore_files_args *) palloc(sizeof(restore_files_args)*num_threads);
/* setup threads */ /* setup threads */
for (i = 0; i < parray_num(files); i++) for (i = 0; i < parray_num(files); i++)
{ {
@ -404,13 +409,13 @@ restore_backup(pgBackup *backup)
/* Restore files into target directory */ /* Restore files into target directory */
for (i = 0; i < num_threads; i++) for (i = 0; i < num_threads; i++)
{ {
restore_files_args *arg = pg_malloc(sizeof(restore_files_args)); restore_files_args *arg = &(restore_threads_args[i]);
arg->files = files; arg->files = files;
arg->backup = backup; arg->backup = backup;
elog(LOG, "Start thread for num:%li", parray_num(files)); elog(LOG, "Start thread for num:%li", parray_num(files));
restore_threads_args[i] = arg;
pthread_create(&restore_threads[i], NULL, (void *(*)(void *)) restore_files, arg); pthread_create(&restore_threads[i], NULL, (void *(*)(void *)) restore_files, arg);
} }
@ -418,9 +423,11 @@ restore_backup(pgBackup *backup)
for (i = 0; i < num_threads; i++) for (i = 0; i < num_threads; i++)
{ {
pthread_join(restore_threads[i], NULL); pthread_join(restore_threads[i], NULL);
pg_free(restore_threads_args[i]);
} }
pfree(restore_threads);
pfree(restore_threads_args);
/* cleanup */ /* cleanup */
parray_walk(files, pgFileFree); parray_walk(files, pgFileFree);
parray_free(files); parray_free(files);