Skip to content

Commit e13f7e9

Browse files
committed
Restructure the pg_upgrade code to use several global structures rather
than packing everything into 'ctx' and passing that to every function.
1 parent 6e74a91 commit e13f7e9

File tree

17 files changed

+976
-976
lines changed

17 files changed

+976
-976
lines changed

contrib/pg_upgrade/check.c

Lines changed: 148 additions & 151 deletions
Large diffs are not rendered by default.

contrib/pg_upgrade/controldata.c

Lines changed: 91 additions & 91 deletions
Large diffs are not rendered by default.

contrib/pg_upgrade/dump.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212

1313

1414
void
15-
generate_old_dump(migratorContext *ctx)
15+
generate_old_dump(void)
1616
{
1717
/* run new pg_dumpall binary */
18-
prep_status(ctx, "Creating catalog dump");
18+
prep_status("Creating catalog dump");
1919

2020
/*
2121
* --binary-upgrade records the width of dropped columns in pg_class, and
2222
* restores the frozenid's for databases and relations.
2323
*/
24-
exec_prog(ctx, true,
24+
exec_prog(true,
2525
SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --username \"%s\" "
2626
"--schema-only --binary-upgrade > \"%s/" ALL_DUMP_FILE "\""
27-
SYSTEMQUOTE, ctx->new.bindir, ctx->old.port, ctx->user, ctx->cwd);
28-
check_ok(ctx);
27+
SYSTEMQUOTE, new_cluster.bindir, old_cluster.port, os_info.user, os_info.cwd);
28+
check_ok();
2929
}
3030

3131

@@ -42,7 +42,7 @@ generate_old_dump(migratorContext *ctx)
4242
* an error during restore
4343
*/
4444
void
45-
split_old_dump(migratorContext *ctx)
45+
split_old_dump(void)
4646
{
4747
FILE *all_dump,
4848
*globals_dump,
@@ -55,22 +55,22 @@ split_old_dump(migratorContext *ctx)
5555
char filename[MAXPGPATH];
5656
bool suppressed_username = false;
5757

58-
snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, ALL_DUMP_FILE);
58+
snprintf(filename, sizeof(filename), "%s/%s", os_info.cwd, ALL_DUMP_FILE);
5959
if ((all_dump = fopen(filename, "r")) == NULL)
60-
pg_log(ctx, PG_FATAL, "Cannot open dump file %s\n", filename);
61-
snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, GLOBALS_DUMP_FILE);
60+
pg_log(PG_FATAL, "Cannot open dump file %s\n", filename);
61+
snprintf(filename, sizeof(filename), "%s/%s", os_info.cwd, GLOBALS_DUMP_FILE);
6262
if ((globals_dump = fopen(filename, "w")) == NULL)
63-
pg_log(ctx, PG_FATAL, "Cannot write to dump file %s\n", filename);
64-
snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, DB_DUMP_FILE);
63+
pg_log(PG_FATAL, "Cannot write to dump file %s\n", filename);
64+
snprintf(filename, sizeof(filename), "%s/%s", os_info.cwd, DB_DUMP_FILE);
6565
if ((db_dump = fopen(filename, "w")) == NULL)
66-
pg_log(ctx, PG_FATAL, "Cannot write to dump file %s\n", filename);
66+
pg_log(PG_FATAL, "Cannot write to dump file %s\n", filename);
6767
current_output = globals_dump;
6868

6969
/* patterns used to prevent our own username from being recreated */
7070
snprintf(create_role_str, sizeof(create_role_str),
71-
"CREATE ROLE %s;", ctx->user);
71+
"CREATE ROLE %s;", os_info.user);
7272
snprintf(create_role_str_quote, sizeof(create_role_str_quote),
73-
"CREATE ROLE %s;", quote_identifier(ctx, ctx->user));
73+
"CREATE ROLE %s;", quote_identifier(os_info.user));
7474

7575
while (fgets(line, sizeof(line), all_dump) != NULL)
7676
{

contrib/pg_upgrade/exec.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <grp.h>
1414

1515

16-
static void check_data_dir(migratorContext *ctx, const char *pg_data);
17-
static void check_bin_dir(migratorContext *ctx, ClusterInfo *cluster);
18-
static int check_exec(migratorContext *ctx, const char *dir, const char *cmdName);
16+
static void check_data_dir(const char *pg_data);
17+
static void check_bin_dir(ClusterInfo *cluster);
18+
static int check_exec(const char *dir, const char *cmdName);
1919
static const char *validate_exec(const char *path);
2020

2121

@@ -30,7 +30,7 @@ static const char *validate_exec(const char *path);
3030
* instead of returning should an error occur.
3131
*/
3232
int
33-
exec_prog(migratorContext *ctx, bool throw_error, const char *fmt,...)
33+
exec_prog(bool throw_error, const char *fmt,...)
3434
{
3535
va_list args;
3636
int result;
@@ -40,13 +40,13 @@ exec_prog(migratorContext *ctx, bool throw_error, const char *fmt,...)
4040
vsnprintf(cmd, MAXPGPATH, fmt, args);
4141
va_end(args);
4242

43-
pg_log(ctx, PG_INFO, "%s\n", cmd);
43+
pg_log(PG_INFO, "%s\n", cmd);
4444

4545
result = system(cmd);
4646

4747
if (result != 0)
4848
{
49-
pg_log(ctx, throw_error ? PG_FATAL : PG_INFO,
49+
pg_log(throw_error ? PG_FATAL : PG_INFO,
5050
"\nThere were problems executing %s\n", cmd);
5151
return 1;
5252
}
@@ -62,7 +62,7 @@ exec_prog(migratorContext *ctx, bool throw_error, const char *fmt,...)
6262
* The check is performed by looking for the existence of postmaster.pid file.
6363
*/
6464
bool
65-
is_server_running(migratorContext *ctx, const char *datadir)
65+
is_server_running(const char *datadir)
6666
{
6767
char path[MAXPGPATH];
6868
int fd;
@@ -72,7 +72,7 @@ is_server_running(migratorContext *ctx, const char *datadir)
7272
if ((fd = open(path, O_RDONLY, 0)) < 0)
7373
{
7474
if (errno != ENOENT)
75-
pg_log(ctx, PG_FATAL, "\ncould not open file \"%s\" for reading\n",
75+
pg_log(PG_FATAL, "\ncould not open file \"%s\" for reading\n",
7676
path);
7777

7878
return false;
@@ -92,23 +92,23 @@ is_server_running(migratorContext *ctx, const char *datadir)
9292
* NOTE: May update the values of all parameters
9393
*/
9494
void
95-
verify_directories(migratorContext *ctx)
95+
verify_directories(void)
9696
{
97-
prep_status(ctx, "Checking old data directory (%s)", ctx->old.pgdata);
98-
check_data_dir(ctx, ctx->old.pgdata);
99-
check_ok(ctx);
97+
prep_status("Checking old data directory (%s)", old_cluster.pgdata);
98+
check_data_dir(old_cluster.pgdata);
99+
check_ok();
100100

101-
prep_status(ctx, "Checking old bin directory (%s)", ctx->old.bindir);
102-
check_bin_dir(ctx, &ctx->old);
103-
check_ok(ctx);
101+
prep_status("Checking old bin directory (%s)", old_cluster.bindir);
102+
check_bin_dir(&old_cluster);
103+
check_ok();
104104

105-
prep_status(ctx, "Checking new data directory (%s)", ctx->new.pgdata);
106-
check_data_dir(ctx, ctx->new.pgdata);
107-
check_ok(ctx);
105+
prep_status("Checking new data directory (%s)", new_cluster.pgdata);
106+
check_data_dir(new_cluster.pgdata);
107+
check_ok();
108108

109-
prep_status(ctx, "Checking new bin directory (%s)", ctx->new.bindir);
110-
check_bin_dir(ctx, &ctx->new);
111-
check_ok(ctx);
109+
prep_status("Checking new bin directory (%s)", new_cluster.bindir);
110+
check_bin_dir(&new_cluster);
111+
check_ok();
112112
}
113113

114114

@@ -122,7 +122,7 @@ verify_directories(migratorContext *ctx)
122122
*
123123
*/
124124
static void
125-
check_data_dir(migratorContext *ctx, const char *pg_data)
125+
check_data_dir(const char *pg_data)
126126
{
127127
char subDirName[MAXPGPATH];
128128
int subdirnum;
@@ -140,10 +140,10 @@ check_data_dir(migratorContext *ctx, const char *pg_data)
140140
requiredSubdirs[subdirnum]);
141141

142142
if (stat(subDirName, &statBuf) != 0)
143-
report_status(ctx, PG_FATAL, "check for %s failed: %s",
143+
report_status(PG_FATAL, "check for %s failed: %s",
144144
requiredSubdirs[subdirnum], getErrorText(errno));
145145
else if (!S_ISDIR(statBuf.st_mode))
146-
report_status(ctx, PG_FATAL, "%s is not a directory",
146+
report_status(PG_FATAL, "%s is not a directory",
147147
requiredSubdirs[subdirnum]);
148148
}
149149
}
@@ -158,12 +158,12 @@ check_data_dir(migratorContext *ctx, const char *pg_data)
158158
* exit().
159159
*/
160160
static void
161-
check_bin_dir(migratorContext *ctx, ClusterInfo *cluster)
161+
check_bin_dir(ClusterInfo *cluster)
162162
{
163-
check_exec(ctx, cluster->bindir, "postgres");
164-
check_exec(ctx, cluster->bindir, "psql");
165-
check_exec(ctx, cluster->bindir, "pg_ctl");
166-
check_exec(ctx, cluster->bindir, "pg_dumpall");
163+
check_exec(cluster->bindir, "postgres");
164+
check_exec(cluster->bindir, "psql");
165+
check_exec(cluster->bindir, "pg_ctl");
166+
check_exec(cluster->bindir, "pg_dumpall");
167167
}
168168

169169

@@ -177,7 +177,7 @@ check_bin_dir(migratorContext *ctx, ClusterInfo *cluster)
177177
* a valid executable, this function returns 0 to indicated failure.
178178
*/
179179
static int
180-
check_exec(migratorContext *ctx, const char *dir, const char *cmdName)
180+
check_exec(const char *dir, const char *cmdName)
181181
{
182182
char path[MAXPGPATH];
183183
const char *errMsg;
@@ -187,7 +187,7 @@ check_exec(migratorContext *ctx, const char *dir, const char *cmdName)
187187
if ((errMsg = validate_exec(path)) == NULL)
188188
return 1; /* 1 -> first alternative OK */
189189
else
190-
pg_log(ctx, PG_FATAL, "check for %s failed - %s\n", cmdName, errMsg);
190+
pg_log(PG_FATAL, "check for %s failed - %s\n", cmdName, errMsg);
191191

192192
return 0; /* 0 -> neither alternative is acceptable */
193193
}

contrib/pg_upgrade/file.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int copy_dir(const char *from, const char *to, bool force);
2222
#endif
2323

2424
#ifndef HAVE_SCANDIR
25-
static int pg_scandir_internal(migratorContext *ctx, const char *dirname,
25+
static int pg_scandir_internal(const char *dirname,
2626
struct dirent *** namelist,
2727
int (*selector) (const struct dirent *));
2828
#endif
@@ -35,7 +35,7 @@ static int pg_scandir_internal(migratorContext *ctx, const char *dirname,
3535
* uses that pageConverter to do a page-by-page conversion.
3636
*/
3737
const char *
38-
copyAndUpdateFile(migratorContext *ctx, pageCnvCtx *pageConverter,
38+
copyAndUpdateFile(pageCnvCtx *pageConverter,
3939
const char *src, const char *dst, bool force)
4040
{
4141
if (pageConverter == NULL)
@@ -116,7 +116,7 @@ copyAndUpdateFile(migratorContext *ctx, pageCnvCtx *pageConverter,
116116
* instead of copying the data from the old cluster to the new cluster.
117117
*/
118118
const char *
119-
linkAndUpdateFile(migratorContext *ctx, pageCnvCtx *pageConverter,
119+
linkAndUpdateFile(pageCnvCtx *pageConverter,
120120
const char *src, const char *dst)
121121
{
122122
if (pageConverter != NULL)
@@ -231,12 +231,12 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
231231
* Wrapper for portable scandir functionality
232232
*/
233233
int
234-
pg_scandir(migratorContext *ctx, const char *dirname,
234+
pg_scandir(const char *dirname,
235235
struct dirent *** namelist,
236236
int (*selector) (const struct dirent *))
237237
{
238238
#ifndef HAVE_SCANDIR
239-
return pg_scandir_internal(ctx, dirname, namelist, selector);
239+
return pg_scandir_internal(dirname, namelist, selector);
240240

241241
/*
242242
* scandir() is originally from BSD 4.3, which had the third argument as
@@ -277,7 +277,7 @@ pg_scandir(migratorContext *ctx, const char *dirname,
277277
* .2, etc.) and should therefore be invoked a small number of times.
278278
*/
279279
static int
280-
pg_scandir_internal(migratorContext *ctx, const char *dirname,
280+
pg_scandir_internal(const char *dirname,
281281
struct dirent *** namelist, int (*selector) (const struct dirent *))
282282
{
283283
DIR *dirdesc;
@@ -287,7 +287,7 @@ pg_scandir_internal(migratorContext *ctx, const char *dirname,
287287
size_t entrysize;
288288

289289
if ((dirdesc = opendir(dirname)) == NULL)
290-
pg_log(ctx, PG_FATAL, "Could not open directory \"%s\": %m\n", dirname);
290+
pg_log(PG_FATAL, "Could not open directory \"%s\": %m\n", dirname);
291291

292292
*namelist = NULL;
293293

@@ -342,18 +342,18 @@ dir_matching_filenames(const struct dirent * scan_ent)
342342

343343

344344
void
345-
check_hard_link(migratorContext *ctx)
345+
check_hard_link(void)
346346
{
347347
char existing_file[MAXPGPATH];
348348
char new_link_file[MAXPGPATH];
349349

350-
snprintf(existing_file, sizeof(existing_file), "%s/PG_VERSION", ctx->old.pgdata);
351-
snprintf(new_link_file, sizeof(new_link_file), "%s/PG_VERSION.linktest", ctx->new.pgdata);
350+
snprintf(existing_file, sizeof(existing_file), "%s/PG_VERSION", old_cluster.pgdata);
351+
snprintf(new_link_file, sizeof(new_link_file), "%s/PG_VERSION.linktest", new_cluster.pgdata);
352352
unlink(new_link_file); /* might fail */
353353

354354
if (pg_link_file(existing_file, new_link_file) == -1)
355355
{
356-
pg_log(ctx, PG_FATAL,
356+
pg_log(PG_FATAL,
357357
"Could not create hard link between old and new data directories: %s\n"
358358
"In link mode the old and new data directories must be on the same file system volume.\n",
359359
getErrorText(errno));

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