Commit 337be37d authored by Andres Freund's avatar Andres Freund

pgbench: consolidate a few PQfinish calls.

Author: Doug Rady
Discussion: https://postgr.es/m/6323D83C-9FDA-4EE1-B0ED-6971E585066A@amazon.com
parent d79e7e92
...@@ -502,6 +502,7 @@ static void pgbench_error(const char *fmt,...) pg_attribute_printf(1, 2); ...@@ -502,6 +502,7 @@ static void pgbench_error(const char *fmt,...) pg_attribute_printf(1, 2);
static void addScript(ParsedScript script); static void addScript(ParsedScript script);
static void *threadRun(void *arg); static void *threadRun(void *arg);
static void setalarm(int seconds); static void setalarm(int seconds);
static void finishCon(CState *st);
/* callback functions for our flex lexer */ /* callback functions for our flex lexer */
...@@ -2982,8 +2983,7 @@ doCustom(TState *thread, CState *st, StatsData *agg) ...@@ -2982,8 +2983,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
if (is_connect) if (is_connect)
{ {
PQfinish(st->con); finishCon(st);
st->con = NULL;
INSTR_TIME_SET_ZERO(now); INSTR_TIME_SET_ZERO(now);
} }
...@@ -3020,11 +3020,7 @@ doCustom(TState *thread, CState *st, StatsData *agg) ...@@ -3020,11 +3020,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
*/ */
case CSTATE_ABORTED: case CSTATE_ABORTED:
case CSTATE_FINISHED: case CSTATE_FINISHED:
if (st->con != NULL) finishCon(st);
{
PQfinish(st->con);
st->con = NULL;
}
return; return;
} }
} }
...@@ -3172,13 +3168,7 @@ disconnect_all(CState *state, int length) ...@@ -3172,13 +3168,7 @@ disconnect_all(CState *state, int length)
int i; int i;
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{ finishCon(&state[i]);
if (state[i].con)
{
PQfinish(state[i].con);
state[i].con = NULL;
}
}
} }
/* /*
...@@ -5266,8 +5256,7 @@ threadRun(void *arg) ...@@ -5266,8 +5256,7 @@ threadRun(void *arg)
{ {
/* interrupt client that has not started a transaction */ /* interrupt client that has not started a transaction */
st->state = CSTATE_FINISHED; st->state = CSTATE_FINISHED;
PQfinish(st->con); finishCon(st);
st->con = NULL;
remains--; remains--;
} }
else if (st->state == CSTATE_SLEEP || st->state == CSTATE_THROTTLE) else if (st->state == CSTATE_SLEEP || st->state == CSTATE_THROTTLE)
...@@ -5547,6 +5536,16 @@ done: ...@@ -5547,6 +5536,16 @@ done:
return NULL; return NULL;
} }
static void
finishCon(CState *st)
{
if (st->con != NULL)
{
PQfinish(st->con);
st->con = NULL;
}
}
/* /*
* Support for duration option: set timer_exceeded after so many seconds. * Support for duration option: set timer_exceeded after so many seconds.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment