diff options
author | Fujii Masao <fujii@postgresql.org> | 2021-11-02 22:49:57 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2021-11-02 22:49:57 +0900 |
commit | cd29be5459f0e138c0f19d49ee588feeda78e3c9 (patch) | |
tree | 0612bf66984245df7cca39fdd074865aa9649a59 /src | |
parent | 335397456b7e3f9f619038cb322fbfc9dd649d4f (diff) | |
download | postgresql-cd29be5459f0e138c0f19d49ee588feeda78e3c9.tar.gz postgresql-cd29be5459f0e138c0f19d49ee588feeda78e3c9.zip |
pgbench: Improve error-handling in pgbench.
Previously failures of initial connection and logfile open caused pgbench
to proceed the benchmarking, report the incomplete results and exit with
status 2. It didn't make sense to proceed the benchmarking even when
pgbench could not start as prescribed.
This commit improves pgbench so that early errors that occur when
starting benchmark such as those failures should make pgbench exit
immediately with status 1.
Author: Yugo Nagata
Reviewed-by: Fabien COELHO, Kyotaro Horiguchi, Fujii Masao
Discussion: https://postgr.es/m/TYCPR01MB5870057375ACA8A73099C649F5349@TYCPR01MB5870.jpnprd01.prod.outlook.com
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pgbench/pgbench.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index d17f69333f4..0dfb625a888 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -3181,6 +3181,10 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg) if ((st->con = doConnect()) == NULL) { + /* + * as the bench is already running, we do not abort + * the process + */ pg_log_error("client %d aborted while establishing connection", st->id); st->state = CSTATE_ABORTED; break; @@ -4456,7 +4460,10 @@ runInitSteps(const char *initialize_steps) initPQExpBuffer(&stats); if ((con = doConnect()) == NULL) + { + pg_log_fatal("could not create connection for initialization"); exit(1); + } setup_cancel_handler(NULL); SetCancelConn(con); @@ -6399,7 +6406,10 @@ main(int argc, char **argv) /* opening connection... */ con = doConnect(); if (con == NULL) + { + pg_log_fatal("could not create connection for setup"); exit(1); + } /* report pgbench and server versions */ printVersion(con); @@ -6625,7 +6635,7 @@ threadRun(void *arg) if (thread->logfile == NULL) { pg_log_fatal("could not open logfile \"%s\": %m", logpath); - goto done; + exit(1); } } @@ -6650,16 +6660,10 @@ threadRun(void *arg) { if ((state[i].con = doConnect()) == NULL) { - /* - * On connection failure, we meet the barrier here in place of - * GO before proceeding to the "done" path which will cleanup, - * so as to avoid locking the process. - * - * It is unclear whether it is worth doing anything rather - * than coldly exiting with an error message. - */ - THREAD_BARRIER_WAIT(&barrier); - goto done; + /* coldly abort on initial connection failure */ + pg_log_fatal("could not create connection for client %d", + state[i].id); + exit(1); } } } |