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

Commit 264aa14

Browse files
committed
pg_upgrade: Split off pg_fatal() from pg_log()
This allows decorating pg_fatal() with noreturn compiler hints, leading to better diagnostics. Reviewed-by: Marko Tiikkaja <marko@joh.to>
1 parent 261c7d4 commit 264aa14

17 files changed

+166
-174
lines changed

contrib/pg_upgrade/check.c

+30-38
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,15 @@ check_new_cluster(void)
158158
* matching install-user oids.
159159
*/
160160
if (old_cluster.install_role_oid != new_cluster.install_role_oid)
161-
pg_log(PG_FATAL,
162-
"Old and new cluster install users have different values for pg_authid.oid.\n");
161+
pg_fatal("Old and new cluster install users have different values for pg_authid.oid.\n");
163162

164163
/*
165164
* We only allow the install user in the new cluster because other defined
166165
* users might match users defined in the old cluster and generate an
167166
* error during pg_dump restore.
168167
*/
169168
if (new_cluster.role_count != 1)
170-
pg_log(PG_FATAL, "Only the install user can be defined in the new cluster.\n");
169+
pg_fatal("Only the install user can be defined in the new cluster.\n");
171170

172171
check_for_prepared_transactions(&new_cluster);
173172
}
@@ -271,11 +270,11 @@ check_cluster_versions(void)
271270
*/
272271

273272
if (GET_MAJOR_VERSION(old_cluster.major_version) < 803)
274-
pg_log(PG_FATAL, "This utility can only upgrade from PostgreSQL version 8.3 and later.\n");
273+
pg_fatal("This utility can only upgrade from PostgreSQL version 8.3 and later.\n");
275274

276275
/* Only current PG version is supported as a target */
277276
if (GET_MAJOR_VERSION(new_cluster.major_version) != GET_MAJOR_VERSION(PG_VERSION_NUM))
278-
pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version %s.\n",
277+
pg_fatal("This utility can only upgrade to PostgreSQL version %s.\n",
279278
PG_MAJORVERSION);
280279

281280
/*
@@ -284,7 +283,7 @@ check_cluster_versions(void)
284283
* versions.
285284
*/
286285
if (old_cluster.major_version > new_cluster.major_version)
287-
pg_log(PG_FATAL, "This utility cannot be used to downgrade to older major PostgreSQL versions.\n");
286+
pg_fatal("This utility cannot be used to downgrade to older major PostgreSQL versions.\n");
288287

289288
/* get old and new binary versions */
290289
get_bin_version(&old_cluster);
@@ -293,12 +292,10 @@ check_cluster_versions(void)
293292
/* Ensure binaries match the designated data directories */
294293
if (GET_MAJOR_VERSION(old_cluster.major_version) !=
295294
GET_MAJOR_VERSION(old_cluster.bin_version))
296-
pg_log(PG_FATAL,
297-
"Old cluster data and binary directories are from different major versions.\n");
295+
pg_fatal("Old cluster data and binary directories are from different major versions.\n");
298296
if (GET_MAJOR_VERSION(new_cluster.major_version) !=
299297
GET_MAJOR_VERSION(new_cluster.bin_version))
300-
pg_log(PG_FATAL,
301-
"New cluster data and binary directories are from different major versions.\n");
298+
pg_fatal("New cluster data and binary directories are from different major versions.\n");
302299

303300
check_ok();
304301
}
@@ -315,17 +312,17 @@ check_cluster_compatibility(bool live_check)
315312
/* Is it 9.0 but without tablespace directories? */
316313
if (GET_MAJOR_VERSION(new_cluster.major_version) == 900 &&
317314
new_cluster.controldata.cat_ver < TABLE_SPACE_SUBDIRS_CAT_VER)
318-
pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
315+
pg_fatal("This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
319316
"because of backend API changes made during development.\n");
320317

321318
/* We read the real port number for PG >= 9.1 */
322319
if (live_check && GET_MAJOR_VERSION(old_cluster.major_version) < 901 &&
323320
old_cluster.port == DEF_PGUPORT)
324-
pg_log(PG_FATAL, "When checking a pre-PG 9.1 live old server, "
321+
pg_fatal("When checking a pre-PG 9.1 live old server, "
325322
"you must specify the old server's port number.\n");
326323

327324
if (live_check && old_cluster.port == new_cluster.port)
328-
pg_log(PG_FATAL, "When checking a live server, "
325+
pg_fatal("When checking a live server, "
329326
"the old and new port numbers must be different.\n");
330327
}
331328

@@ -413,16 +410,13 @@ check_locale_and_encoding(ControlData *oldctrl,
413410
* UTF-8 vs. UTF8, so at least we display the mismatching values.
414411
*/
415412
if (pg_strcasecmp(oldctrl->lc_collate, newctrl->lc_collate) != 0)
416-
pg_log(PG_FATAL,
417-
"lc_collate cluster values do not match: old \"%s\", new \"%s\"\n",
413+
pg_fatal("lc_collate cluster values do not match: old \"%s\", new \"%s\"\n",
418414
oldctrl->lc_collate, newctrl->lc_collate);
419415
if (pg_strcasecmp(oldctrl->lc_ctype, newctrl->lc_ctype) != 0)
420-
pg_log(PG_FATAL,
421-
"lc_ctype cluster values do not match: old \"%s\", new \"%s\"\n",
416+
pg_fatal("lc_ctype cluster values do not match: old \"%s\", new \"%s\"\n",
422417
oldctrl->lc_ctype, newctrl->lc_ctype);
423418
if (pg_strcasecmp(oldctrl->encoding, newctrl->encoding) != 0)
424-
pg_log(PG_FATAL,
425-
"encoding cluster values do not match: old \"%s\", new \"%s\"\n",
419+
pg_fatal("encoding cluster values do not match: old \"%s\", new \"%s\"\n",
426420
oldctrl->encoding, newctrl->encoding);
427421
}
428422

@@ -442,7 +436,7 @@ check_new_cluster_is_empty(void)
442436
{
443437
/* pg_largeobject and its index should be skipped */
444438
if (strcmp(rel_arr->rels[relnum].nspname, "pg_catalog") != 0)
445-
pg_log(PG_FATAL, "New cluster database \"%s\" is not empty\n",
439+
pg_fatal("New cluster database \"%s\" is not empty\n",
446440
new_cluster.dbarr.dbs[dbnum].db_name);
447441
}
448442
}
@@ -475,7 +469,7 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
475469
SCRIPT_EXT);
476470

477471
if ((script = fopen_priv(*analyze_script_file_name, "w")) == NULL)
478-
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
472+
pg_fatal("Could not open file \"%s\": %s\n",
479473
*analyze_script_file_name, getErrorText(errno));
480474

481475
#ifndef WIN32
@@ -580,7 +574,7 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
580574

581575
#ifndef WIN32
582576
if (chmod(*analyze_script_file_name, S_IRWXU) != 0)
583-
pg_log(PG_FATAL, "Could not add execute permission to file \"%s\": %s\n",
577+
pg_fatal("Could not add execute permission to file \"%s\": %s\n",
584578
*analyze_script_file_name, getErrorText(errno));
585579
#endif
586580

@@ -634,7 +628,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
634628
prep_status("Creating script to delete old cluster");
635629

636630
if ((script = fopen_priv(*deletion_script_file_name, "w")) == NULL)
637-
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
631+
pg_fatal("Could not open file \"%s\": %s\n",
638632
*deletion_script_file_name, getErrorText(errno));
639633

640634
#ifndef WIN32
@@ -688,7 +682,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
688682

689683
#ifndef WIN32
690684
if (chmod(*deletion_script_file_name, S_IRWXU) != 0)
691-
pg_log(PG_FATAL, "Could not add execute permission to file \"%s\": %s\n",
685+
pg_fatal("Could not add execute permission to file \"%s\": %s\n",
692686
*deletion_script_file_name, getErrorText(errno));
693687
#endif
694688

@@ -716,7 +710,7 @@ check_is_super_user(ClusterInfo *cluster)
716710
"WHERE rolname = current_user");
717711

718712
if (PQntuples(res) != 1 || strcmp(PQgetvalue(res, 0, 0), "t") != 0)
719-
pg_log(PG_FATAL, "database user \"%s\" is not a superuser\n",
713+
pg_fatal("database user \"%s\" is not a superuser\n",
720714
os_info.user);
721715

722716
cluster->install_role_oid = atooid(PQgetvalue(res, 0, 1));
@@ -728,7 +722,7 @@ check_is_super_user(ClusterInfo *cluster)
728722
"FROM pg_catalog.pg_roles ");
729723

730724
if (PQntuples(res) != 1)
731-
pg_log(PG_FATAL, "could not determine the number of users\n");
725+
pg_fatal("could not determine the number of users\n");
732726

733727
cluster->role_count = atoi(PQgetvalue(res, 0, 0));
734728

@@ -759,7 +753,7 @@ check_for_prepared_transactions(ClusterInfo *cluster)
759753
"FROM pg_catalog.pg_prepared_xacts");
760754

761755
if (PQntuples(res) != 0)
762-
pg_log(PG_FATAL, "The %s cluster contains prepared transactions\n",
756+
pg_fatal("The %s cluster contains prepared transactions\n",
763757
CLUSTER_NAME(cluster));
764758

765759
PQclear(res);
@@ -824,7 +818,7 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
824818
{
825819
found = true;
826820
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
827-
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
821+
pg_fatal("Could not open file \"%s\": %s\n",
828822
output_path, getErrorText(errno));
829823
if (!db_used)
830824
{
@@ -847,8 +841,7 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
847841
if (found)
848842
{
849843
pg_log(PG_REPORT, "fatal\n");
850-
pg_log(PG_FATAL,
851-
"Your installation contains \"contrib/isn\" functions which rely on the\n"
844+
pg_fatal("Your installation contains \"contrib/isn\" functions which rely on the\n"
852845
"bigint data type. Your old and new clusters pass bigint values\n"
853846
"differently so this cluster cannot currently be upgraded. You can\n"
854847
"manually upgrade databases that use \"contrib/isn\" facilities and remove\n"
@@ -929,7 +922,7 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
929922
{
930923
found = true;
931924
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
932-
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
925+
pg_fatal("Could not open file \"%s\": %s\n",
933926
output_path, getErrorText(errno));
934927
if (!db_used)
935928
{
@@ -953,8 +946,7 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
953946
if (found)
954947
{
955948
pg_log(PG_REPORT, "fatal\n");
956-
pg_log(PG_FATAL,
957-
"Your installation contains one of the reg* data types in user tables.\n"
949+
pg_fatal("Your installation contains one of the reg* data types in user tables.\n"
958950
"These data types reference system OIDs that are not preserved by\n"
959951
"pg_upgrade, so this cluster cannot currently be upgraded. You can\n"
960952
"remove the problem tables and restart the upgrade. A list of the problem\n"
@@ -979,7 +971,7 @@ get_bin_version(ClusterInfo *cluster)
979971

980972
if ((output = popen(cmd, "r")) == NULL ||
981973
fgets(cmd_output, sizeof(cmd_output), output) == NULL)
982-
pg_log(PG_FATAL, "Could not get pg_ctl version data using %s: %s\n",
974+
pg_fatal("Could not get pg_ctl version data using %s: %s\n",
983975
cmd, getErrorText(errno));
984976

985977
pclose(output);
@@ -989,7 +981,7 @@ get_bin_version(ClusterInfo *cluster)
989981
*strchr(cmd_output, '\n') = '\0';
990982

991983
if (sscanf(cmd_output, "%*s %*s %d.%d", &pre_dot, &post_dot) != 2)
992-
pg_log(PG_FATAL, "could not get version from %s\n", cmd);
984+
pg_fatal("could not get version from %s\n", cmd);
993985

994986
cluster->bin_version = (pre_dot * 100 + post_dot) * 100;
995987
}
@@ -1009,7 +1001,7 @@ get_canonical_locale_name(int category, const char *locale)
10091001

10101002
save = setlocale(category, NULL);
10111003
if (!save)
1012-
pg_log(PG_FATAL, "failed to get the current locale\n");
1004+
pg_fatal("failed to get the current locale\n");
10131005

10141006
/* 'save' may be pointing at a modifiable scratch variable, so copy it. */
10151007
save = pg_strdup(save);
@@ -1018,13 +1010,13 @@ get_canonical_locale_name(int category, const char *locale)
10181010
res = setlocale(category, locale);
10191011

10201012
if (!res)
1021-
pg_log(PG_FATAL, "failed to get system local name for \"%s\"\n", res);
1013+
pg_fatal("failed to get system local name for \"%s\"\n", res);
10221014

10231015
res = pg_strdup(res);
10241016

10251017
/* restore old value. */
10261018
if (!setlocale(category, save))
1027-
pg_log(PG_FATAL, "failed to restore old locale \"%s\"\n", save);
1019+
pg_fatal("failed to restore old locale \"%s\"\n", save);
10281020

10291021
pg_free(save);
10301022

0 commit comments

Comments
 (0)