Skip to content

Commit 910d3a4

Browse files
committed
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
1 parent d7de6a4 commit 910d3a4

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

contrib/pg_upgrade/parallel.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ HANDLE *thread_handles;
3232

3333
typedef struct
3434
{
35-
char log_file[MAXPGPATH];
36-
char opt_log_file[MAXPGPATH];
37-
char cmd[MAX_STRING];
35+
char *log_file;
36+
char *opt_log_file;
37+
char *cmd;
3838
} exec_thread_arg;
3939

4040
typedef struct
4141
{
4242
DbInfoArr *old_db_arr;
4343
DbInfoArr *new_db_arr;
44-
char old_pgdata[MAXPGPATH];
45-
char new_pgdata[MAXPGPATH];
46-
char old_tablespace[MAXPGPATH];
44+
char *old_pgdata;
45+
char *new_pgdata;
46+
char *old_tablespace;
4747
} transfer_thread_arg;
4848

4949
exec_thread_arg **exec_thread_args;
@@ -113,10 +113,12 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
113113
pg_log(PG_FATAL, "could not create worker process: %s\n", strerror(errno));
114114
#else
115115
if (thread_handles == NULL)
116+
thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE));
117+
118+
if (exec_thread_args == NULL)
116119
{
117120
int i;
118121

119-
thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE));
120122
exec_thread_args = pg_malloc(user_opts.jobs * sizeof(exec_thread_arg *));
121123

122124
/*
@@ -125,16 +127,22 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
125127
* thread different from the one that allocated it.
126128
*/
127129
for (i = 0; i < user_opts.jobs; i++)
128-
exec_thread_args[i] = pg_malloc(sizeof(exec_thread_arg));
130+
exec_thread_args[i] = pg_malloc0(sizeof(exec_thread_arg));
129131
}
130132

131133
/* use first empty array element */
132134
new_arg = exec_thread_args[parallel_jobs - 1];
133135

134136
/* Can only pass one pointer into the function, so use a struct */
135-
strcpy(new_arg->log_file, log_file);
136-
strcpy(new_arg->opt_log_file, opt_log_file);
137-
strcpy(new_arg->cmd, cmd);
137+
if (new_arg->log_file)
138+
pg_free(new_arg->log_file);
139+
new_arg->log_file = pg_strdup(log_file);
140+
if (new_arg->opt_log_file)
141+
pg_free(new_arg->opt_log_file);
142+
new_arg->opt_log_file = opt_log_file ? pg_strdup(opt_log_file) : NULL;
143+
if (new_arg->cmd)
144+
pg_free(new_arg->cmd);
145+
new_arg->cmd = pg_strdup(cmd);
138146

139147
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_exec_prog,
140148
new_arg, 0, NULL);
@@ -219,10 +227,12 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
219227
pg_log(PG_FATAL, "could not create worker process: %s\n", strerror(errno));
220228
#else
221229
if (thread_handles == NULL)
230+
thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE));
231+
232+
if (transfer_thread_args == NULL)
222233
{
223234
int i;
224235

225-
thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE));
226236
transfer_thread_args = pg_malloc(user_opts.jobs * sizeof(transfer_thread_arg *));
227237

228238
/*
@@ -231,7 +241,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
231241
* thread different from the one that allocated it.
232242
*/
233243
for (i = 0; i < user_opts.jobs; i++)
234-
transfer_thread_args[i] = pg_malloc(sizeof(transfer_thread_arg));
244+
transfer_thread_args[i] = pg_malloc0(sizeof(transfer_thread_arg));
235245
}
236246

237247
/* use first empty array element */
@@ -240,9 +250,15 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
240250
/* Can only pass one pointer into the function, so use a struct */
241251
new_arg->old_db_arr = old_db_arr;
242252
new_arg->new_db_arr = new_db_arr;
243-
strcpy(new_arg->old_pgdata, old_pgdata);
244-
strcpy(new_arg->new_pgdata, new_pgdata);
245-
strcpy(new_arg->old_tablespace, old_tablespace);
253+
if (new_arg->old_pgdata)
254+
pg_free(new_arg->old_pgdata);
255+
new_arg->old_pgdata = pg_strdup(old_pgdata);
256+
if (new_arg->new_pgdata)
257+
pg_free(new_arg->new_pgdata);
258+
new_arg->new_pgdata = pg_strdup(new_pgdata);
259+
if (new_arg->old_tablespace)
260+
pg_free(new_arg->old_tablespace);
261+
new_arg->old_tablespace = old_tablespace ? pg_strdup(old_tablespace) : NULL;
246262

247263
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_transfer_all_new_dbs,
248264
new_arg, 0, NULL);

contrib/pg_upgrade/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ PGDATA=$BASE_PGDATA
152152

153153
initdb -N
154154

155-
pg_upgrade -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" -p "$PGPORT" -P "$PGPORT"
155+
pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" -p "$PGPORT" -P "$PGPORT"
156156

157157
pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
158158

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy