Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite13f7e9

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 parent6e74a91 commite13f7e9

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
charfilename[MAXPGPATH];
5656
boolsuppressed_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-
staticvoidcheck_data_dir(migratorContext*ctx,constchar*pg_data);
17-
staticvoidcheck_bin_dir(migratorContext*ctx,ClusterInfo*cluster);
18-
staticintcheck_exec(migratorContext*ctx,constchar*dir,constchar*cmdName);
16+
staticvoidcheck_data_dir(constchar*pg_data);
17+
staticvoidcheck_bin_dir(ClusterInfo*cluster);
18+
staticintcheck_exec(constchar*dir,constchar*cmdName);
1919
staticconstchar*validate_exec(constchar*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,boolthrow_error,constchar*fmt,...)
33+
exec_prog(boolthrow_error,constchar*fmt,...)
3434
{
3535
va_listargs;
3636
intresult;
@@ -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
return1;
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,constchar*datadir)
65+
is_server_running(constchar*datadir)
6666
{
6767
charpath[MAXPGPATH];
6868
intfd;
@@ -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
staticvoid
125-
check_data_dir(migratorContext*ctx,constchar*pg_data)
125+
check_data_dir(constchar*pg_data)
126126
{
127127
charsubDirName[MAXPGPATH];
128128
intsubdirnum;
@@ -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
elseif (!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
staticvoid
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
staticint
180-
check_exec(migratorContext*ctx,constchar*dir,constchar*cmdName)
180+
check_exec(constchar*dir,constchar*cmdName)
181181
{
182182
charpath[MAXPGPATH];
183183
constchar*errMsg;
@@ -187,7 +187,7 @@ check_exec(migratorContext *ctx, const char *dir, const char *cmdName)
187187
if ((errMsg=validate_exec(path))==NULL)
188188
return1;/* 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
return0;/* 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 intcopy_dir(const char *from, const char *to, bool force);
2222
#endif
2323

2424
#ifndefHAVE_SCANDIR
25-
staticintpg_scandir_internal(migratorContext*ctx,constchar*dirname,
25+
staticintpg_scandir_internal(constchar*dirname,
2626
structdirent***namelist,
2727
int (*selector) (conststructdirent*));
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
constchar*
38-
copyAndUpdateFile(migratorContext*ctx,pageCnvCtx*pageConverter,
38+
copyAndUpdateFile(pageCnvCtx*pageConverter,
3939
constchar*src,constchar*dst,boolforce)
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
constchar*
119-
linkAndUpdateFile(migratorContext*ctx,pageCnvCtx*pageConverter,
119+
linkAndUpdateFile(pageCnvCtx*pageConverter,
120120
constchar*src,constchar*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,constchar*dirname,
234+
pg_scandir(constchar*dirname,
235235
structdirent***namelist,
236236
int (*selector) (conststructdirent*))
237237
{
238238
#ifndefHAVE_SCANDIR
239-
returnpg_scandir_internal(ctx,dirname,namelist,selector);
239+
returnpg_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
staticint
280-
pg_scandir_internal(migratorContext*ctx,constchar*dirname,
280+
pg_scandir_internal(constchar*dirname,
281281
structdirent***namelist,int (*selector) (conststructdirent*))
282282
{
283283
DIR*dirdesc;
@@ -287,7 +287,7 @@ pg_scandir_internal(migratorContext *ctx, const char *dirname,
287287
size_tentrysize;
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
charexisting_file[MAXPGPATH];
348348
charnew_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)

[8]ページ先頭

©2009-2025 Movatter.jp