struct data_type_check_state
{
DataTypesUsageChecks *check; /* the check for this step */
- bool *result; /* true if check failed for any database */
+ bool result; /* true if check failed for any database */
PQExpBuffer *report; /* buffer for report on failed checks */
};
{
struct data_type_check_state *state = (struct data_type_check_state *) arg;
int ntups = PQntuples(res);
+ char output_path[MAXPGPATH];
+ int i_nspname = PQfnumber(res, "nspname");
+ int i_relname = PQfnumber(res, "relname");
+ int i_attname = PQfnumber(res, "attname");
+ FILE *script = NULL;
AssertVariableIsOfType(&process_data_type_check, UpgradeTaskProcessCB);
- if (ntups)
- {
- char output_path[MAXPGPATH];
- int i_nspname;
- int i_relname;
- int i_attname;
- FILE *script = NULL;
- bool db_used = false;
+ if (ntups == 0)
+ return;
- snprintf(output_path, sizeof(output_path), "%s/%s",
- log_opts.basedir,
- state->check->report_filename);
+ snprintf(output_path, sizeof(output_path), "%s/%s",
+ log_opts.basedir,
+ state->check->report_filename);
- /*
- * Make sure we have a buffer to save reports to now that we found a
- * first failing check.
- */
- if (*state->report == NULL)
- *state->report = createPQExpBuffer();
+ /*
+ * Make sure we have a buffer to save reports to now that we found a first
+ * failing check.
+ */
+ if (*state->report == NULL)
+ *state->report = createPQExpBuffer();
- /*
- * If this is the first time we see an error for the check in question
- * then print a status message of the failure.
- */
- if (!(*state->result))
- {
- pg_log(PG_REPORT, "failed check: %s", _(state->check->status));
- appendPQExpBuffer(*state->report, "\n%s\n%s %s\n",
- _(state->check->report_text),
- _("A list of the problem columns is in the file:"),
- output_path);
- }
- *state->result = true;
+ /*
+ * If this is the first time we see an error for the check in question
+ * then print a status message of the failure.
+ */
+ if (!state->result)
+ {
+ pg_log(PG_REPORT, "failed check: %s", _(state->check->status));
+ appendPQExpBuffer(*state->report, "\n%s\n%s %s\n",
+ _(state->check->report_text),
+ _("A list of the problem columns is in the file:"),
+ output_path);
+ }
+ state->result = true;
- i_nspname = PQfnumber(res, "nspname");
- i_relname = PQfnumber(res, "relname");
- i_attname = PQfnumber(res, "attname");
+ if ((script = fopen_priv(output_path, "a")) == NULL)
+ pg_fatal("could not open file \"%s\": %m", output_path);
- for (int rowno = 0; rowno < ntups; rowno++)
- {
- if (script == NULL && (script = fopen_priv(output_path, "a")) == NULL)
- pg_fatal("could not open file \"%s\": %m", output_path);
+ fprintf(script, "In database: %s\n", dbinfo->db_name);
- if (!db_used)
- {
- fprintf(script, "In database: %s\n", dbinfo->db_name);
- db_used = true;
- }
- fprintf(script, " %s.%s.%s\n",
- PQgetvalue(res, rowno, i_nspname),
- PQgetvalue(res, rowno, i_relname),
- PQgetvalue(res, rowno, i_attname));
- }
+ for (int rowno = 0; rowno < ntups; rowno++)
+ fprintf(script, " %s.%s.%s\n",
+ PQgetvalue(res, rowno, i_nspname),
+ PQgetvalue(res, rowno, i_relname),
+ PQgetvalue(res, rowno, i_attname));
- if (script)
- {
- fclose(script);
- script = NULL;
- }
- }
+ fclose(script);
}
/*
static void
check_for_data_types_usage(ClusterInfo *cluster)
{
- bool *results;
PQExpBuffer report = NULL;
DataTypesUsageChecks *tmp = data_types_usage_checks;
int n_data_types_usage_checks = 0;
tmp++;
}
- /* Prepare an array to store the results of checks in */
- results = pg_malloc0(sizeof(bool) * n_data_types_usage_checks);
+ /* Allocate memory for queries and for task states */
queries = pg_malloc0(sizeof(char *) * n_data_types_usage_checks);
states = pg_malloc0(sizeof(struct data_type_check_state) * n_data_types_usage_checks);
queries[i] = data_type_check_query(i);
states[i].check = check;
- states[i].result = &results[i];
states[i].report = &report;
upgrade_task_add_step(task, queries[i], process_data_type_check,
destroyPQExpBuffer(report);
}
- pg_free(results);
for (int i = 0; i < n_data_types_usage_checks; i++)
{
if (queries[i])
static void
process_isn_and_int8_passing_mismatch(DbInfo *dbinfo, PGresult *res, void *arg)
{
- bool db_used = false;
int ntups = PQntuples(res);
int i_nspname = PQfnumber(res, "nspname");
int i_proname = PQfnumber(res, "proname");
AssertVariableIsOfType(&process_isn_and_int8_passing_mismatch,
UpgradeTaskProcessCB);
+ if (ntups == 0)
+ return;
+
+ if (report->file == NULL &&
+ (report->file = fopen_priv(report->path, "w")) == NULL)
+ pg_fatal("could not open file \"%s\": %m", report->path);
+
+ fprintf(report->file, "In database: %s\n", dbinfo->db_name);
+
for (int rowno = 0; rowno < ntups; rowno++)
- {
- if (report->file == NULL &&
- (report->file = fopen_priv(report->path, "w")) == NULL)
- pg_fatal("could not open file \"%s\": %m", report->path);
- if (!db_used)
- {
- fprintf(report->file, "In database: %s\n", dbinfo->db_name);
- db_used = true;
- }
fprintf(report->file, " %s.%s\n",
PQgetvalue(res, rowno, i_nspname),
PQgetvalue(res, rowno, i_proname));
- }
}
/*
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
int ntups = PQntuples(res);
- bool db_used = false;
int i_oproid = PQfnumber(res, "oproid");
int i_oprnsp = PQfnumber(res, "oprnsp");
int i_oprname = PQfnumber(res, "oprname");
AssertVariableIsOfType(&process_user_defined_postfix_ops,
UpgradeTaskProcessCB);
- if (!ntups)
+ if (ntups == 0)
return;
+ if (report->file == NULL &&
+ (report->file = fopen_priv(report->path, "w")) == NULL)
+ pg_fatal("could not open file \"%s\": %m", report->path);
+
+ fprintf(report->file, "In database: %s\n", dbinfo->db_name);
+
for (int rowno = 0; rowno < ntups; rowno++)
- {
- if (report->file == NULL &&
- (report->file = fopen_priv(report->path, "w")) == NULL)
- pg_fatal("could not open file \"%s\": %m", report->path);
- if (!db_used)
- {
- fprintf(report->file, "In database: %s\n", dbinfo->db_name);
- db_used = true;
- }
fprintf(report->file, " (oid=%s) %s.%s (%s.%s, NONE)\n",
PQgetvalue(res, rowno, i_oproid),
PQgetvalue(res, rowno, i_oprnsp),
PQgetvalue(res, rowno, i_oprname),
PQgetvalue(res, rowno, i_typnsp),
PQgetvalue(res, rowno, i_typname));
- }
}
/*
process_incompat_polymorphics(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
- bool db_used = false;
int ntups = PQntuples(res);
int i_objkind = PQfnumber(res, "objkind");
int i_objname = PQfnumber(res, "objname");
AssertVariableIsOfType(&process_incompat_polymorphics,
UpgradeTaskProcessCB);
- for (int rowno = 0; rowno < ntups; rowno++)
- {
- if (report->file == NULL &&
- (report->file = fopen_priv(report->path, "w")) == NULL)
- pg_fatal("could not open file \"%s\": %m", report->path);
- if (!db_used)
- {
- fprintf(report->file, "In database: %s\n", dbinfo->db_name);
- db_used = true;
- }
+ if (ntups == 0)
+ return;
+
+ if (report->file == NULL &&
+ (report->file = fopen_priv(report->path, "w")) == NULL)
+ pg_fatal("could not open file \"%s\": %m", report->path);
+ fprintf(report->file, "In database: %s\n", dbinfo->db_name);
+
+ for (int rowno = 0; rowno < ntups; rowno++)
fprintf(report->file, " %s: %s\n",
PQgetvalue(res, rowno, i_objkind),
PQgetvalue(res, rowno, i_objname));
- }
}
/*
process_with_oids_check(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
- bool db_used = false;
int ntups = PQntuples(res);
int i_nspname = PQfnumber(res, "nspname");
int i_relname = PQfnumber(res, "relname");
AssertVariableIsOfType(&process_with_oids_check, UpgradeTaskProcessCB);
- if (!ntups)
+ if (ntups == 0)
return;
+ if (report->file == NULL &&
+ (report->file = fopen_priv(report->path, "w")) == NULL)
+ pg_fatal("could not open file \"%s\": %m", report->path);
+
+ fprintf(report->file, "In database: %s\n", dbinfo->db_name);
+
for (int rowno = 0; rowno < ntups; rowno++)
- {
- if (report->file == NULL &&
- (report->file = fopen_priv(report->path, "w")) == NULL)
- pg_fatal("could not open file \"%s\": %m", report->path);
- if (!db_used)
- {
- fprintf(report->file, "In database: %s\n", dbinfo->db_name);
- db_used = true;
- }
fprintf(report->file, " %s.%s\n",
PQgetvalue(res, rowno, i_nspname),
PQgetvalue(res, rowno, i_relname));
- }
}
/*
process_user_defined_encoding_conversions(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
- bool db_used = false;
int ntups = PQntuples(res);
int i_conoid = PQfnumber(res, "conoid");
int i_conname = PQfnumber(res, "conname");
AssertVariableIsOfType(&process_user_defined_encoding_conversions,
UpgradeTaskProcessCB);
- if (!ntups)
+ if (ntups == 0)
return;
+ if (report->file == NULL &&
+ (report->file = fopen_priv(report->path, "w")) == NULL)
+ pg_fatal("could not open file \"%s\": %m", report->path);
+
+ fprintf(report->file, "In database: %s\n", dbinfo->db_name);
+
for (int rowno = 0; rowno < ntups; rowno++)
- {
- if (report->file == NULL &&
- (report->file = fopen_priv(report->path, "w")) == NULL)
- pg_fatal("could not open file \"%s\": %m", report->path);
- if (!db_used)
- {
- fprintf(report->file, "In database: %s\n", dbinfo->db_name);
- db_used = true;
- }
fprintf(report->file, " (oid=%s) %s.%s\n",
PQgetvalue(res, rowno, i_conoid),
PQgetvalue(res, rowno, i_nspname),
PQgetvalue(res, rowno, i_conname));
- }
}
/*
process_old_sub_state_check(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
- int ntup = PQntuples(res);
+ int ntups = PQntuples(res);
int i_srsubstate = PQfnumber(res, "srsubstate");
int i_subname = PQfnumber(res, "subname");
int i_nspname = PQfnumber(res, "nspname");
AssertVariableIsOfType(&process_old_sub_state_check, UpgradeTaskProcessCB);
- for (int i = 0; i < ntup; i++)
- {
- if (report->file == NULL &&
- (report->file = fopen_priv(report->path, "w")) == NULL)
- pg_fatal("could not open file \"%s\": %m", report->path);
+ if (ntups == 0)
+ return;
+ if (report->file == NULL &&
+ (report->file = fopen_priv(report->path, "w")) == NULL)
+ pg_fatal("could not open file \"%s\": %m", report->path);
+
+ for (int i = 0; i < ntups; i++)
fprintf(report->file, "The table sync state \"%s\" is not allowed for database:\"%s\" subscription:\"%s\" schema:\"%s\" relation:\"%s\"\n",
PQgetvalue(res, i, i_srsubstate),
dbinfo->db_name,
PQgetvalue(res, i, i_subname),
PQgetvalue(res, i, i_nspname),
PQgetvalue(res, i, i_relname));
- }
}
/*