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

Commit4b56bb4

Browse files
pg_upgrade: Move live_check variable to user_opts.
At the moment, pg_upgrade stores whether it is doing a "live check"(i.e., the user specified --check and the old server is stillrunning) in a local variable scoped to main(). This live_checkvariable is passed to several functions. To further complicatematters, a few call sites provide a hard-coded "false" as thelive_check argument. Specifically, this is done when calling thesefunctions for the new cluster, for which any live-check-only pathswon't apply.This commit moves the live_check variable to the global user_optsvariable, which stores information about the options the userspecified on the command line. This allows us to remove thelive_check parameter from several functions. For the functionswith callers that provide a hard-coded "false" as the live_checkargument (e.g., get_control_data()), we verify the given cluster isthe old cluster before taking any live-check-only paths.This small refactoring effort helps simplify some proposed changesthat would parallelize many of pg_upgrade's once-in-each-databasetasks using libpq's asynchronous APIs. By removing the live_checkparameter, we can more easily convert the functions to callbacksfor the new parallel system.Reviewed-by: Daniel GustafssonDiscussion:https://postgr.es/m/20240516211638.GA1688936%40nathanxps13
1 parent5d1d8b3 commit4b56bb4

File tree

6 files changed

+41
-42
lines changed

6 files changed

+41
-42
lines changed

‎src/bin/pg_upgrade/check.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void check_for_new_tablespace_dir(void);
2929
staticvoidcheck_for_user_defined_encoding_conversions(ClusterInfo*cluster);
3030
staticvoidcheck_new_cluster_logical_replication_slots(void);
3131
staticvoidcheck_new_cluster_subscription_configuration(void);
32-
staticvoidcheck_old_cluster_for_valid_slots(boollive_check);
32+
staticvoidcheck_old_cluster_for_valid_slots(void);
3333
staticvoidcheck_old_cluster_subscription_state(void);
3434

3535
/*
@@ -555,9 +555,9 @@ fix_path_separator(char *path)
555555
}
556556

557557
void
558-
output_check_banner(boollive_check)
558+
output_check_banner(void)
559559
{
560-
if (user_opts.check&&live_check)
560+
if (user_opts.live_check)
561561
{
562562
pg_log(PG_REPORT,
563563
"Performing Consistency Checks on Old Live Server\n"
@@ -573,18 +573,18 @@ output_check_banner(bool live_check)
573573

574574

575575
void
576-
check_and_dump_old_cluster(boollive_check)
576+
check_and_dump_old_cluster(void)
577577
{
578578
/* -- OLD -- */
579579

580-
if (!live_check)
580+
if (!user_opts.live_check)
581581
start_postmaster(&old_cluster, true);
582582

583583
/*
584584
* Extract a list of databases, tables, and logical replication slots from
585585
* the old cluster.
586586
*/
587-
get_db_rel_and_slot_infos(&old_cluster,live_check);
587+
get_db_rel_and_slot_infos(&old_cluster);
588588

589589
init_tablespaces();
590590

@@ -605,7 +605,7 @@ check_and_dump_old_cluster(bool live_check)
605605
* Logical replication slots can be migrated since PG17. See comments
606606
* atop get_old_cluster_logical_slot_infos().
607607
*/
608-
check_old_cluster_for_valid_slots(live_check);
608+
check_old_cluster_for_valid_slots();
609609

610610
/*
611611
* Subscriptions and their dependencies can be migrated since PG17.
@@ -669,15 +669,15 @@ check_and_dump_old_cluster(bool live_check)
669669
if (!user_opts.check)
670670
generate_old_dump();
671671

672-
if (!live_check)
672+
if (!user_opts.live_check)
673673
stop_postmaster(false);
674674
}
675675

676676

677677
void
678678
check_new_cluster(void)
679679
{
680-
get_db_rel_and_slot_infos(&new_cluster, false);
680+
get_db_rel_and_slot_infos(&new_cluster);
681681

682682
check_new_cluster_is_empty();
683683

@@ -828,14 +828,14 @@ check_cluster_versions(void)
828828

829829

830830
void
831-
check_cluster_compatibility(boollive_check)
831+
check_cluster_compatibility(void)
832832
{
833833
/* get/check pg_control data of servers */
834-
get_control_data(&old_cluster,live_check);
835-
get_control_data(&new_cluster, false);
834+
get_control_data(&old_cluster);
835+
get_control_data(&new_cluster);
836836
check_control_data(&old_cluster.controldata,&new_cluster.controldata);
837837

