1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +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

@ -11,7 +11,7 @@
#include <ctype.h>
static void putenv2(migratorContext *ctx, const char *var, const char *val);
static void putenv2(const char *var, const char *val);
/*
* get_control_data()
@ -31,7 +31,7 @@ static void putenv2(migratorContext *ctx, const char *var, const char *val);
* return valid xid data for a running server.
*/
void
get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
get_control_data(ClusterInfo *cluster, bool live_check)
{
char cmd[MAXPGPATH];
char bufin[MAX_STRING];
@ -67,39 +67,39 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
* English. Copied from pg_regress.c.
*/
if (getenv("LC_COLLATE"))
lc_collate = pg_strdup(ctx, getenv("LC_COLLATE"));
lc_collate = pg_strdup(getenv("LC_COLLATE"));
if (getenv("LC_CTYPE"))
lc_ctype = pg_strdup(ctx, getenv("LC_CTYPE"));
lc_ctype = pg_strdup(getenv("LC_CTYPE"));
if (getenv("LC_MONETARY"))
lc_monetary = pg_strdup(ctx, getenv("LC_MONETARY"));
lc_monetary = pg_strdup(getenv("LC_MONETARY"));
if (getenv("LC_NUMERIC"))
lc_numeric = pg_strdup(ctx, getenv("LC_NUMERIC"));
lc_numeric = pg_strdup(getenv("LC_NUMERIC"));
if (getenv("LC_TIME"))
lc_time = pg_strdup(ctx, getenv("LC_TIME"));
lc_time = pg_strdup(getenv("LC_TIME"));
if (getenv("LANG"))
lang = pg_strdup(ctx, getenv("LANG"));
lang = pg_strdup(getenv("LANG"));
if (getenv("LANGUAGE"))
language = pg_strdup(ctx, getenv("LANGUAGE"));
language = pg_strdup(getenv("LANGUAGE"));
if (getenv("LC_ALL"))
lc_all = pg_strdup(ctx, getenv("LC_ALL"));
lc_all = pg_strdup(getenv("LC_ALL"));
if (getenv("LC_MESSAGES"))
lc_messages = pg_strdup(ctx, getenv("LC_MESSAGES"));
lc_messages = pg_strdup(getenv("LC_MESSAGES"));
putenv2(ctx, "LC_COLLATE", NULL);
putenv2(ctx, "LC_CTYPE", NULL);
putenv2(ctx, "LC_MONETARY", NULL);
putenv2(ctx, "LC_NUMERIC", NULL);
putenv2(ctx, "LC_TIME", NULL);
putenv2(ctx, "LANG",
putenv2("LC_COLLATE", NULL);
putenv2("LC_CTYPE", NULL);
putenv2("LC_MONETARY", NULL);
putenv2("LC_NUMERIC", NULL);
putenv2("LC_TIME", NULL);
putenv2("LANG",
#ifndef WIN32
NULL);
#else
/* On Windows the default locale cannot be English, so force it */
"en");
#endif
putenv2(ctx, "LANGUAGE", NULL);
putenv2(ctx, "LC_ALL", NULL);
putenv2(ctx, "LC_MESSAGES", "C");
putenv2("LANGUAGE", NULL);
putenv2("LC_ALL", NULL);
putenv2("LC_MESSAGES", "C");
snprintf(cmd, sizeof(cmd), SYSTEMQUOTE "\"%s/%s \"%s\"" SYSTEMQUOTE,
cluster->bindir,
@ -109,7 +109,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
fflush(stderr);
if ((output = popen(cmd, "r")) == NULL)
pg_log(ctx, PG_FATAL, "Could not get control data: %s\n",
pg_log(PG_FATAL, "Could not get control data: %s\n",
getErrorText(errno));
/* Only pre-8.4 has these so if they are not set below we will check later */
@ -126,8 +126,8 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
/* we have the result of cmd in "output". so parse it line by line now */
while (fgets(bufin, sizeof(bufin), output))
{
if (ctx->debug)
fputs(bufin, ctx->debug_fd);
if (log.debug)
fputs(bufin, log.debug_fd);
#ifdef WIN32
@ -140,7 +140,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
{
for (p = bufin; *p; p++)
if (!isascii(*p))
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"The 8.3 cluster's pg_controldata is incapable of outputting ASCII, even\n"
"with LANG=C. You must upgrade this cluster to a newer version of Postgres\n"
"8.3 to fix this bug. Postgres 8.3.7 and later are known to work properly.\n");
@ -152,7 +152,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: pg_resetxlog problem\n", __LINE__);
pg_log(PG_FATAL, "%d: pg_resetxlog problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.ctrl_ver = str2uint(p);
@ -162,7 +162,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.cat_ver = str2uint(p);
@ -172,7 +172,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.logid = str2uint(p);
@ -183,7 +183,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.nxtlogseg = str2uint(p);
@ -194,7 +194,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.chkpnt_tli = str2uint(p);
@ -208,7 +208,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
op = strchr(p, ':');
if (op == NULL || strlen(op) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
op++; /* removing ':' char */
cluster->controldata.chkpnt_nxtxid = str2uint(op);
@ -219,7 +219,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.chkpnt_nxtoid = str2uint(p);
@ -230,7 +230,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.align = str2uint(p);
@ -241,7 +241,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.blocksz = str2uint(p);
@ -252,7 +252,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.largesz = str2uint(p);
@ -263,7 +263,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.walsz = str2uint(p);
@ -274,7 +274,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.walseg = str2uint(p);
@ -285,7 +285,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.ident = str2uint(p);
@ -296,7 +296,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.index = str2uint(p);
@ -307,7 +307,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.toast = str2uint(p);
@ -318,7 +318,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
cluster->controldata.date_is_int = strstr(p, "64-bit integers") != NULL;
@ -329,7 +329,7 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
/* used later for /contrib check */
@ -342,14 +342,14 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
/* skip leading spaces and remove trailing newline */
p += strspn(p, " ");
if (strlen(p) > 0 && *(p + strlen(p) - 1) == '\n')
*(p + strlen(p) - 1) = '\0';
cluster->controldata.lc_collate = pg_strdup(ctx, p);
cluster->controldata.lc_collate = pg_strdup(p);
}
/* In pre-8.4 only */
else if ((p = strstr(bufin, "LC_CTYPE:")) != NULL)
@ -357,14 +357,14 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
p = strchr(p, ':');
if (p == NULL || strlen(p) <= 1)
pg_log(ctx, PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
p++; /* removing ':' char */
/* skip leading spaces and remove trailing newline */
p += strspn(p, " ");
if (strlen(p) > 0 && *(p + strlen(p) - 1) == '\n')
*(p + strlen(p) - 1) = '\0';
cluster->controldata.lc_ctype = pg_strdup(ctx, p);
cluster->controldata.lc_ctype = pg_strdup(p);
}
}
@ -374,15 +374,15 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
/*
* Restore environment variables
*/
putenv2(ctx, "LC_COLLATE", lc_collate);
putenv2(ctx, "LC_CTYPE", lc_ctype);
putenv2(ctx, "LC_MONETARY", lc_monetary);
putenv2(ctx, "LC_NUMERIC", lc_numeric);
putenv2(ctx, "LC_TIME", lc_time);
putenv2(ctx, "LANG", lang);
putenv2(ctx, "LANGUAGE", language);
putenv2(ctx, "LC_ALL", lc_all);
putenv2(ctx, "LC_MESSAGES", lc_messages);
putenv2("LC_COLLATE", lc_collate);
putenv2("LC_CTYPE", lc_ctype);
putenv2("LC_MONETARY", lc_monetary);
putenv2("LC_NUMERIC", lc_numeric);
putenv2("LC_TIME", lc_time);
putenv2("LANG", lang);
putenv2("LANGUAGE", language);
putenv2("LC_ALL", lc_all);
putenv2("LC_MESSAGES", lc_messages);
pg_free(lc_collate);
pg_free(lc_ctype);
@ -403,56 +403,56 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
!got_walseg || !got_ident || !got_index || !got_toast ||
!got_date_is_int || !got_float8_pass_by_value)
{
pg_log(ctx, PG_REPORT,
pg_log(PG_REPORT,
"Some required control information is missing; cannot find:\n");
if (!got_xid)
pg_log(ctx, PG_REPORT, " checkpoint next XID\n");
pg_log(PG_REPORT, " checkpoint next XID\n");
if (!got_oid)
pg_log(ctx, PG_REPORT, " latest checkpoint next OID\n");
pg_log(PG_REPORT, " latest checkpoint next OID\n");
if (!live_check && !got_log_id)
pg_log(ctx, PG_REPORT, " first log file ID after reset\n");
pg_log(PG_REPORT, " first log file ID after reset\n");
if (!live_check && !got_log_seg)
pg_log(ctx, PG_REPORT, " first log file segment after reset\n");
pg_log(PG_REPORT, " first log file segment after reset\n");
if (!got_tli)
pg_log(ctx, PG_REPORT, " latest checkpoint timeline ID\n");
pg_log(PG_REPORT, " latest checkpoint timeline ID\n");
if (!got_align)
pg_log(ctx, PG_REPORT, " maximum alignment\n");
pg_log(PG_REPORT, " maximum alignment\n");
if (!got_blocksz)
pg_log(ctx, PG_REPORT, " block size\n");
pg_log(PG_REPORT, " block size\n");
if (!got_largesz)
pg_log(ctx, PG_REPORT, " large relation segment size\n");
pg_log(PG_REPORT, " large relation segment size\n");
if (!got_walsz)
pg_log(ctx, PG_REPORT, " WAL block size\n");
pg_log(PG_REPORT, " WAL block size\n");
if (!got_walseg)
pg_log(ctx, PG_REPORT, " WAL segment size\n");
pg_log(PG_REPORT, " WAL segment size\n");
if (!got_ident)
pg_log(ctx, PG_REPORT, " maximum identifier length\n");
pg_log(PG_REPORT, " maximum identifier length\n");
if (!got_index)
pg_log(ctx, PG_REPORT, " maximum number of indexed columns\n");
pg_log(PG_REPORT, " maximum number of indexed columns\n");
if (!got_toast)
pg_log(ctx, PG_REPORT, " maximum TOAST chunk size\n");
pg_log(PG_REPORT, " maximum TOAST chunk size\n");
if (!got_date_is_int)
pg_log(ctx, PG_REPORT, " dates/times are integers?\n");
pg_log(PG_REPORT, " dates/times are integers?\n");
/* value added in Postgres 8.4 */
if (!got_float8_pass_by_value)
pg_log(ctx, PG_REPORT, " float8 argument passing method\n");
pg_log(PG_REPORT, " float8 argument passing method\n");
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"Unable to continue without required control information, terminating\n");
}
}
@ -464,51 +464,51 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
* check to make sure the control data settings are compatible
*/
void
check_control_data(migratorContext *ctx, ControlData *oldctrl,
check_control_data(ControlData *oldctrl,
ControlData *newctrl)
{
if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata alignments are invalid or do not match\n");
if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata block sizes are invalid or do not match\n");
if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata maximum relation segement sizes are invalid or do not match\n");
if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata WAL block sizes are invalid or do not match\n");
if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata WAL segment sizes are invalid or do not match\n");
if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata maximum identifier lengths are invalid or do not match\n");
if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata maximum indexed columns are invalid or do not match\n");
if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match\n");
if (oldctrl->date_is_int != newctrl->date_is_int)
{
pg_log(ctx, PG_WARNING,
pg_log(PG_WARNING,
"\nOld and new pg_controldata date/time storage types do not match.\n");
/*
* This is a common 8.3 -> 8.4 migration problem, so we are more
* verboase
*/
pg_log(ctx, PG_FATAL,
pg_log(PG_FATAL,
"You will need to rebuild the new server with configure\n"
"--disable-integer-datetimes or get server binaries built\n"
"with those options.\n");
@ -517,18 +517,18 @@ check_control_data(migratorContext *ctx, ControlData *oldctrl,
void
rename_old_pg_control(migratorContext *ctx)
rename_old_pg_control(void)
{
char old_path[MAXPGPATH],
new_path[MAXPGPATH];
prep_status(ctx, "Adding \".old\" suffix to old global/pg_control");
prep_status("Adding \".old\" suffix to old global/pg_control");
snprintf(old_path, sizeof(old_path), "%s/global/pg_control", ctx->old.pgdata);
snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", ctx->old.pgdata);
snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
if (pg_mv_file(old_path, new_path) != 0)
pg_log(ctx, PG_FATAL, "Unable to rename %s to %s.\n", old_path, new_path);
check_ok(ctx);
pg_log(PG_FATAL, "Unable to rename %s to %s.\n", old_path, new_path);
check_ok();
}
@ -539,12 +539,12 @@ rename_old_pg_control(migratorContext *ctx)
* It also does unsetenv() if val is NULL.
*/
static void
putenv2(migratorContext *ctx, const char *var, const char *val)
putenv2(const char *var, const char *val)
{
if (val)
{
#ifndef WIN32
char *envstr = (char *) pg_malloc(ctx, strlen(var) +
char *envstr = (char *) pg_malloc(strlen(var) +
strlen(val) + 1);
sprintf(envstr, "%s=%s", var, val);