]> granicus.if.org Git - postgresql/commitdiff
pg_upgrade: more Windows parallel/-j fixes
authorBruce Momjian <bruce@momjian.us>
Wed, 24 Jul 2013 17:15:47 +0000 (13:15 -0400)
committerBruce Momjian <bruce@momjian.us>
Wed, 24 Jul 2013 17:15:47 +0000 (13:15 -0400)
More fixes to handle Windows thread parameter passing.
Backpatch to 9.3 beta.
Patch originally from Andrew Dunstan

contrib/pg_upgrade/parallel.c
contrib/pg_upgrade/test.sh

index bf52890ad45e50ff17ff87a974c8dcba8e4f5c41..caeebcd9d0797639268340f424d3a4a4e610be7f 100644 (file)
@@ -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);
index e1db3761558e534a89aad92592bc2bd8b2f4086c..30bc5274317c206805fe4d918c8939be923e74a0 100644 (file)
@@ -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