mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-01-09 14:45:47 +02:00
use dynamically allocated array for validate_threads
This commit is contained in:
parent
79ece89521
commit
14fa9542d4
@ -20,6 +20,16 @@
|
|||||||
#include "port/pthread-win32.h"
|
#include "port/pthread-win32.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
typedef struct win32_pthread *pthread_t;
|
||||||
|
typedef int pthread_attr_t;
|
||||||
|
#define PTHREAD_MUTEX_INITIALIZER NULL //{ NULL, 0 }
|
||||||
|
#define PTHREAD_ONCE_INIT false
|
||||||
|
|
||||||
|
int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
|
||||||
|
int pthread_join(pthread_t th, void **thread_return);
|
||||||
|
#endif
|
||||||
|
|
||||||
static void pgBackupValidateFiles(void *arg);
|
static void pgBackupValidateFiles(void *arg);
|
||||||
static void do_validate_instance(void);
|
static void do_validate_instance(void);
|
||||||
|
|
||||||
@ -41,8 +51,9 @@ pgBackupValidate(pgBackup *backup)
|
|||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
parray *files;
|
parray *files;
|
||||||
bool corrupted = false;
|
bool corrupted = false;
|
||||||
pthread_t validate_threads[num_threads];
|
/* arrays with meta info for multi threaded validate */
|
||||||
validate_files_args *validate_threads_args[num_threads];
|
pthread_t *validate_threads;
|
||||||
|
validate_files_args *validate_threads_args;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (backup->status != BACKUP_STATUS_OK &&
|
if (backup->status != BACKUP_STATUS_OK &&
|
||||||
@ -71,25 +82,31 @@ pgBackupValidate(pgBackup *backup)
|
|||||||
pg_atomic_clear_flag(&file->lock);
|
pg_atomic_clear_flag(&file->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* init thread args with own file lists */
|
||||||
|
validate_threads = (pthread_t *) palloc(sizeof(pthread_t)*num_threads);
|
||||||
|
validate_threads_args = (validate_files_args *) palloc(sizeof(validate_files_args)*num_threads);
|
||||||
|
|
||||||
/* Validate files */
|
/* Validate files */
|
||||||
for (i = 0; i < num_threads; i++)
|
for (i = 0; i < num_threads; i++)
|
||||||
{
|
{
|
||||||
validate_files_args *arg = pg_malloc(sizeof(validate_files_args));
|
validate_files_args *arg = &(validate_threads_args[i]);
|
||||||
arg->files = files;
|
arg->files = files;
|
||||||
arg->corrupted = false;
|
arg->corrupted = false;
|
||||||
validate_threads_args[i] = arg;
|
|
||||||
pthread_create(&validate_threads[i], NULL, (void *(*)(void *)) pgBackupValidateFiles, arg);
|
pthread_create(&validate_threads[i], NULL, (void *(*)(void *)) pgBackupValidateFiles, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait theads */
|
/* Wait theads */
|
||||||
for (i = 0; i < num_threads; i++)
|
for (i = 0; i < num_threads; i++)
|
||||||
{
|
{
|
||||||
|
validate_files_args *arg = &(validate_threads_args[i]);
|
||||||
pthread_join(validate_threads[i], NULL);
|
pthread_join(validate_threads[i], NULL);
|
||||||
if (validate_threads_args[i]->corrupted)
|
if (arg->corrupted)
|
||||||
corrupted = true;
|
corrupted = true;
|
||||||
pg_free(validate_threads_args[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pfree(validate_threads);
|
||||||
|
pfree(validate_threads_args);
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
parray_walk(files, pgFileFree);
|
parray_walk(files, pgFileFree);
|
||||||
parray_free(files);
|
parray_free(files);
|
||||||
|
Loading…
Reference in New Issue
Block a user