27 static HANDLE *thread_handles;
43 } transfer_thread_arg;
45 static exec_thread_arg **exec_thread_args;
46 static transfer_thread_arg **transfer_thread_args;
49 static void **cur_thread_args;
51 DWORD win32_exec_prog(exec_thread_arg *
args);
52 DWORD win32_transfer_all_new_dbs(transfer_thread_arg *
args);
72 exec_thread_arg *new_arg;
86 if (thread_handles == NULL)
89 if (exec_thread_args == NULL)
101 exec_thread_args[
i] =
pg_malloc0(
sizeof(exec_thread_arg));
104 cur_thread_args = (
void **) exec_thread_args;
127 pg_fatal(
"could not create worker process: %m");
135 pg_free(new_arg->opt_log_file);
136 new_arg->opt_log_file = opt_log_file ?
pg_strdup(opt_log_file) : NULL;
140 child = (HANDLE) _beginthreadex(NULL, 0, (
void *) win32_exec_prog,
143 pg_fatal(
"could not create worker thread: %m");
153 win32_exec_prog(exec_thread_arg *
args)
173 char *old_pgdata,
char *new_pgdata,
174 char *old_tablespace)
180 transfer_thread_arg *new_arg;
189 if (thread_handles == NULL)
192 if (transfer_thread_args == NULL)
204 transfer_thread_args[
i] =
pg_malloc0(
sizeof(transfer_thread_arg));
207 cur_thread_args = (
void **) transfer_thread_args;
235 pg_fatal(
"could not create worker process: %m");
241 new_arg->old_db_arr = old_db_arr;
242 new_arg->new_db_arr = new_db_arr;
244 new_arg->old_pgdata =
pg_strdup(old_pgdata);
246 new_arg->new_pgdata =
pg_strdup(new_pgdata);
247 pg_free(new_arg->old_tablespace);
248 new_arg->old_tablespace = old_tablespace ?
pg_strdup(old_tablespace) : NULL;
250 child = (HANDLE) _beginthreadex(NULL, 0, (
void *) win32_transfer_all_new_dbs,
253 pg_fatal(
"could not create worker thread: %m");
263 win32_transfer_all_new_dbs(transfer_thread_arg *
args)
266 args->new_pgdata,
args->old_tablespace);
292 child = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
293 if (child == (pid_t) -1)
294 pg_fatal(
"%s() failed: %m",
"waitpid");
297 if (work_status != 0)
298 pg_fatal(
"child process exited abnormally: status %d", work_status);
301 thread_num = WaitForMultipleObjects(
parallel_jobs, thread_handles,
302 false, wait_for_child ? INFINITE : 0);
304 if (thread_num == WAIT_TIMEOUT || thread_num == WAIT_FAILED)
308 thread_num -= WAIT_OBJECT_0;
311 GetExitCodeThread(thread_handles[thread_num], &
res);
313 pg_fatal(
"child worker exited abnormally: %m");
316 CloseHandle(thread_handles[thread_num]);
323 thread_handles[thread_num] = thread_handles[
parallel_jobs - 1];
331 tmp_args = cur_thread_args[thread_num];
332 cur_thread_args[thread_num] = cur_thread_args[
parallel_jobs - 1];
bool exec_prog(const char *log_filename, const char *opt_log_file, bool report_error, bool exit_on_error, const char *fmt,...)
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata, char *old_tablespace)
bool reap_child(bool wait_for_child)
void parallel_exec_prog(const char *log_file, const char *opt_log_file, const char *fmt,...)
static void PGresult * res
void * pg_malloc0(size_t size)
char * pg_strdup(const char *in)
void * pg_malloc(size_t size)
static void const char * fmt
static void const char fflush(stdout)
void transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata, char *old_tablespace)