838-
if (live_check&&old_cluster.port==new_cluster.port)
838+
if (user_opts.live_check&&old_cluster.port==new_cluster.port)
839839
pg_fatal("When checking a live server, "
840840
"the old and new port numbers must be different.");
841841
}
@@ -1838,7 +1838,7 @@ check_new_cluster_subscription_configuration(void)
18381838
* before shutdown.
18391839
*/
18401840
staticvoid
1841-
check_old_cluster_for_valid_slots(boollive_check)
1841+
check_old_cluster_for_valid_slots(void)
18421842
{
18431843
charoutput_path[MAXPGPATH];
18441844
FILE*script=NULL;
@@ -1877,7 +1877,7 @@ check_old_cluster_for_valid_slots(bool live_check)
18771877
* Note: This can be satisfied only when the old cluster has been
18781878
* shut down, so we skip this for live checks.
18791879
*/
1880-
if (!live_check&& !slot->caught_up)
1880+
if (!user_opts.live_check&& !slot->caught_up)
18811881
{
18821882
if (script==NULL&&
18831883
(script=fopen_priv(output_path,"w"))==NULL)

‎src/bin/pg_upgrade/controldata.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* return valid xid data for a running server.
3434
*/
3535
void
36-
get_control_data(ClusterInfo*cluster,boollive_check)
36+
get_control_data(ClusterInfo*cluster)
3737
{
3838
charcmd[MAXPGPATH];
3939
charbufin[MAX_STRING];
@@ -76,6 +76,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
7676
uint32segno=0;
7777
char*resetwal_bin;
7878
intrc;
79+
boollive_check= (cluster==&old_cluster&&user_opts.live_check);
7980

8081
/*
8182
* Because we test the pg_resetwal output as strings, it has to be in

‎src/bin/pg_upgrade/info.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void free_rel_infos(RelInfoArr *rel_arr);
2727
staticvoidprint_db_infos(DbInfoArr*db_arr);
2828
staticvoidprint_rel_infos(RelInfoArr*rel_arr);
2929
staticvoidprint_slot_infos(LogicalSlotInfoArr*slot_arr);
30-
staticvoidget_old_cluster_logical_slot_infos(DbInfo*dbinfo,boollive_check);
30+
staticvoidget_old_cluster_logical_slot_infos(DbInfo*dbinfo);
3131

3232

3333
/*
@@ -272,11 +272,9 @@ report_unmatched_relation(const RelInfo *rel, const DbInfo *db, bool is_new_db)
272272
*
273273
* higher level routine to generate dbinfos for the database running
274274
* on the given "port". Assumes that server is already running.
275-
*
276-
* live_check would be used only when the target is the old cluster.
277275
*/
278276
void
279-
get_db_rel_and_slot_infos(ClusterInfo*cluster,boollive_check)
277+
get_db_rel_and_slot_infos(ClusterInfo*cluster)
280278
{
281279
intdbnum;
282280

@@ -293,7 +291,7 @@ get_db_rel_and_slot_infos(ClusterInfo *cluster, bool live_check)
293291
get_rel_infos(cluster,pDbInfo);
294292

295293
if (cluster==&old_cluster)
296-
get_old_cluster_logical_slot_infos(pDbInfo,live_check);
294+
get_old_cluster_logical_slot_infos(pDbInfo);
297295
}
298296

299297
if (cluster==&old_cluster)
@@ -637,7 +635,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
637635
* are included.
638636
*/
639637
staticvoid
640-
get_old_cluster_logical_slot_infos(DbInfo*dbinfo,boollive_check)
638+
get_old_cluster_logical_slot_infos(DbInfo*dbinfo)
641639
{
642640
PGconn*conn;
643641
PGresult*res;
@@ -673,7 +671,7 @@ get_old_cluster_logical_slot_infos(DbInfo *dbinfo, bool live_check)
673671
"WHERE slot_type = 'logical' AND "
674672
"database = current_database() AND "
675673
"temporary IS FALSE;",
676-
live_check ?"FALSE" :
674+
user_opts.live_check ?"FALSE" :
677675
"(CASE WHEN invalidation_reason IS NOT NULL THEN FALSE "
678676
"ELSE (SELECT pg_catalog.binary_upgrade_logical_slot_has_caught_up(slot_name)) "
679677
"END)");

‎src/bin/pg_upgrade/option.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ adjust_data_dir(ClusterInfo *cluster)
470470
* directory.
471471
*/
472472
void
473-
get_sock_dir(ClusterInfo*cluster,boollive_check)
473+
get_sock_dir(ClusterInfo*cluster)
474474
{
475475
#if !defined(WIN32)
476-
if (!live_check)
476+
if (!user_opts.live_check||cluster==&new_cluster)
477477
cluster->sockdir=user_opts.socketdir;
478478
else
479479
{

‎src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void create_new_objects(void);
6565
staticvoidcopy_xact_xlog_xid(void);
6666
staticvoidset_frozenxids(boolminmxid_only);
6767
staticvoidmake_outputdirs(char*pgdata);
68-
staticvoidsetup(char*argv0,bool*live_check);
68+
staticvoidsetup(char*argv0);
6969
staticvoidcreate_logical_replication_slots(void);
7070

7171
ClusterInfoold_cluster,
@@ -88,7 +88,6 @@ int
8888
main(intargc,char**argv)
8989
{
9090
char*deletion_script_file_name=NULL;
91-
boollive_check= false;
9291

9392
/*
9493
* pg_upgrade doesn't currently use common/logging.c, but initialize it
@@ -123,18 +122,18 @@ main(int argc, char **argv)
123122
*/
124123
make_outputdirs(new_cluster.pgdata);
125124

126-
setup(argv[0],&live_check);
125+
setup(argv[0]);
127126

128-
output_check_banner(live_check);
127+
output_check_banner();
129128

130129
check_cluster_versions();
131130

132-
get_sock_dir(&old_cluster,live_check);
133-
get_sock_dir(&new_cluster, false);
131+
get_sock_dir(&old_cluster);
132+
get_sock_dir(&new_cluster);
134133

135-
check_cluster_compatibility(live_check);
134+
check_cluster_compatibility();
136135

137-
check_and_dump_old_cluster(live_check);
136+
check_and_dump_old_cluster();
138137

139138

140139
/* -- NEW -- */
@@ -331,7 +330,7 @@ make_outputdirs(char *pgdata)
331330

332331

333332
staticvoid
334-
setup(char*argv0,bool*live_check)
333+
setup(char*argv0)
335334
{
336335
/*
337336
* make sure the user has a clean environment, otherwise, we may confuse
@@ -378,7 +377,7 @@ setup(char *argv0, bool *live_check)
378377
pg_fatal("There seems to be a postmaster servicing the old cluster.\n"
379378
"Please shutdown that postmaster and try again.");
380379
else
381-
*live_check= true;
380+
user_opts.live_check= true;
382381
}
383382
}
384383

@@ -660,7 +659,7 @@ create_new_objects(void)
660659
set_frozenxids(true);
661660

662661
/* update new_cluster info now that we have objects in the databases */
663-
get_db_rel_and_slot_infos(&new_cluster, false);
662+
get_db_rel_and_slot_infos(&new_cluster);
664663
}
665664

666665
/*

‎src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ typedef struct
321321
typedefstruct
322322
{
323323
boolcheck;/* check clusters only, don't change any data */
324+
boollive_check;/* check clusters only, old server is running */
324325
booldo_sync;/* flush changes to disk */
325326
transferModetransfer_mode;/* copy files or link them? */
326327
intjobs;/* number of processes/threads to use */
@@ -365,20 +366,20 @@ extern OSInfo os_info;
365366

366367
/* check.c */
367368

368-
voidoutput_check_banner(boollive_check);
369-
voidcheck_and_dump_old_cluster(boollive_check);
369+
voidoutput_check_banner(void);
370+
voidcheck_and_dump_old_cluster(void);
370371
voidcheck_new_cluster(void);
371372
voidreport_clusters_compatible(void);
372373
voidissue_warnings_and_set_wal_level(void);
373374
voidoutput_completion_banner(char*deletion_script_file_name);
374375
voidcheck_cluster_versions(void);
375-
voidcheck_cluster_compatibility(boollive_check);
376+
voidcheck_cluster_compatibility(void);
376377
voidcreate_script_for_old_cluster_deletion(char**deletion_script_file_name);
377378

378379

379380
/* controldata.c */
380381

381-
voidget_control_data(ClusterInfo*cluster,boollive_check);
382+
voidget_control_data(ClusterInfo*cluster);
382383
voidcheck_control_data(ControlData*oldctrl,ControlData*newctrl);
383384
voiddisable_old_cluster(void);
384385

@@ -427,15 +428,15 @@ voidcheck_loadable_libraries(void);
427428
FileNameMap*gen_db_file_maps(DbInfo*old_db,
428429
DbInfo*new_db,int*nmaps,constchar*old_pgdata,
429430
constchar*new_pgdata);
430-
voidget_db_rel_and_slot_infos(ClusterInfo*cluster,boollive_check);
431+
voidget_db_rel_and_slot_infos(ClusterInfo*cluster);
431432
intcount_old_cluster_logical_slots(void);
432433
voidget_subscription_count(ClusterInfo*cluster);
433434

434435
/* option.c */
435436

436437
voidparseCommandLine(intargc,char*argv[]);
437438
voidadjust_data_dir(ClusterInfo*cluster);
438-
voidget_sock_dir(ClusterInfo*cluster,boollive_check);
439+
voidget_sock_dir(ClusterInfo*cluster);
439440

440441
/* relfilenumber.c */
441442

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp