The experiences with elog() and ereport() have shown that having one
function that can return or not depending on some log level parameter
isn't a good idea when you want to communicate well with the compiler.
In pg_upgrade, there is a similar case with the pg_log() function.
Since that isn't a public API, I'm proposing to change it and introduce
a separate function pg_fatal() for those cases where the calls don't
return.
From 12ae7ed2b4174f694f67f31ac18eb1fe22d30ef9 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut pete...@gmx.net
Date: Wed, 11 Sep 2013 22:43:03 -0400
Subject: [PATCH] pg_upgrade: Split off pg_fatal() from pg_log()
This allows decorating pg_fatal() with noreturn compiler hints, leading
to better diagnostics.
---
contrib/pg_upgrade/check.c | 68 --
contrib/pg_upgrade/controldata.c | 92
contrib/pg_upgrade/exec.c| 21
contrib/pg_upgrade/file.c| 3 +-
contrib/pg_upgrade/function.c| 11 ++---
contrib/pg_upgrade/info.c| 6 +--
contrib/pg_upgrade/option.c | 23 +
contrib/pg_upgrade/page.c| 6 +--
contrib/pg_upgrade/parallel.c| 12 ++---
contrib/pg_upgrade/pg_upgrade.c | 8 ++--
contrib/pg_upgrade/pg_upgrade.h | 3 ++
contrib/pg_upgrade/relfilenode.c | 11 ++---
contrib/pg_upgrade/server.c | 11 ++---
contrib/pg_upgrade/tablespace.c | 3 +-
contrib/pg_upgrade/util.c| 35 +++---
contrib/pg_upgrade/version.c | 2 +-
contrib/pg_upgrade/version_old_8_3.c | 23 -
17 files changed, 165 insertions(+), 173 deletions(-)
diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c
index 0376fcb..1a37b79 100644
--- a/contrib/pg_upgrade/check.c
+++ b/contrib/pg_upgrade/check.c
@@ -158,8 +158,7 @@ static void check_locale_and_encoding(ControlData *oldctrl,
* matching install-user oids.
*/
if (old_cluster.install_role_oid != new_cluster.install_role_oid)
- pg_log(PG_FATAL,
- Old and new cluster install users have different values for pg_authid.oid.\n);
+ pg_fatal(Old and new cluster install users have different values for pg_authid.oid.\n);
/*
* We only allow the install user in the new cluster because other defined
@@ -167,7 +166,7 @@ static void check_locale_and_encoding(ControlData *oldctrl,
* error during pg_dump restore.
*/
if (new_cluster.role_count != 1)
- pg_log(PG_FATAL, Only the install user can be defined in the new cluster.\n);
+ pg_fatal(Only the install user can be defined in the new cluster.\n);
check_for_prepared_transactions(new_cluster);
}
@@ -271,11 +270,11 @@ static void check_locale_and_encoding(ControlData *oldctrl,
*/
if (GET_MAJOR_VERSION(old_cluster.major_version) 803)
- pg_log(PG_FATAL, This utility can only upgrade from PostgreSQL version 8.3 and later.\n);
+ pg_fatal(This utility can only upgrade from PostgreSQL version 8.3 and later.\n);
/* Only current PG version is supported as a target */
if (GET_MAJOR_VERSION(new_cluster.major_version) != GET_MAJOR_VERSION(PG_VERSION_NUM))
- pg_log(PG_FATAL, This utility can only upgrade to PostgreSQL version %s.\n,
+ pg_fatal(This utility can only upgrade to PostgreSQL version %s.\n,
PG_MAJORVERSION);
/*
@@ -284,7 +283,7 @@ static void check_locale_and_encoding(ControlData *oldctrl,
* versions.
*/
if (old_cluster.major_version new_cluster.major_version)
- pg_log(PG_FATAL, This utility cannot be used to downgrade to older major PostgreSQL versions.\n);
+ pg_fatal(This utility cannot be used to downgrade to older major PostgreSQL versions.\n);
/* get old and new binary versions */
get_bin_version(old_cluster);
@@ -293,12 +292,10 @@ static void check_locale_and_encoding(ControlData *oldctrl,
/* Ensure binaries match the designated data directories */
if (GET_MAJOR_VERSION(old_cluster.major_version) !=
GET_MAJOR_VERSION(old_cluster.bin_version))
- pg_log(PG_FATAL,
- Old cluster data and binary directories are from different major versions.\n);
+ pg_fatal(Old cluster data and binary directories are from different major versions.\n);
if (GET_MAJOR_VERSION(new_cluster.major_version) !=
GET_MAJOR_VERSION(new_cluster.bin_version))
- pg_log(PG_FATAL,
- New cluster data and binary directories are from different major versions.\n);
+ pg_fatal(New cluster data and binary directories are from different major versions.\n);
check_ok();
}
@@ -315,17 +312,17 @@ static void check_locale_and_encoding(ControlData *oldctrl,
/* Is it 9.0 but without tablespace directories? */
if (GET_MAJOR_VERSION(new_cluster.major_version) == 900
new_cluster.controldata.cat_ver TABLE_SPACE_SUBDIRS_CAT_VER)
- pg_log(PG_FATAL, This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n
+ pg_fatal(This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n
because of backend API