Commit 5b3cc1af authored by Alvaro Herrera's avatar Alvaro Herrera

Mostly mechanical cleanup of pgbench

pgindent for recent commits; also change some variables from int to
boolean, which is how they are really used.

Mostly submitted by Fabien Coelho; this is in preparation to commit
further patches to the file.
parent b8682a71
...@@ -201,16 +201,15 @@ typedef struct ...@@ -201,16 +201,15 @@ typedef struct
PGconn *con; /* connection handle to DB */ PGconn *con; /* connection handle to DB */
int id; /* client No. */ int id; /* client No. */
int state; /* state No. */ int state; /* state No. */
int listen; /* 0 indicates that an async query has been bool listen; /* whether an async query has been sent */
* sent */ bool is_throttled; /* whether transaction throttling is done */
int sleeping; /* 1 indicates that the client is napping */ bool sleeping; /* whether the client is napping */
bool throttling; /* whether nap is for throttling */ bool throttling; /* whether nap is for throttling */
Variable *variables; /* array of variable definitions */ Variable *variables; /* array of variable definitions */
int nvariables; int nvariables;
int64 txn_scheduled; /* scheduled start time of transaction (usec) */ int64 txn_scheduled; /* scheduled start time of transaction (usec) */
instr_time txn_begin; /* used for measuring schedule lag times */ instr_time txn_begin; /* used for measuring schedule lag times */
instr_time stmt_begin; /* used for measuring statement latencies */ instr_time stmt_begin; /* used for measuring statement latencies */
bool is_throttled; /* whether transaction throttling is done */
int use_file; /* index in sql_files for this client */ int use_file; /* index in sql_files for this client */
bool prepared[MAX_FILES]; bool prepared[MAX_FILES];
...@@ -520,16 +519,16 @@ getGaussianRand(TState *thread, int64 min, int64 max, double parameter) ...@@ -520,16 +519,16 @@ getGaussianRand(TState *thread, int64 min, int64 max, double parameter)
double rand; double rand;
/* /*
* Get user specified random number from this loop, * Get user specified random number from this loop, with -parameter <
* with -parameter < stdev <= parameter * stdev <= parameter
* *
* This loop is executed until the number is in the expected range. * This loop is executed until the number is in the expected range.
* *
* As the minimum parameter is 2.0, the probability of looping is low: * As the minimum parameter is 2.0, the probability of looping is low:
* sqrt(-2 ln(r)) <= 2 => r >= e^{-2} ~ 0.135, then when taking the * sqrt(-2 ln(r)) <= 2 => r >= e^{-2} ~ 0.135, then when taking the
* average sinus multiplier as 2/pi, we have a 8.6% looping probability in * average sinus multiplier as 2/pi, we have a 8.6% looping probability in
* the worst case. For a parameter value of 5.0, the looping probability is * the worst case. For a parameter value of 5.0, the looping probability
* about e^{-5} * 2 / pi ~ 0.43%. * is about e^{-5} * 2 / pi ~ 0.43%.
*/ */
do do
{ {
...@@ -1191,7 +1190,7 @@ top: ...@@ -1191,7 +1190,7 @@ top:
} }
} }
st->sleeping = 1; st->sleeping = true;
st->throttling = true; st->throttling = true;
st->is_throttled = true; st->is_throttled = true;
if (debug) if (debug)
...@@ -1208,7 +1207,8 @@ top: ...@@ -1208,7 +1207,8 @@ top:
now_us = INSTR_TIME_GET_MICROSEC(now); now_us = INSTR_TIME_GET_MICROSEC(now);
if (st->txn_scheduled <= now_us) if (st->txn_scheduled <= now_us)
{ {
st->sleeping = 0; /* Done sleeping, go ahead with next command */ /* Done sleeping, go ahead with next command */
st->sleeping = false;
if (st->throttling) if (st->throttling)
{ {
/* Measure lag of throttled transaction relative to target */ /* Measure lag of throttled transaction relative to target */
...@@ -1337,9 +1337,9 @@ top: ...@@ -1337,9 +1337,9 @@ top:
* nothing to listen to right now. When throttling rate limits * nothing to listen to right now. When throttling rate limits
* are active, a sleep will happen next, as the next transaction * are active, a sleep will happen next, as the next transaction
* starts. And then in any case the next SQL command will set * starts. And then in any case the next SQL command will set
* listen back to 1. * listen back to true.
*/ */
st->listen = 0; st->listen = false;
trans_needs_throttle = (throttle_delay > 0); trans_needs_throttle = (throttle_delay > 0);
} }
} }
...@@ -1462,7 +1462,7 @@ top: ...@@ -1462,7 +1462,7 @@ top:
st->ecnt++; st->ecnt++;
} }
else else
st->listen = 1; /* flags that should be listened */ st->listen = true; /* flags that should be listened */
} }
else if (commands[st->state]->type == META_COMMAND) else if (commands[st->state]->type == META_COMMAND)
{ {
...@@ -1613,7 +1613,7 @@ top: ...@@ -1613,7 +1613,7 @@ top:
return true; return true;
} }
st->listen = 1; st->listen = true;
} }
else if (pg_strcasecmp(argv[0], "set") == 0) else if (pg_strcasecmp(argv[0], "set") == 0)
{ {
...@@ -1634,7 +1634,7 @@ top: ...@@ -1634,7 +1634,7 @@ top:
return true; return true;
} }
st->listen = 1; st->listen = true;
} }
else if (pg_strcasecmp(argv[0], "sleep") == 0) else if (pg_strcasecmp(argv[0], "sleep") == 0)
{ {
...@@ -1668,9 +1668,9 @@ top: ...@@ -1668,9 +1668,9 @@ top:
INSTR_TIME_SET_CURRENT(now); INSTR_TIME_SET_CURRENT(now);
st->txn_scheduled = INSTR_TIME_GET_MICROSEC(now) + usec; st->txn_scheduled = INSTR_TIME_GET_MICROSEC(now) + usec;
st->sleeping = 1; st->sleeping = true;
st->listen = 1; st->listen = true;
} }
else if (pg_strcasecmp(argv[0], "setshell") == 0) else if (pg_strcasecmp(argv[0], "setshell") == 0)
{ {
...@@ -1684,7 +1684,7 @@ top: ...@@ -1684,7 +1684,7 @@ top:
return true; return true;
} }
else /* succeeded */ else /* succeeded */
st->listen = 1; st->listen = true;
} }
else if (pg_strcasecmp(argv[0], "shell") == 0) else if (pg_strcasecmp(argv[0], "shell") == 0)
{ {
...@@ -1698,7 +1698,7 @@ top: ...@@ -1698,7 +1698,7 @@ top:
return true; return true;
} }
else /* succeeded */ else /* succeeded */
st->listen = 1; st->listen = true;
} }
goto top; goto top;
} }
...@@ -2207,7 +2207,8 @@ parseQuery(Command *cmd, const char *raw_sql) ...@@ -2207,7 +2207,8 @@ parseQuery(Command *cmd, const char *raw_sql)
return true; return true;
} }
void pg_attribute_noreturn() void
pg_attribute_noreturn()
syntax_error(const char *source, const int lineno, syntax_error(const char *source, const int lineno,
const char *line, const char *command, const char *line, const char *command,
const char *msg, const char *more, const int column) const char *msg, const char *more, const int column)
...@@ -2289,7 +2290,7 @@ process_commands(char *buf, const char *source, const int lineno) ...@@ -2289,7 +2290,7 @@ process_commands(char *buf, const char *source, const int lineno)
if (pg_strcasecmp(my_commands->argv[0], "setrandom") == 0) if (pg_strcasecmp(my_commands->argv[0], "setrandom") == 0)
{ {
/* /*--------
* parsing: * parsing:
* \setrandom variable min max [uniform] * \setrandom variable min max [uniform]
* \setrandom variable min max (gaussian|exponential) parameter * \setrandom variable min max (gaussian|exponential) parameter
...@@ -2762,12 +2763,14 @@ main(int argc, char **argv) ...@@ -2762,12 +2763,14 @@ main(int argc, char **argv)
{"initialize", no_argument, NULL, 'i'}, {"initialize", no_argument, NULL, 'i'},
{"jobs", required_argument, NULL, 'j'}, {"jobs", required_argument, NULL, 'j'},
{"log", no_argument, NULL, 'l'}, {"log", no_argument, NULL, 'l'},
{"latency-limit", required_argument, NULL, 'L'},
{"no-vacuum", no_argument, NULL, 'n'}, {"no-vacuum", no_argument, NULL, 'n'},
{"port", required_argument, NULL, 'p'}, {"port", required_argument, NULL, 'p'},
{"progress", required_argument, NULL, 'P'}, {"progress", required_argument, NULL, 'P'},
{"protocol", required_argument, NULL, 'M'}, {"protocol", required_argument, NULL, 'M'},
{"quiet", no_argument, NULL, 'q'}, {"quiet", no_argument, NULL, 'q'},
{"report-latencies", no_argument, NULL, 'r'}, {"report-latencies", no_argument, NULL, 'r'},
{"rate", required_argument, NULL, 'R'},
{"scale", required_argument, NULL, 's'}, {"scale", required_argument, NULL, 's'},
{"select-only", no_argument, NULL, 'S'}, {"select-only", no_argument, NULL, 'S'},
{"skip-some-updates", no_argument, NULL, 'N'}, {"skip-some-updates", no_argument, NULL, 'N'},
...@@ -2782,8 +2785,6 @@ main(int argc, char **argv) ...@@ -2782,8 +2785,6 @@ main(int argc, char **argv)
{"unlogged-tables", no_argument, &unlogged_tables, 1}, {"unlogged-tables", no_argument, &unlogged_tables, 1},
{"sampling-rate", required_argument, NULL, 4}, {"sampling-rate", required_argument, NULL, 4},
{"aggregate-interval", required_argument, NULL, 5}, {"aggregate-interval", required_argument, NULL, 5},
{"rate", required_argument, NULL, 'R'},
{"latency-limit", required_argument, NULL, 'L'},
{"progress-timestamp", no_argument, NULL, 6}, {"progress-timestamp", no_argument, NULL, 6},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
...@@ -3627,7 +3628,7 @@ threadRun(void *arg) ...@@ -3627,7 +3628,7 @@ threadRun(void *arg)
{ {
/* interrupt client which has not started a transaction */ /* interrupt client which has not started a transaction */
remains--; remains--;
st->sleeping = 0; st->sleeping = false;
st->throttling = false; st->throttling = false;
PQfinish(st->con); PQfinish(st->con);
st->con = NULL; st->con = NULL;
......
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