81
81
#include <stdarg.h>
82
82
#include <sys/types.h>
83
83
#include <sys/wait.h>
84
#ifdef HAVE_SYS_STAT_H
85
# include <sys/stat.h>
96
87
/* Added this for string translation. */
97
88
#include <drizzled/gettext.h>
99
90
using namespace std;
100
using namespace drizzled;
103
93
static char *shared_memory_base_name=0;
97
bool get_one_option(int optid, const struct my_option *, char *argument);
106
99
/* Global Thread counter */
107
100
uint32_t thread_counter;
108
101
pthread_mutex_t counter_mutex;
128
121
*user_supplied_post_statements= NULL,
129
122
*default_engine= NULL,
130
123
*pre_system= NULL,
125
*opt_drizzle_unix_port= NULL;
133
127
const char *delimiter= "\n";
135
129
const char *create_schema_string= "drizzleslap";
137
static bool opt_mysql= false;
138
131
static bool opt_preserve= true;
132
static bool debug_info_flag= false, debug_check_flag= false;
139
133
static bool opt_only_print= false;
140
134
static bool opt_burnin= false;
141
135
static bool opt_ignore_sql_errors= false;
142
static bool tty_password= false,
136
static bool opt_compress= false, tty_password= false,
143
137
opt_silent= false,
144
138
auto_generate_sql_autoincrement= false,
145
139
auto_generate_sql_guid_primary= false,
168
162
static unsigned int num_int_cols_index= 0;
169
163
static unsigned int num_char_cols_index= 0;
170
164
static unsigned int iterations;
165
static uint32_t my_end_arg= 0;
171
166
static uint64_t actual_queries= 0;
172
167
static uint64_t auto_actual_queries;
173
168
static uint64_t auto_generate_sql_unique_write_number;
323
318
option_string *eptr;
328
323
MY_INIT(argv[0]);
330
internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
325
load_defaults("drizzle",load_default_groups,&argc,&argv);
331
326
defaults_argv=argv;
332
327
if (get_options(&argc,&argv))
334
internal::free_defaults(defaults_argv);
329
free_defaults(defaults_argv);
352
fprintf(stderr,"%s: Too many arguments\n",internal::my_progname);
353
internal::free_defaults(defaults_argv);
347
fprintf(stderr,"%s: Too many arguments\n",my_progname);
348
free_defaults(defaults_argv);
531
static struct option my_long_options[] =
526
static struct my_option my_long_options[] =
533
528
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
534
529
0, 0, 0, 0, 0, 0},
593
588
{"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
594
589
(char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
595
590
0, 0, 0, 0, 0, 0},
591
{"compress", 'C', "Use compression in server/client protocol.",
592
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
596
594
{"concurrency", 'c', "Number of clients to simulate for query to run.",
597
595
(char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
598
596
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
606
604
"Generate CSV output to named file or to stdout if no file is named.",
607
605
(char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
608
606
OPT_ARG, 0, 0, 0, 0, 0, 0},
607
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
608
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
609
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
610
{"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
611
(char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
609
612
{"delayed-start", OPT_SLAP_DELAYED_START,
610
613
"Delay the startup of threads by a random number of microsends (the maximum of the delay)",
611
614
(char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
628
631
{"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
629
632
(char**) &opt_label, (char**) &opt_label, 0,
630
633
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
631
{"mysql", 'm', N_("Use MySQL Protocol."),
632
(char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
634
634
{"number-blob-cols", OPT_SLAP_BLOB_COL,
635
635
"Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ",
636
636
(char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
691
691
{"silent", 's', "Run program in silent mode - no output.",
692
692
(char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL, NO_ARG,
693
693
0, 0, 0, 0, 0, 0},
694
{"socket", 'S', "Socket file to use for connection.",
695
(char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
696
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
694
697
{"timer-length", OPT_SLAP_TIMER_LENGTH,
695
698
"Require drizzleslap to run each specific test a certain amount of time in seconds.",
696
699
(char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
710
713
static void print_version(void)
712
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
715
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",my_progname, SLAP_VERSION,
713
716
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
722
725
\nand you are welcome to modify and redistribute it under the GPL \
724
727
puts("Run a query multiple times against the server\n");
725
printf("Usage: %s [OPTIONS]\n",internal::my_progname);
726
internal::print_defaults("drizzle",load_default_groups);
728
printf("Usage: %s [OPTIONS]\n",my_progname);
729
print_defaults("drizzle",load_default_groups);
727
730
my_print_help(my_long_options);
730
static int get_one_option(int optid, const struct option *, char *argument)
733
bool get_one_option(int optid, const struct my_option *, char *argument)
732
735
char *endchar= NULL;
733
736
uint64_t temp_drizzle_port= 0;
742
745
if (strlen(endchar) != 0)
744
747
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
745
return EXIT_ARGUMENT_INVALID;
747
750
/* If the port number is > 65535 it is not a valid port
748
751
This also helps with potential data loss casting unsigned long to a
1285
1288
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1286
1289
exit(ho_error);
1290
if (debug_info_flag)
1291
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
1292
if (debug_check_flag)
1293
my_end_arg= MY_CHECK_ERROR;
1289
1296
user= (char *)"root";
1333
1340
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1335
1342
fprintf(stderr,"%s: Could not open csv file: %sn\n",
1336
internal::my_progname, opt_csv_str);
1343
my_progname, opt_csv_str);
1535
1542
if (create_string && !stat(create_string, &sbuf))
1538
1545
if (!S_ISREG(sbuf.st_mode))
1540
1547
fprintf(stderr,"%s: Create file was not a regular file\n",
1541
internal::my_progname);
1544
1551
if ((data_file= open(create_string, O_RDWR)) == -1)
1546
fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
1553
fprintf(stderr,"%s: Could not open create file\n", my_progname);
1549
1556
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1592
1599
if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1595
1602
if (!S_ISREG(sbuf.st_mode))
1597
1604
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1598
internal::my_progname);
1601
1608
if ((data_file= open(user_supplied_query, O_RDWR)) == -1)
1603
fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1610
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1606
1613
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1638
1645
if (user_supplied_pre_statements
1639
1646
&& !stat(user_supplied_pre_statements, &sbuf))
1642
1649
if (!S_ISREG(sbuf.st_mode))
1644
1651
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1645
internal::my_progname);
1648
1655
if ((data_file= open(user_supplied_pre_statements, O_RDWR)) == -1)
1650
fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1657
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1653
1660
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1685
1692
if (user_supplied_post_statements
1686
1693
&& !stat(user_supplied_post_statements, &sbuf))
1689
1696
if (!S_ISREG(sbuf.st_mode))
1691
1698
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1692
internal::my_progname);
1695
1702
if ((data_file= open(user_supplied_post_statements, O_RDWR)) == -1)
1697
fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1704
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1810
1817
if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1812
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
1819
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1813
1820
drizzle_con_error(con));
1893
1900
if (run_query(con, NULL, query, len))
1895
fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
1902
fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1896
1903
drizzle_con_error(con));
1916
1923
if (drizzle_select_db(con, &result, db, &ret) == NULL ||
1917
1924
ret != DRIZZLE_RETURN_OK)
1919
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
1926
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1920
1927
ret == DRIZZLE_RETURN_ERROR_CODE ?
1921
1928
drizzle_result_error(&result) : drizzle_con_error(con));
1931
1938
engine_stmt->string);
1932
1939
if (run_query(con, NULL, query, len))
1934
fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
1941
fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1935
1942
drizzle_con_error(con));
1956
1963
if (run_query(con, NULL, buffer, strlen(buffer)))
1958
1965
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1959
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1966
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1960
1967
if (!opt_ignore_sql_errors)
1967
1974
if (run_query(con, NULL, ptr->string, ptr->length))
1969
1976
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1970
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1977
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1971
1978
if (!opt_ignore_sql_errors)
2000
2007
if (run_query(con, NULL, query, len))
2002
2009
fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
2003
internal::my_progname, db, drizzle_con_error(con));
2010
my_progname, db, drizzle_con_error(con));
2019
2026
if (run_query(con, NULL, ptr->string, ptr->length))
2021
2028
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2022
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
2029
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
2083
2090
if (pthread_create(&mainthread, &attr, run_task,
2084
2091
(void *)con) != 0)
2086
fprintf(stderr,"%s: Could not create thread\n", internal::my_progname);
2093
fprintf(stderr,"%s: Could not create thread\n", my_progname);
2089
2096
thread_counter++;
2103
2110
if (pthread_create(&mainthread, &attr, timer_thread,
2104
2111
(void *)&opt_timer_length) != 0)
2106
fprintf(stderr,"%s: Could not create timer thread\n", internal::my_progname);
2113
fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
2244
2251
if (run_query(&con, &result, buffer, length))
2246
2253
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2247
internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
2254
my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
2254
2261
if (run_query(&con, &result, ptr->string, ptr->length))
2256
2263
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2257
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
2264
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
2575
2582
con->real_users, /* Children used max_timing */
2576
2583
con->avg_rows /* Queries run */
2578
internal::my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2585
my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2696
2703
drizzle_con_add_tcp(drizzle, con, host, opt_drizzle_port, user,
2698
2705
connect_to_schema ? create_schema_string : NULL,
2699
opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
2706
DRIZZLE_CON_NONE) == NULL)
2701
fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
2708
fprintf(stderr,"%s: Error creating drizzle object\n", my_progname);
2715
2722
if (connect_error)
2717
fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
2724
fprintf(stderr,"%s: Error when connecting to server: %d %s\n", my_progname,
2718
2725
ret, drizzle_con_error(con));