1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Restructure the pg_upgrade code to use several global structures rather

than packing everything into 'ctx' and passing that to every function.
This commit is contained in:
Bruce Momjian
2010-10-19 21:38:16 +00:00
parent 6e74a91b2b
commit e13f7e9a71
17 changed files with 972 additions and 972 deletions

View File

@ -9,22 +9,22 @@
#include "pg_upgrade.h"
static void get_tablespace_paths(migratorContext *ctx);
static void set_tablespace_directory_suffix(migratorContext *ctx,
static void get_tablespace_paths(void);
static void set_tablespace_directory_suffix(
Cluster whichCluster);
void
init_tablespaces(migratorContext *ctx)
init_tablespaces(void)
{
get_tablespace_paths(ctx);
get_tablespace_paths();
set_tablespace_directory_suffix(ctx, CLUSTER_OLD);
set_tablespace_directory_suffix(ctx, CLUSTER_NEW);
set_tablespace_directory_suffix(CLUSTER_OLD);
set_tablespace_directory_suffix(CLUSTER_NEW);
if (ctx->num_tablespaces > 0 &&
strcmp(ctx->old.tablespace_suffix, ctx->new.tablespace_suffix) == 0)
pg_log(ctx, PG_FATAL,
if (os_info.num_tablespaces > 0 &&
strcmp(old_cluster.tablespace_suffix, new_cluster.tablespace_suffix) == 0)
pg_log(PG_FATAL,
"Cannot migrate to/from the same system catalog version when\n"
"using tablespaces.\n");
}
@ -37,29 +37,29 @@ init_tablespaces(migratorContext *ctx)
* paths. Its the caller's responsibility to free the array.
*/
static void
get_tablespace_paths(migratorContext *ctx)
get_tablespace_paths(void)
{
PGconn *conn = connectToServer(ctx, "template1", CLUSTER_OLD);
PGconn *conn = connectToServer("template1", CLUSTER_OLD);
PGresult *res;
int tblnum;
int i_spclocation;
res = executeQueryOrDie(ctx, conn,
res = executeQueryOrDie(conn,
"SELECT spclocation "
"FROM pg_catalog.pg_tablespace "
"WHERE spcname != 'pg_default' AND "
" spcname != 'pg_global'");
if ((ctx->num_tablespaces = PQntuples(res)) != 0)
ctx->tablespaces = (char **) pg_malloc(ctx,
ctx->num_tablespaces * sizeof(char *));
if ((os_info.num_tablespaces = PQntuples(res)) != 0)
os_info.tablespaces = (char **) pg_malloc(
os_info.num_tablespaces * sizeof(char *));
else
ctx->tablespaces = NULL;
os_info.tablespaces = NULL;
i_spclocation = PQfnumber(res, "spclocation");
for (tblnum = 0; tblnum < ctx->num_tablespaces; tblnum++)
ctx->tablespaces[tblnum] = pg_strdup(ctx,
for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++)
os_info.tablespaces[tblnum] = pg_strdup(
PQgetvalue(res, tblnum, i_spclocation));
PQclear(res);
@ -71,20 +71,21 @@ get_tablespace_paths(migratorContext *ctx)
static void
set_tablespace_directory_suffix(migratorContext *ctx, Cluster whichCluster)
set_tablespace_directory_suffix(Cluster whichCluster)
{
ClusterInfo *cluster = (whichCluster == CLUSTER_OLD) ? &ctx->old : &ctx->new;
ClusterInfo *active_cluster = ACTIVE_CLUSTER(whichCluster);
if (GET_MAJOR_VERSION(cluster->major_version) <= 804)
cluster->tablespace_suffix = pg_strdup(ctx, "");
if (GET_MAJOR_VERSION(active_cluster->major_version) <= 804)
active_cluster->tablespace_suffix = pg_strdup("");
else
{
/* This cluster has a version-specific subdirectory */
cluster->tablespace_suffix = pg_malloc(ctx, 4 + strlen(cluster->major_version_str) +
10 /* OIDCHARS */ + 1);
active_cluster->tablespace_suffix = pg_malloc(4 +
strlen(active_cluster->major_version_str) +
10 /* OIDCHARS */ + 1);
/* The leading slash is needed to start a new directory. */
sprintf(cluster->tablespace_suffix, "/PG_%s_%d", cluster->major_version_str,
cluster->controldata.cat_ver);
sprintf(active_cluster->tablespace_suffix, "/PG_%s_%d", active_cluster->major_version_str,
active_cluster->controldata.cat_ver);
}
}