Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6e6bee9

Browse files
committed
In pg_upgrade, remove use of whichCluster, and just pass old/new cluster
pointers, which simplifies the code. This was not possible in 9.0 because everything was in a single nested struct, but is possible now. Per suggestion from Tom.
1 parent f82b3e5 commit 6e6bee9

File tree

11 files changed

+181
-227
lines changed

11 files changed

+181
-227
lines changed

contrib/pg_upgrade/check.c

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
#include "pg_upgrade.h"
1111

1212

13-
static void set_locale_and_encoding(Cluster whichCluster);
13+
static void set_locale_and_encoding(ClusterInfo *cluster);
1414
static void check_new_db_is_empty(void);
1515
static void check_locale_and_encoding(ControlData *oldctrl,
1616
ControlData *newctrl);
17-
static void check_for_isn_and_int8_passing_mismatch(
18-
Cluster whichCluster);
19-
static void check_for_reg_data_type_usage(Cluster whichCluster);
17+
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
18+
static void check_for_reg_data_type_usage(ClusterInfo *cluster);
2019

2120

2221
void
@@ -46,14 +45,14 @@ check_old_cluster(bool live_check,
4645
/* -- OLD -- */
4746

4847
if (!live_check)
49-
start_postmaster(CLUSTER_OLD, false);
48+
start_postmaster(&old_cluster, false);
5049

51-
set_locale_and_encoding(CLUSTER_OLD);
50+
set_locale_and_encoding(&old_cluster);
5251

53-
get_pg_database_relfilenode(CLUSTER_OLD);
52+
get_pg_database_relfilenode(&old_cluster);
5453

5554
/* Extract a list of databases and tables from the old cluster */
56-
get_db_and_rel_infos(&old_cluster.dbarr, CLUSTER_OLD);
55+
get_db_and_rel_infos(&old_cluster);
5756

5857
init_tablespaces();
5958

@@ -64,19 +63,19 @@ check_old_cluster(bool live_check,
6463
* Check for various failure cases
6564
*/
6665

67-
check_for_reg_data_type_usage(CLUSTER_OLD);
68-
check_for_isn_and_int8_passing_mismatch(CLUSTER_OLD);
66+
check_for_reg_data_type_usage(&old_cluster);
67+
check_for_isn_and_int8_passing_mismatch(&old_cluster);
6968

7069
/* old = PG 8.3 checks? */
7170
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
7271
{
73-
old_8_3_check_for_name_data_type_usage(CLUSTER_OLD);
74-
old_8_3_check_for_tsquery_usage(CLUSTER_OLD);
72+
old_8_3_check_for_name_data_type_usage(&old_cluster);
73+
old_8_3_check_for_tsquery_usage(&old_cluster);
7574
if (user_opts.check)
7675
{
77-
old_8_3_rebuild_tsvector_tables(true, CLUSTER_OLD);
78-
old_8_3_invalidate_hash_gin_indexes(true, CLUSTER_OLD);
79-
old_8_3_invalidate_bpchar_pattern_ops_indexes(true, CLUSTER_OLD);
76+
old_8_3_rebuild_tsvector_tables(&old_cluster, true);
77+
old_8_3_invalidate_hash_gin_indexes(&old_cluster, true);
78+
old_8_3_invalidate_bpchar_pattern_ops_indexes(&old_cluster, true);
8079
}
8180
else
8281

@@ -86,12 +85,12 @@ check_old_cluster(bool live_check,
8685
* end.
8786
*/
8887
*sequence_script_file_name =
89-
old_8_3_create_sequence_script(CLUSTER_OLD);
88+
old_8_3_create_sequence_script(&old_cluster);
9089
}
9190

9291
/* Pre-PG 9.0 had no large object permissions */
9392
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
94-
new_9_0_populate_pg_largeobject_metadata(true, CLUSTER_OLD);
93+
new_9_0_populate_pg_largeobject_metadata(&old_cluster, true);
9594

9695
/*
9796
* While not a check option, we do this now because this is the only time
@@ -111,7 +110,7 @@ check_old_cluster(bool live_check,
111110
void
112111
check_new_cluster(void)
113112
{
114-
set_locale_and_encoding(CLUSTER_NEW);
113+
set_locale_and_encoding(&new_cluster);
115114

116115
check_new_db_is_empty();
117116

@@ -149,7 +148,7 @@ issue_warnings(char *sequence_script_file_name)
149148
/* old = PG 8.3 warnings? */
150149
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
151150
{
152-
start_postmaster(CLUSTER_NEW, true);
151+
start_postmaster(&new_cluster, true);
153152

154153
/* restore proper sequence values using file created from old server */
155154
if (sequence_script_file_name)
@@ -165,17 +164,17 @@ issue_warnings(char *sequence_script_file_name)
165164
check_ok();
166165
}
167166

168-
old_8_3_rebuild_tsvector_tables(false, CLUSTER_NEW);
169-
old_8_3_invalidate_hash_gin_indexes(false, CLUSTER_NEW);
170-
old_8_3_invalidate_bpchar_pattern_ops_indexes(false, CLUSTER_NEW);
167+
old_8_3_rebuild_tsvector_tables(&new_cluster, false);
168+
old_8_3_invalidate_hash_gin_indexes(&new_cluster, false);
169+
old_8_3_invalidate_bpchar_pattern_ops_indexes(&new_cluster, false);
171170
stop_postmaster(false, true);
172171
}
173172

174173
/* Create dummy large object permissions for old < PG 9.0? */
175174
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
176175
{
177-
start_postmaster(CLUSTER_NEW, true);
178-
new_9_0_populate_pg_largeobject_metadata(false, CLUSTER_NEW);
176+
start_postmaster(&new_cluster, true);
177+
new_9_0_populate_pg_largeobject_metadata(&new_cluster, false);
179178
stop_postmaster(false, true);
180179
}
181180
}
@@ -210,8 +209,8 @@ void
210209
check_cluster_versions(void)
211210
{
212211
/* get old and new cluster versions */
213-
old_cluster.major_version = get_major_server_version(&old_cluster.major_version_str, CLUSTER_OLD);
214-
new_cluster.major_version = get_major_server_version(&new_cluster.major_version_str, CLUSTER_NEW);
212+
old_cluster.major_version = get_major_server_version(&old_cluster, &old_cluster.major_version_str);
213+
new_cluster.major_version = get_major_server_version(&new_cluster, &new_cluster.major_version_str);
215214

216215
/* We allow upgrades from/to the same major version for alpha/beta upgrades */
217216

@@ -270,16 +269,15 @@ check_cluster_compatibility(bool live_check)
270269
* query the database to get the template0 locale
271270
*/
272271
static void
273-
set_locale_and_encoding(Cluster whichCluster)
272+
set_locale_and_encoding(ClusterInfo *cluster)
274273
{
275-
ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
276-
ControlData *ctrl = &active_cluster->controldata;
274+
ControlData *ctrl = &cluster->controldata;
277275
PGconn *conn;
278276
PGresult *res;
279277
int i_encoding;
280-
int cluster_version = active_cluster->major_version;
278+
int cluster_version = cluster->major_version;
281279

282-
conn = connectToServer("template1", whichCluster);
280+
conn = connectToServer(cluster, "template1");
283281

284282
/* for pg < 80400, we got the values from pg_controldata */
285283
if (cluster_version >= 80400)
@@ -345,7 +343,7 @@ check_new_db_is_empty(void)
345343
int dbnum;
346344
bool found = false;
347345

348-
get_db_and_rel_infos(&new_cluster.dbarr, CLUSTER_NEW);
346+
get_db_and_rel_infos(&new_cluster);
349347

350348
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
351349
{
@@ -457,9 +455,8 @@ create_script_for_old_cluster_deletion(
457455
* it must match for the old and new servers.
458456
*/
459457
void
460-
check_for_isn_and_int8_passing_mismatch(Cluster whichCluster)
458+
check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
461459
{
462-
ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
463460
int dbnum;
464461
FILE *script = NULL;
465462
bool found = false;
@@ -478,16 +475,16 @@ check_for_isn_and_int8_passing_mismatch(Cluster whichCluster)
478475
snprintf(output_path, sizeof(output_path), "%s/contrib_isn_and_int8_pass_by_value.txt",
479476
os_info.cwd);
480477

481-
for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
478+
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
482479
{
483480
PGresult *res;
484481
bool db_used = false;
485482
int ntups;
486483
int rowno;
487484
int i_nspname,
488485
i_proname;
489-
DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
490-
PGconn *conn = connectToServer(active_db->db_name, whichCluster);
486+
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
487+
PGconn *conn = connectToServer(cluster, active_db->db_name);
491488

492489
/* Find any functions coming from contrib/isn */
493490
res = executeQueryOrDie(conn,
@@ -552,9 +549,8 @@ check_for_isn_and_int8_passing_mismatch(Cluster whichCluster)
552549
* tables upgraded by pg_upgrade.
553550
*/
554551
void
555-
check_for_reg_data_type_usage(Cluster whichCluster)
552+
check_for_reg_data_type_usage(ClusterInfo *cluster)
556553
{
557-
ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
558554
int dbnum;
559555
FILE *script = NULL;
560556
bool found = false;
@@ -565,7 +561,7 @@ check_for_reg_data_type_usage(Cluster whichCluster)
565561
snprintf(output_path, sizeof(output_path), "%s/tables_using_reg.txt",
566562
os_info.cwd);
567563

568-
for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
564+
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
569565
{
570566
PGresult *res;
571567
bool db_used = false;
@@ -574,8 +570,8 @@ check_for_reg_data_type_usage(Cluster whichCluster)
574570
int i_nspname,
575571
i_relname,
576572
i_attname;
577-
DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
578-
PGconn *conn = connectToServer(active_db->db_name, whichCluster);
573+
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
574+
PGconn *conn = connectToServer(cluster, active_db->db_name);
579575

580576
res = executeQueryOrDie(conn,
581577
"SELECT n.nspname, c.relname, a.attname "

contrib/pg_upgrade/exec.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
static void check_data_dir(const char *pg_data);
17-
static void check_bin_dir(ClusterInfo *cluster, Cluster whichCluster);
17+
static void check_bin_dir(ClusterInfo *cluster);
1818
static int check_exec(const char *dir, const char *cmdName);
1919
static const char *validate_exec(const char *path);
2020

@@ -99,15 +99,15 @@ verify_directories(void)
9999
check_ok();
100100

101101
prep_status("Checking old bin directory (%s)", old_cluster.bindir);
102-
check_bin_dir(&old_cluster, CLUSTER_OLD);
102+
check_bin_dir(&old_cluster);
103103
check_ok();
104104

105105
prep_status("Checking new data directory (%s)", new_cluster.pgdata);
106106
check_data_dir(new_cluster.pgdata);
107107
check_ok();
108108

109109
prep_status("Checking new bin directory (%s)", new_cluster.bindir);
110-
check_bin_dir(&new_cluster, CLUSTER_NEW);
110+
check_bin_dir(&new_cluster);
111111
check_ok();
112112
}
113113

@@ -158,12 +158,12 @@ check_data_dir(const char *pg_data)
158158
* exit().
159159
*/
160160
static void
161-
check_bin_dir(ClusterInfo *cluster, Cluster whichCluster)
161+
check_bin_dir(ClusterInfo *cluster)
162162
{
163163
check_exec(cluster->bindir, "postgres");
164164
check_exec(cluster->bindir, "pg_ctl");
165165
check_exec(cluster->bindir, "pg_resetxlog");
166-
if (whichCluster == CLUSTER_NEW)
166+
if (cluster == &new_cluster)
167167
{
168168
/* these are only needed in the new cluster */
169169
check_exec(cluster->bindir, "pg_config");

contrib/pg_upgrade/function.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ install_support_functions(void)
2828
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
2929
{
3030
DbInfo *newdb = &new_cluster.dbarr.dbs[dbnum];
31-
PGconn *conn = connectToServer(newdb->db_name, CLUSTER_NEW);
31+
PGconn *conn = connectToServer(&new_cluster, newdb->db_name);
3232

3333
/* suppress NOTICE of dropped objects */
3434
PQclear(executeQueryOrDie(conn,
@@ -99,7 +99,7 @@ uninstall_support_functions(void)
9999
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
100100
{
101101
DbInfo *newdb = &new_cluster.dbarr.dbs[dbnum];
102-
PGconn *conn = connectToServer(newdb->db_name, CLUSTER_NEW);
102+
PGconn *conn = connectToServer(&new_cluster, newdb->db_name);
103103

104104
/* suppress NOTICE of dropped objects */
105105
PQclear(executeQueryOrDie(conn,
@@ -123,20 +123,19 @@ uninstall_support_functions(void)
123123
void
124124
get_loadable_libraries(void)
125125
{
126-
ClusterInfo *active_cluster = &old_cluster;
127126
PGresult **ress;
128127
int totaltups;
129128
int dbnum;
130129

131130
ress = (PGresult **)
132-
pg_malloc(active_cluster->dbarr.ndbs * sizeof(PGresult *));
131+
pg_malloc(old_cluster.dbarr.ndbs * sizeof(PGresult *));
133132
totaltups = 0;
134133

135134
/* Fetch all library names, removing duplicates within each DB */
136-
for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
135+
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
137136
{
138-
DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
139-
PGconn *conn = connectToServer(active_db->db_name, CLUSTER_OLD);
137+
DbInfo *active_db = &old_cluster.dbarr.dbs[dbnum];
138+
PGconn *conn = connectToServer(&old_cluster, active_db->db_name);
140139

141140
/* Fetch all libraries referenced in this DB */
142141
ress[dbnum] = executeQueryOrDie(conn,
@@ -163,7 +162,7 @@ get_loadable_libraries(void)
163162
*/
164163
totaltups = 0;
165164

166-
for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
165+
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
167166
{
168167
PGresult *res = ress[dbnum];
169168
int ntups;
@@ -207,7 +206,7 @@ get_loadable_libraries(void)
207206
void
208207
check_loadable_libraries(void)
209208
{
210-
PGconn *conn = connectToServer("template1", CLUSTER_NEW);
209+
PGconn *conn = connectToServer(&new_cluster, "template1");
211210
int libnum;
212211
FILE *script = NULL;
213212
bool found = false;

0 commit comments

Comments
 (0)