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

Commit 25cc742

Browse files
committed
Simplify functions and parameters used by pg_upgrade.
1 parent 14158f2 commit 25cc742

File tree

2 files changed

+62
-83
lines changed

2 files changed

+62
-83
lines changed

contrib/pg_upgrade/dump.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "pg_upgrade.h"
1111

1212

13-
1413
void
1514
generate_old_dump(void)
1615
{

contrib/pg_upgrade/info.c

Lines changed: 62 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,18 @@
1313

1414

1515
static void get_db_infos(ClusterInfo *cluster);
16-
static void dbarr_print(ClusterInfo *cluster);
17-
static void relarr_print(RelInfoArr *arr);
18-
static void get_rel_infos(ClusterInfo *cluster, const int dbnum);
19-
static void relarr_free(RelInfoArr *rel_arr);
20-
static void map_rel(const RelInfo *oldrel,
21-
const RelInfo *newrel, const DbInfo *old_db,
22-
const DbInfo *new_db, const char *olddata,
23-
const char *newdata, FileNameMap *map);
24-
static void map_rel_by_id(Oid oldid, Oid newid,
25-
const char *old_nspname, const char *old_relname,
26-
const char *new_nspname, const char *new_relname,
27-
const char *old_tablespace, const DbInfo *old_db,
28-
const DbInfo *new_db, const char *olddata,
29-
const char *newdata, FileNameMap *map);
30-
static RelInfo *relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr,
31-
Oid oid);
32-
static RelInfo *relarr_lookup_rel(ClusterInfo *cluster, RelInfoArr *rel_arr,
16+
static void print_db_arr(ClusterInfo *cluster);
17+
static void print_rel_arr(RelInfoArr *arr);
18+
static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo);
19+
static void free_rel_arr(RelInfoArr *rel_arr);
20+
static void create_rel_filename_map(const char *old_data, const char *new_data,
21+
const DbInfo *old_db, const DbInfo *new_db,
22+
const RelInfo *old_rel, const RelInfo *new_rel,
23+
FileNameMap *map);
24+
static RelInfo *relarr_lookup_rel_name(ClusterInfo *cluster, RelInfoArr *rel_arr,
3325
const char *nspname, const char *relname);
26+
static RelInfo *relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr,
27+
Oid oid);
3428

3529

3630
/*
@@ -62,11 +56,11 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
6256
if (strcmp(newrel->nspname, "pg_toast") == 0)
6357
continue;
6458

65-
oldrel = relarr_lookup_rel(&old_cluster, &old_db->rel_arr,
59+
oldrel = relarr_lookup_rel_name(&old_cluster, &old_db->rel_arr,
6660
newrel->nspname, newrel->relname);
6761

68-
map_rel(oldrel, newrel, old_db, new_db, old_pgdata, new_pgdata,
69-
maps + num_maps);
62+
create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
63+
oldrel, newrel, maps + num_maps);
7064
num_maps++;
7165

7266
/*
@@ -81,20 +75,18 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
8175
char old_name[MAXPGPATH];
8276

8377
/* construct the new and old relnames for the toast relation */
84-
snprintf(old_name, sizeof(old_name), "pg_toast_%u",
85-
oldrel->reloid);
86-
snprintf(new_name, sizeof(new_name), "pg_toast_%u",
87-
newrel->reloid);
78+
snprintf(old_name, sizeof(old_name), "pg_toast_%u", oldrel->reloid);
79+
snprintf(new_name, sizeof(new_name), "pg_toast_%u", newrel->reloid);
8880

8981
/* look them up in their respective arrays */
90-
old_toast = relarr_lookup_reloid(&old_cluster, &old_db->rel_arr,
82+
old_toast = relarr_lookup_rel_oid(&old_cluster, &old_db->rel_arr,
9183
oldrel->toastrelid);
92-
new_toast = relarr_lookup_rel(&new_cluster, &new_db->rel_arr,
84+
new_toast = relarr_lookup_rel_name(&new_cluster, &new_db->rel_arr,
9385
"pg_toast", new_name);
9486

9587
/* finally create a mapping for them */
96-
map_rel(old_toast, new_toast, old_db, new_db, old_pgdata, new_pgdata,
97-
maps + num_maps);
88+
create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
89+
old_toast, new_toast, maps + num_maps);
9890
num_maps++;
9991

10092
/*
@@ -113,15 +105,14 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
113105
newrel->reloid);
114106

115107
/* look them up in their respective arrays */
116-
/* we lose our cache location here */
117-
old_toast = relarr_lookup_rel(&old_cluster, &old_db->rel_arr,
108+
old_toast = relarr_lookup_rel_name(&old_cluster, &old_db->rel_arr,
118109
"pg_toast", old_name);
119-
new_toast = relarr_lookup_rel(&new_cluster, &new_db->rel_arr,
110+
new_toast = relarr_lookup_rel_name(&new_cluster, &new_db->rel_arr,
120111
"pg_toast", new_name);
121112

122113
/* finally create a mapping for them */
123-
map_rel(old_toast, new_toast, old_db, new_db, old_pgdata,
124-
new_pgdata, maps + num_maps);
114+
create_rel_filename_map(old_pgdata, new_pgdata, old_db,
115+
new_db, old_toast, new_toast, maps + num_maps);
125116
num_maps++;
126117
}
127118
}
@@ -131,56 +122,45 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
131122
}
132123

133124

134-
static void
135-
map_rel(const RelInfo *oldrel, const RelInfo *newrel,
136-
const DbInfo *old_db, const DbInfo *new_db, const char *olddata,
137-
const char *newdata, FileNameMap *map)
138-
{
139-
map_rel_by_id(oldrel->relfilenode, newrel->relfilenode, oldrel->nspname,
140-
oldrel->relname, newrel->nspname, newrel->relname, oldrel->tablespace, old_db,
141-
new_db, olddata, newdata, map);
142-
}
143-
144-
145125
/*
146-
* map_rel_by_id()
126+
* create_rel_filename_map()
147127
*
148128
* fills a file node map structure and returns it in "map".
149129
*/
150130
static void
151-
map_rel_by_id(Oid oldid, Oid newid,
152-
const char *old_nspname, const char *old_relname,
153-
const char *new_nspname, const char *new_relname,
154-
const char *old_tablespace, const DbInfo *old_db,
155-
const DbInfo *new_db, const char *olddata,
156-
const char *newdata, FileNameMap *map)
131+
create_rel_filename_map(const char *old_data, const char *new_data,
132+
const DbInfo *old_db, const DbInfo *new_db,
133+
const RelInfo *old_rel, const RelInfo *new_rel,
134+
FileNameMap *map)
157135
{
158-
map->old_relfilenode = oldid;
159-
map->new_relfilenode = newid;
136+
map->old_relfilenode = old_rel->relfilenode;
137+
map->new_relfilenode = new_rel->relfilenode;
138+
139+
snprintf(map->old_nspname, sizeof(map->old_nspname), "%s", old_rel->nspname);
140+
snprintf(map->new_nspname, sizeof(map->new_nspname), "%s", new_rel->nspname);
160141

161-
snprintf(map->old_nspname, sizeof(map->old_nspname), "%s", old_nspname);
162-
snprintf(map->old_relname, sizeof(map->old_relname), "%s", old_relname);
163-
snprintf(map->new_nspname, sizeof(map->new_nspname), "%s", new_nspname);
164-
snprintf(map->new_relname, sizeof(map->new_relname), "%s", new_relname);
142+
snprintf(map->old_relname, sizeof(map->old_relname), "%s", old_rel->relname);
143+
snprintf(map->new_relname, sizeof(map->new_relname), "%s", new_rel->relname);
165144

166-
if (strlen(old_tablespace) == 0)
145+
if (strlen(old_rel->tablespace) == 0)
167146
{
168147
/*
169-
* relation belongs to the default tablespace, hence relfiles would
148+
* relation belongs to the default tablespace, hence relfiles should
170149
* exist in the data directories.
171150
*/
172-
snprintf(map->old_dir, sizeof(map->old_dir), "%s/base/%u", olddata, old_db->db_oid);
173-
snprintf(map->new_dir, sizeof(map->new_dir), "%s/base/%u", newdata, new_db->db_oid);
151+
snprintf(map->old_dir, sizeof(map->old_dir), "%s/base/%u", old_data,
152+
old_db->db_oid);
153+
snprintf(map->new_dir, sizeof(map->new_dir), "%s/base/%u", new_data,
154+
new_db->db_oid);
174155
}
175156
else
176157
{
177158
/*
178-
* relation belongs to some tablespace, hence copy its physical
179-
* location
159+
* relation belongs to some tablespace, so use the tablespace location
180160
*/
181-
snprintf(map->old_dir, sizeof(map->old_dir), "%s%s/%u", old_tablespace,
161+
snprintf(map->old_dir, sizeof(map->old_dir), "%s%s/%u", old_rel->tablespace,
182162
old_cluster.tablespace_suffix, old_db->db_oid);
183-
snprintf(map->new_dir, sizeof(map->new_dir), "%s%s/%u", old_tablespace,
163+
snprintf(map->new_dir, sizeof(map->new_dir), "%s%s/%u", new_rel->tablespace,
184164
new_cluster.tablespace_suffix, new_db->db_oid);
185165
}
186166
}
@@ -271,10 +251,10 @@ get_db_and_rel_infos(ClusterInfo *cluster)
271251
get_db_infos(cluster);
272252

273253
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
274-
get_rel_infos(cluster, dbnum);
254+
get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum]);
275255

276256
if (log_opts.debug)
277-
dbarr_print(cluster);
257+
print_db_arr(cluster);
278258
}
279259

280260

@@ -288,10 +268,10 @@ get_db_and_rel_infos(ClusterInfo *cluster)
288268
* FirstNormalObjectId belongs to the user
289269
*/
290270
static void
291-
get_rel_infos(ClusterInfo *cluster, const int dbnum)
271+
get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
292272
{
293273
PGconn *conn = connectToServer(cluster,
294-
cluster->dbarr.dbs[dbnum].db_name);
274+
dbinfo->db_name);
295275
PGresult *res;
296276
RelInfo *relinfos;
297277
int ntups;
@@ -373,16 +353,16 @@ get_rel_infos(ClusterInfo *cluster, const int dbnum)
373353
tblspace = PQgetvalue(res, relnum, i_spclocation);
374354
/* if no table tablespace, use the database tablespace */
375355
if (strlen(tblspace) == 0)
376-
tblspace = cluster->dbarr.dbs[dbnum].db_tblspace;
356+
tblspace = dbinfo->db_tblspace;
377357
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
378358
}
379359
PQclear(res);
380360

381361
PQfinish(conn);
382362

383-
cluster->dbarr.dbs[dbnum].rel_arr.rels = relinfos;
384-
cluster->dbarr.dbs[dbnum].rel_arr.nrels = num_rels;
385-
cluster->dbarr.dbs[dbnum].rel_arr.last_relname_lookup = 0;
363+
dbinfo->rel_arr.rels = relinfos;
364+
dbinfo->rel_arr.nrels = num_rels;
365+
dbinfo->rel_arr.last_relname_lookup = 0;
386366
}
387367

388368

@@ -407,13 +387,13 @@ dbarr_lookup_db(DbInfoArr *db_arr, const char *db_name)
407387

408388

409389
/*
410-
* relarr_lookup_rel()
390+
* relarr_lookup_rel_name()
411391
*
412392
* Searches "relname" in rel_arr. Returns the *real* pointer to the
413393
* RelInfo structure.
414394
*/
415395
static RelInfo *
416-
relarr_lookup_rel(ClusterInfo *cluster, RelInfoArr *rel_arr,
396+
relarr_lookup_rel_name(ClusterInfo *cluster, RelInfoArr *rel_arr,
417397
const char *nspname, const char *relname)
418398
{
419399
int relnum;
@@ -443,14 +423,14 @@ relarr_lookup_rel(ClusterInfo *cluster, RelInfoArr *rel_arr,
443423

444424

445425
/*
446-
* relarr_lookup_reloid()
426+
* relarr_lookup_rel_oid()
447427
*
448428
* Returns a pointer to the RelInfo structure for the
449429
* given oid or NULL if the desired entry cannot be
450430
* found.
451431
*/
452432
static RelInfo *
453-
relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
433+
relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
454434
{
455435
int relnum;
456436

@@ -466,7 +446,7 @@ relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
466446

467447

468448
static void
469-
relarr_free(RelInfoArr *rel_arr)
449+
free_rel_arr(RelInfoArr *rel_arr)
470450
{
471451
pg_free(rel_arr->rels);
472452
rel_arr->nrels = 0;
@@ -480,13 +460,13 @@ dbarr_free(DbInfoArr *db_arr)
480460
int dbnum;
481461

482462
for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
483-
relarr_free(&db_arr->dbs[dbnum].rel_arr);
463+
free_rel_arr(&db_arr->dbs[dbnum].rel_arr);
484464
db_arr->ndbs = 0;
485465
}
486466

487467

488468
static void
489-
dbarr_print(ClusterInfo *cluster)
469+
print_db_arr(ClusterInfo *cluster)
490470
{
491471
int dbnum;
492472

@@ -495,14 +475,14 @@ dbarr_print(ClusterInfo *cluster)
495475
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
496476
{
497477
pg_log(PG_DEBUG, "Database: %s\n", cluster->dbarr.dbs[dbnum].db_name);
498-
relarr_print(&cluster->dbarr.dbs[dbnum].rel_arr);
478+
print_rel_arr(&cluster->dbarr.dbs[dbnum].rel_arr);
499479
pg_log(PG_DEBUG, "\n\n");
500480
}
501481
}
502482

503483

504484
static void
505-
relarr_print(RelInfoArr *arr)
485+
print_rel_arr(RelInfoArr *arr)
506486
{
507487
int relnum;
508488

0 commit comments

Comments
 (0)