Skip to content

Commit 337be37

Browse files
committed
pgbench: consolidate a few PQfinish calls.
Author: Doug Rady Discussion: https://postgr.es/m/6323D83C-9FDA-4EE1-B0ED-6971E585066A@amazon.com
1 parent d79e7e9 commit 337be37

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ static void pgbench_error(const char *fmt,...) pg_attribute_printf(1, 2);
502502
static void addScript(ParsedScript script);
503503
static void *threadRun(void *arg);
504504
static void setalarm(int seconds);
505+
static void finishCon(CState *st);
505506

506507

507508
/* callback functions for our flex lexer */
@@ -2982,8 +2983,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
29822983

29832984
if (is_connect)
29842985
{
2985-
PQfinish(st->con);
2986-
st->con = NULL;
2986+
finishCon(st);
29872987
INSTR_TIME_SET_ZERO(now);
29882988
}
29892989

@@ -3020,11 +3020,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
30203020
*/
30213021
case CSTATE_ABORTED:
30223022
case CSTATE_FINISHED:
3023-
if (st->con != NULL)
3024-
{
3025-
PQfinish(st->con);
3026-
st->con = NULL;
3027-
}
3023+
finishCon(st);
30283024
return;
30293025
}
30303026
}
@@ -3172,13 +3168,7 @@ disconnect_all(CState *state, int length)
31723168
int i;
31733169

31743170
for (i = 0; i < length; i++)
3175-
{
3176-
if (state[i].con)
3177-
{
3178-
PQfinish(state[i].con);
3179-
state[i].con = NULL;
3180-
}
3181-
}
3171+
finishCon(&state[i]);
31823172
}
31833173

31843174
/*
@@ -5266,8 +5256,7 @@ threadRun(void *arg)
52665256
{
52675257
/* interrupt client that has not started a transaction */
52685258
st->state = CSTATE_FINISHED;
5269-
PQfinish(st->con);
5270-
st->con = NULL;
5259+
finishCon(st);
52715260
remains--;
52725261
}
52735262
else if (st->state == CSTATE_SLEEP || st->state == CSTATE_THROTTLE)
@@ -5547,6 +5536,16 @@ threadRun(void *arg)
55475536
return NULL;
55485537
}
55495538

5539+
static void
5540+
finishCon(CState *st)
5541+
{
5542+
if (st->con != NULL)
5543+
{
5544+
PQfinish(st->con);
5545+
st->con = NULL;
5546+
}
5547+
}
5548+
55505549
/*
55515550
* Support for duration option: set timer_exceeded after so many seconds.
55525551
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy