Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd29be5

Browse files
committed
pgbench: Improve error-handling in pgbench.
Previously failures of initial connection and logfile open caused pgbenchto proceed the benchmarking, report the incomplete results and exit withstatus 2. It didn't make sense to proceed the benchmarking even whenpgbench could not start as prescribed.This commit improves pgbench so that early errors that occur whenstarting benchmark such as those failures should make pgbench exitimmediately with status 1.Author: Yugo NagataReviewed-by: Fabien COELHO, Kyotaro Horiguchi, Fujii MasaoDiscussion:https://postgr.es/m/TYCPR01MB5870057375ACA8A73099C649F5349@TYCPR01MB5870.jpnprd01.prod.outlook.com
1 parent3353974 commitcd29be5

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

‎doc/src/sgml/ref/pgbench.sgml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,12 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
904904

905905
<para>
906906
A successful run will exit with status 0. Exit status 1 indicates static
907-
problems such as invalid command-line options. Errors during the run such
908-
as database errors or problems in the script will result in exit status 2.
909-
In the latter case, <application>pgbench</application> will print partial
910-
results.
907+
problems such as invalid command-line options or internal errors which
908+
are supposed to never occur. Early errors that occur when starting
909+
benchmark such as initial connection failures also exit with status 1.
910+
Errors during the run such as database errors or problems in the script
911+
will result in exit status 2. In the latter case,
912+
<application>pgbench</application> will print partial results.
911913
</para>
912914
</refsect1>
913915

‎src/bin/pgbench/pgbench.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,10 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
31813181

31823182
if ((st->con=doConnect())==NULL)
31833183
{
3184+
/*
3185+
* as the bench is already running, we do not abort
3186+
* the process
3187+
*/
31843188
pg_log_error("client %d aborted while establishing connection",st->id);
31853189
st->state=CSTATE_ABORTED;
31863190
break;
@@ -4456,7 +4460,10 @@ runInitSteps(const char *initialize_steps)
44564460
initPQExpBuffer(&stats);
44574461

44584462
if ((con=doConnect())==NULL)
4463+
{
4464+
pg_log_fatal("could not create connection for initialization");
44594465
exit(1);
4466+
}
44604467

44614468
setup_cancel_handler(NULL);
44624469
SetCancelConn(con);
@@ -6399,7 +6406,10 @@ main(int argc, char **argv)
63996406
/* opening connection... */
64006407
con=doConnect();
64016408
if (con==NULL)
6409+
{
6410+
pg_log_fatal("could not create connection for setup");
64026411
exit(1);
6412+
}
64036413

64046414
/* report pgbench and server versions */
64056415
printVersion(con);
@@ -6625,7 +6635,7 @@ threadRun(void *arg)
66256635
if (thread->logfile==NULL)
66266636
{
66276637
pg_log_fatal("could not open logfile \"%s\": %m",logpath);
6628-
gotodone;
6638+
exit(1);
66296639
}
66306640
}
66316641

@@ -6650,16 +6660,10 @@ threadRun(void *arg)
66506660
{
66516661
if ((state[i].con=doConnect())==NULL)
66526662
{
6653-
/*
6654-
* On connection failure, we meet the barrier here in place of
6655-
* GO before proceeding to the "done" path which will cleanup,
6656-
* so as to avoid locking the process.
6657-
*
6658-
* It is unclear whether it is worth doing anything rather
6659-
* than coldly exiting with an error message.
6660-
*/
6661-
THREAD_BARRIER_WAIT(&barrier);
6662-
gotodone;
6663+
/* coldly abort on initial connection failure */
6664+
pg_log_fatal("could not create connection for client %d",
6665+
state[i].id);
6666+
exit(1);
66636667
}
66646668
}
66656669
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp