From: Bruce Momjian Date: Wed, 24 Jul 2013 17:15:47 +0000 (-0400) Subject: pg_upgrade: more Windows parallel/-j fixes X-Git-Tag: REL9_3_RC1~49 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a67a9ac13495d69b4d3b560b63cafda9318b4f4;p=postgresql pg_upgrade: more Windows parallel/-j fixes More fixes to handle Windows thread parameter passing. Backpatch to 9.3 beta. Patch originally from Andrew Dunstan --- diff --git a/contrib/pg_upgrade/parallel.c b/contrib/pg_upgrade/parallel.c index bf52890ad4..caeebcd9d0 100644 --- a/contrib/pg_upgrade/parallel.c +++ b/contrib/pg_upgrade/parallel.c @@ -32,18 +32,18 @@ HANDLE *thread_handles; typedef struct { - char log_file[MAXPGPATH]; - char opt_log_file[MAXPGPATH]; - char cmd[MAX_STRING]; + char *log_file; + char *opt_log_file; + char *cmd; } exec_thread_arg; typedef struct { DbInfoArr *old_db_arr; DbInfoArr *new_db_arr; - char old_pgdata[MAXPGPATH]; - char new_pgdata[MAXPGPATH]; - char old_tablespace[MAXPGPATH]; + char *old_pgdata; + char *new_pgdata; + char *old_tablespace; } transfer_thread_arg; exec_thread_arg **exec_thread_args; @@ -113,10 +113,12 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file, pg_log(PG_FATAL, "could not create worker process: %s\n", strerror(errno)); #else if (thread_handles == NULL) + thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE)); + + if (exec_thread_args == NULL) { int i; - thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE)); exec_thread_args = pg_malloc(user_opts.jobs * sizeof(exec_thread_arg *)); /* @@ -125,16 +127,22 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file, * thread different from the one that allocated it. */ for (i = 0; i < user_opts.jobs; i++) - exec_thread_args[i] = pg_malloc(sizeof(exec_thread_arg)); + exec_thread_args[i] = pg_malloc0(sizeof(exec_thread_arg)); } /* use first empty array element */ new_arg = exec_thread_args[parallel_jobs - 1]; /* Can only pass one pointer into the function, so use a struct */ - strcpy(new_arg->log_file, log_file); - strcpy(new_arg->opt_log_file, opt_log_file); - strcpy(new_arg->cmd, cmd); + if (new_arg->log_file) + pg_free(new_arg->log_file); + new_arg->log_file = pg_strdup(log_file); + if (new_arg->opt_log_file) + pg_free(new_arg->opt_log_file); + new_arg->opt_log_file = opt_log_file ? pg_strdup(opt_log_file) : NULL; + if (new_arg->cmd) + pg_free(new_arg->cmd); + new_arg->cmd = pg_strdup(cmd); child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_exec_prog, new_arg, 0, NULL); @@ -219,10 +227,12 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, pg_log(PG_FATAL, "could not create worker process: %s\n", strerror(errno)); #else if (thread_handles == NULL) + thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE)); + + if (transfer_thread_args == NULL) { int i; - thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE)); transfer_thread_args = pg_malloc(user_opts.jobs * sizeof(transfer_thread_arg *)); /* @@ -231,7 +241,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, * thread different from the one that allocated it. */ for (i = 0; i < user_opts.jobs; i++) - transfer_thread_args[i] = pg_malloc(sizeof(transfer_thread_arg)); + transfer_thread_args[i] = pg_malloc0(sizeof(transfer_thread_arg)); } /* use first empty array element */ @@ -240,9 +250,15 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, /* Can only pass one pointer into the function, so use a struct */ new_arg->old_db_arr = old_db_arr; new_arg->new_db_arr = new_db_arr; - strcpy(new_arg->old_pgdata, old_pgdata); - strcpy(new_arg->new_pgdata, new_pgdata); - strcpy(new_arg->old_tablespace, old_tablespace); + if (new_arg->old_pgdata) + pg_free(new_arg->old_pgdata); + new_arg->old_pgdata = pg_strdup(old_pgdata); + if (new_arg->new_pgdata) + pg_free(new_arg->new_pgdata); + new_arg->new_pgdata = pg_strdup(new_pgdata); + if (new_arg->old_tablespace) + pg_free(new_arg->old_tablespace); + new_arg->old_tablespace = old_tablespace ? pg_strdup(old_tablespace) : NULL; child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_transfer_all_new_dbs, new_arg, 0, NULL); diff --git a/contrib/pg_upgrade/test.sh b/contrib/pg_upgrade/test.sh index e1db376155..30bc527431 100644 --- a/contrib/pg_upgrade/test.sh +++ b/contrib/pg_upgrade/test.sh @@ -152,7 +152,7 @@ PGDATA=$BASE_PGDATA initdb -N -pg_upgrade -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" -p "$PGPORT" -P "$PGPORT" +pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" -p "$PGPORT" -P "$PGPORT" pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w