mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-07 19:47:50 +08:00
Enhance pgbench's option checking.
Now benchmarking options such as -c cannot be used if initializing option (-i) is specified. Also initializing options such as -F cannot be used if initializing option is not specified. Tatsuo Ishii and Fabien COELHO.
This commit is contained in:
parent
3e3f65973a
commit
51222a1766
@ -2520,6 +2520,9 @@ main(int argc, char **argv)
|
|||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
bool scale_given = false;
|
bool scale_given = false;
|
||||||
|
|
||||||
|
bool benchmarking_option_set = false;
|
||||||
|
bool initialization_option_set = false;
|
||||||
|
|
||||||
CState *state; /* status of clients */
|
CState *state; /* status of clients */
|
||||||
TState *threads; /* array of thread */
|
TState *threads; /* array of thread */
|
||||||
|
|
||||||
@ -2599,11 +2602,14 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
ttype = 1;
|
ttype = 1;
|
||||||
|
benchmarking_option_set = true;
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
ttype = 2;
|
ttype = 2;
|
||||||
|
benchmarking_option_set = true;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
|
benchmarking_option_set = true;
|
||||||
nclients = atoi(optarg);
|
nclients = atoi(optarg);
|
||||||
if (nclients <= 0 || nclients > MAXCLIENTS)
|
if (nclients <= 0 || nclients > MAXCLIENTS)
|
||||||
{
|
{
|
||||||
@ -2629,6 +2635,7 @@ main(int argc, char **argv)
|
|||||||
#endif /* HAVE_GETRLIMIT */
|
#endif /* HAVE_GETRLIMIT */
|
||||||
break;
|
break;
|
||||||
case 'j': /* jobs */
|
case 'j': /* jobs */
|
||||||
|
benchmarking_option_set = true;
|
||||||
nthreads = atoi(optarg);
|
nthreads = atoi(optarg);
|
||||||
if (nthreads <= 0)
|
if (nthreads <= 0)
|
||||||
{
|
{
|
||||||
@ -2637,9 +2644,11 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
|
benchmarking_option_set = true;
|
||||||
is_connect = true;
|
is_connect = true;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
benchmarking_option_set = true;
|
||||||
is_latencies = true;
|
is_latencies = true;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
@ -2652,6 +2661,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
|
benchmarking_option_set = true;
|
||||||
if (duration > 0)
|
if (duration > 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "specify either a number of transactions (-t) or a duration (-T), not both.\n");
|
fprintf(stderr, "specify either a number of transactions (-t) or a duration (-T), not both.\n");
|
||||||
@ -2665,6 +2675,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
|
benchmarking_option_set = true;
|
||||||
if (nxacts > 0)
|
if (nxacts > 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "specify either a number of transactions (-t) or a duration (-T), not both.\n");
|
fprintf(stderr, "specify either a number of transactions (-t) or a duration (-T), not both.\n");
|
||||||
@ -2681,12 +2692,15 @@ main(int argc, char **argv)
|
|||||||
login = pg_strdup(optarg);
|
login = pg_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
|
benchmarking_option_set = true;
|
||||||
use_log = true;
|
use_log = true;
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
|
initialization_option_set = true;
|
||||||
use_quiet = true;
|
use_quiet = true;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
|
benchmarking_option_set = true;
|
||||||
ttype = 3;
|
ttype = 3;
|
||||||
filename = pg_strdup(optarg);
|
filename = pg_strdup(optarg);
|
||||||
if (process_file(filename) == false || *sql_files[num_files - 1] == NULL)
|
if (process_file(filename) == false || *sql_files[num_files - 1] == NULL)
|
||||||
@ -2696,6 +2710,8 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
benchmarking_option_set = true;
|
||||||
|
|
||||||
if ((p = strchr(optarg, '=')) == NULL || p == optarg || *(p + 1) == '\0')
|
if ((p = strchr(optarg, '=')) == NULL || p == optarg || *(p + 1) == '\0')
|
||||||
{
|
{
|
||||||
fprintf(stderr, "invalid variable definition: %s\n", optarg);
|
fprintf(stderr, "invalid variable definition: %s\n", optarg);
|
||||||
@ -2708,6 +2724,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
|
initialization_option_set = true;
|
||||||
fillfactor = atoi(optarg);
|
fillfactor = atoi(optarg);
|
||||||
if ((fillfactor < 10) || (fillfactor > 100))
|
if ((fillfactor < 10) || (fillfactor > 100))
|
||||||
{
|
{
|
||||||
@ -2716,6 +2733,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
|
benchmarking_option_set = true;
|
||||||
if (num_files > 0)
|
if (num_files > 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "query mode (-M) should be specifiled before transaction scripts (-f)\n");
|
fprintf(stderr, "query mode (-M) should be specifiled before transaction scripts (-f)\n");
|
||||||
@ -2731,6 +2749,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
|
benchmarking_option_set = true;
|
||||||
progress = atoi(optarg);
|
progress = atoi(optarg);
|
||||||
if (progress <= 0)
|
if (progress <= 0)
|
||||||
{
|
{
|
||||||
@ -2745,6 +2764,8 @@ main(int argc, char **argv)
|
|||||||
/* get a double from the beginning of option value */
|
/* get a double from the beginning of option value */
|
||||||
double throttle_value = atof(optarg);
|
double throttle_value = atof(optarg);
|
||||||
|
|
||||||
|
benchmarking_option_set = true;
|
||||||
|
|
||||||
if (throttle_value <= 0.0)
|
if (throttle_value <= 0.0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "invalid rate limit: %s\n", optarg);
|
fprintf(stderr, "invalid rate limit: %s\n", optarg);
|
||||||
@ -2756,14 +2777,19 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
/* This covers long options which take no argument. */
|
/* This covers long options which take no argument. */
|
||||||
|
if (foreign_keys || unlogged_tables)
|
||||||
|
initialization_option_set = true;
|
||||||
break;
|
break;
|
||||||
case 2: /* tablespace */
|
case 2: /* tablespace */
|
||||||
|
initialization_option_set = true;
|
||||||
tablespace = pg_strdup(optarg);
|
tablespace = pg_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 3: /* index-tablespace */
|
case 3: /* index-tablespace */
|
||||||
|
initialization_option_set = true;
|
||||||
index_tablespace = pg_strdup(optarg);
|
index_tablespace = pg_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
benchmarking_option_set = true;
|
||||||
sample_rate = atof(optarg);
|
sample_rate = atof(optarg);
|
||||||
if (sample_rate <= 0.0 || sample_rate > 1.0)
|
if (sample_rate <= 0.0 || sample_rate > 1.0)
|
||||||
{
|
{
|
||||||
@ -2776,6 +2802,7 @@ main(int argc, char **argv)
|
|||||||
fprintf(stderr, "--aggregate-interval is not currently supported on Windows");
|
fprintf(stderr, "--aggregate-interval is not currently supported on Windows");
|
||||||
exit(1);
|
exit(1);
|
||||||
#else
|
#else
|
||||||
|
benchmarking_option_set = true;
|
||||||
agg_interval = atoi(optarg);
|
agg_interval = atoi(optarg);
|
||||||
if (agg_interval <= 0)
|
if (agg_interval <= 0)
|
||||||
{
|
{
|
||||||
@ -2808,9 +2835,23 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (is_init_mode)
|
if (is_init_mode)
|
||||||
{
|
{
|
||||||
|
if (benchmarking_option_set)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "some options cannot be used in initialization (-i) mode\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
init(is_no_vacuum);
|
init(is_no_vacuum);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (initialization_option_set)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "some options cannot be used in benchmarking mode\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Use DEFAULT_NXACTS if neither nxacts nor duration is specified. */
|
/* Use DEFAULT_NXACTS if neither nxacts nor duration is specified. */
|
||||||
if (nxacts <= 0 && duration <= 0)
|
if (nxacts <= 0 && duration <= 0)
|
||||||
@ -2829,13 +2870,6 @@ main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -q may be used only with -i */
|
|
||||||
if (use_quiet && !is_init_mode)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "quiet-logging is allowed only in initialization mode (-i)\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --sampling-rate may must not be used with --aggregate-interval */
|
/* --sampling-rate may must not be used with --aggregate-interval */
|
||||||
if (sample_rate > 0.0 && agg_interval > 0)
|
if (sample_rate > 0.0 && agg_interval > 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user