Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 51222a1

Browse files
committed
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.
1 parent 3e3f659 commit 51222a1

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

contrib/pgbench/pgbench.c

+41-7
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,9 @@ main(int argc, char **argv)
25202520
char *filename = NULL;
25212521
bool scale_given = false;
25222522

2523+
bool benchmarking_option_set = false;
2524+
bool initialization_option_set = false;
2525+
25232526
CState *state; /* status of clients */
25242527
TState *threads; /* array of thread */
25252528

@@ -2599,11 +2602,14 @@ main(int argc, char **argv)
25992602
break;
26002603
case 'S':
26012604
ttype = 1;
2605+
benchmarking_option_set = true;
26022606
break;
26032607
case 'N':
26042608
ttype = 2;
2609+
benchmarking_option_set = true;
26052610
break;
26062611
case 'c':
2612+
benchmarking_option_set = true;
26072613
nclients = atoi(optarg);
26082614
if (nclients <= 0 || nclients > MAXCLIENTS)
26092615
{
@@ -2629,6 +2635,7 @@ main(int argc, char **argv)
26292635
#endif /* HAVE_GETRLIMIT */
26302636
break;
26312637
case 'j': /* jobs */
2638+
benchmarking_option_set = true;
26322639
nthreads = atoi(optarg);
26332640
if (nthreads <= 0)
26342641
{
@@ -2637,9 +2644,11 @@ main(int argc, char **argv)
26372644
}
26382645
break;
26392646
case 'C':
2647+
benchmarking_option_set = true;
26402648
is_connect = true;
26412649
break;
26422650
case 'r':
2651+
benchmarking_option_set = true;
26432652
is_latencies = true;
26442653
break;
26452654
case 's':
@@ -2652,6 +2661,7 @@ main(int argc, char **argv)
26522661
}
26532662
break;
26542663
case 't':
2664+
benchmarking_option_set = true;
26552665
if (duration > 0)
26562666
{
26572667
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)
26652675
}
26662676
break;
26672677
case 'T':
2678+
benchmarking_option_set = true;
26682679
if (nxacts > 0)
26692680
{
26702681
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)
26812692
login = pg_strdup(optarg);
26822693
break;
26832694
case 'l':
2695+
benchmarking_option_set = true;
26842696
use_log = true;
26852697
break;
26862698
case 'q':
2699+
initialization_option_set = true;
26872700
use_quiet = true;
26882701
break;
26892702
case 'f':
2703+
benchmarking_option_set = true;
26902704
ttype = 3;
26912705
filename = pg_strdup(optarg);
26922706
if (process_file(filename) == false || *sql_files[num_files - 1] == NULL)
@@ -2696,6 +2710,8 @@ main(int argc, char **argv)
26962710
{
26972711
char *p;
26982712

2713+
benchmarking_option_set = true;
2714+
26992715
if ((p = strchr(optarg, '=')) == NULL || p == optarg || *(p + 1) == '\0')
27002716
{
27012717
fprintf(stderr, "invalid variable definition: %s\n", optarg);
@@ -2708,6 +2724,7 @@ main(int argc, char **argv)
27082724
}
27092725
break;
27102726
case 'F':
2727+
initialization_option_set = true;
27112728
fillfactor = atoi(optarg);
27122729
if ((fillfactor < 10) || (fillfactor > 100))
27132730
{
@@ -2716,6 +2733,7 @@ main(int argc, char **argv)
27162733
}
27172734
break;
27182735
case 'M':
2736+
benchmarking_option_set = true;
27192737
if (num_files > 0)
27202738
{
27212739
fprintf(stderr, "query mode (-M) should be specifiled before transaction scripts (-f)\n");
@@ -2731,6 +2749,7 @@ main(int argc, char **argv)
27312749
}
27322750
break;
27332751
case 'P':
2752+
benchmarking_option_set = true;
27342753
progress = atoi(optarg);
27352754
if (progress <= 0)
27362755
{
@@ -2745,6 +2764,8 @@ main(int argc, char **argv)
27452764
/* get a double from the beginning of option value */
27462765
double throttle_value = atof(optarg);
27472766

2767+
benchmarking_option_set = true;
2768+
27482769
if (throttle_value <= 0.0)
27492770
{
27502771
fprintf(stderr, "invalid rate limit: %s\n", optarg);
@@ -2756,14 +2777,19 @@ main(int argc, char **argv)
27562777
break;
27572778
case 0:
27582779
/* This covers long options which take no argument. */
2780+
if (foreign_keys || unlogged_tables)
2781+
initialization_option_set = true;
27592782
break;
27602783
case 2: /* tablespace */
2784+
initialization_option_set = true;
27612785
tablespace = pg_strdup(optarg);
27622786
break;
27632787
case 3: /* index-tablespace */
2788+
initialization_option_set = true;
27642789
index_tablespace = pg_strdup(optarg);
27652790
break;
27662791
case 4:
2792+
benchmarking_option_set = true;
27672793
sample_rate = atof(optarg);
27682794
if (sample_rate <= 0.0 || sample_rate > 1.0)
27692795
{
@@ -2776,6 +2802,7 @@ main(int argc, char **argv)
27762802
fprintf(stderr, "--aggregate-interval is not currently supported on Windows");
27772803
exit(1);
27782804
#else
2805+
benchmarking_option_set = true;
27792806
agg_interval = atoi(optarg);
27802807
if (agg_interval <= 0)
27812808
{
@@ -2808,9 +2835,23 @@ main(int argc, char **argv)
28082835

28092836
if (is_init_mode)
28102837
{
2838+
if (benchmarking_option_set)
2839+
{
2840+
fprintf(stderr, "some options cannot be used in initialization (-i) mode\n");
2841+
exit(1);
2842+
}
2843+
28112844
init(is_no_vacuum);
28122845
exit(0);
28132846
}
2847+
else
2848+
{
2849+
if (initialization_option_set)
2850+
{
2851+
fprintf(stderr, "some options cannot be used in benchmarking mode\n");
2852+
exit(1);
2853+
}
2854+
}
28142855

28152856
/* Use DEFAULT_NXACTS if neither nxacts nor duration is specified. */
28162857
if (nxacts <= 0 && duration <= 0)
@@ -2829,13 +2870,6 @@ main(int argc, char **argv)
28292870
exit(1);
28302871
}
28312872

2832-
/* -q may be used only with -i */
2833-
if (use_quiet && !is_init_mode)
2834-
{
2835-
fprintf(stderr, "quiet-logging is allowed only in initialization mode (-i)\n");
2836-
exit(1);
2837-
}
2838-
28392873
/* --sampling-rate may must not be used with --aggregate-interval */
28402874
if (sample_rate > 0.0 && agg_interval > 0)
28412875
{

0 commit comments

Comments
 (0)