1313
1414
1515static 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 ,
3325const 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,
6256if (strcmp (newrel -> nspname ,"pg_toast" )== 0 )
6357continue ;
6458
65- oldrel = relarr_lookup_rel (& old_cluster ,& old_db -> rel_arr ,
59+ oldrel = relarr_lookup_rel_name (& old_cluster ,& old_db -> rel_arr ,
6660newrel -> 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 );
7064num_maps ++ ;
7165
7266/*
@@ -81,20 +75,18 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
8175char 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 ,
9183oldrel -> 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 );
9890num_maps ++ ;
9991
10092/*
@@ -113,15 +105,14 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
113105newrel -> 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 );
125116num_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 */
150130static 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 relfileswould
148+ * relation belongs to the default tablespace, hence relfilesshould
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}
175156else
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 ,
182162old_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 ,
184164new_cluster .tablespace_suffix ,new_db -> db_oid );
185165}
186166}
@@ -271,10 +251,10 @@ get_db_and_rel_infos(ClusterInfo *cluster)
271251get_db_infos (cluster );
272252
273253for (dbnum = 0 ;dbnum < cluster -> dbarr .ndbs ;dbnum ++ )
274- get_rel_infos (cluster ,dbnum );
254+ get_rel_infos (cluster ,& cluster -> dbarr . dbs [ dbnum ] );
275255
276256if (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 */
290270static void
291- get_rel_infos (ClusterInfo * cluster ,const int dbnum )
271+ get_rel_infos (ClusterInfo * cluster ,DbInfo * dbinfo )
292272{
293273PGconn * conn = connectToServer (cluster ,
294- cluster -> dbarr . dbs [ dbnum ]. db_name );
274+ dbinfo -> db_name );
295275PGresult * res ;
296276RelInfo * relinfos ;
297277int ntups ;
@@ -373,16 +353,16 @@ get_rel_infos(ClusterInfo *cluster, const int dbnum)
373353tblspace = PQgetvalue (res ,relnum ,i_spclocation );
374354/* if no table tablespace, use the database tablespace */
375355if (strlen (tblspace )== 0 )
376- tblspace = cluster -> dbarr . dbs [ dbnum ]. db_tblspace ;
356+ tblspace = dbinfo -> db_tblspace ;
377357strlcpy (curr -> tablespace ,tblspace ,sizeof (curr -> tablespace ));
378358}
379359PQclear (res );
380360
381361PQfinish (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 */
415395static RelInfo *
416- relarr_lookup_rel (ClusterInfo * cluster ,RelInfoArr * rel_arr ,
396+ relarr_lookup_rel_name (ClusterInfo * cluster ,RelInfoArr * rel_arr ,
417397const char * nspname ,const char * relname )
418398{
419399int 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 */
452432static 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{
455435int relnum ;
456436
@@ -466,7 +446,7 @@ relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
466446
467447
468448static void
469- relarr_free (RelInfoArr * rel_arr )
449+ free_rel_arr (RelInfoArr * rel_arr )
470450{
471451pg_free (rel_arr -> rels );
472452rel_arr -> nrels = 0 ;
@@ -480,13 +460,13 @@ dbarr_free(DbInfoArr *db_arr)
480460int dbnum ;
481461
482462for (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 );
484464db_arr -> ndbs = 0 ;
485465}
486466
487467
488468static void
489- dbarr_print (ClusterInfo * cluster )
469+ print_db_arr (ClusterInfo * cluster )
490470{
491471int dbnum ;
492472
@@ -495,14 +475,14 @@ dbarr_print(ClusterInfo *cluster)
495475for (dbnum = 0 ;dbnum < cluster -> dbarr .ndbs ;dbnum ++ )
496476{
497477pg_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 );
499479pg_log (PG_DEBUG ,"\n\n" );
500480}
501481}
502482
503483
504484static void
505- relarr_print (RelInfoArr * arr )
485+ print_rel_arr (RelInfoArr * arr )
506486{
507487int relnum ;
508488