269
269
uint parse_comma(const char *string, uint **range);
270
270
uint parse_delimiter(const char *script, statement **stmt, char delm);
271
271
uint parse_option(const char *origin, option_string **stmt, char delm);
272
static int drop_schema(MYSQL *mysql, const char *db);
272
static int drop_schema(DRIZZLE *drizzle, const char *db);
273
273
uint get_random_string(char *buf, size_t size);
274
274
static statement *build_table_string(void);
275
275
static statement *build_insert_string(void);
276
276
static statement *build_update_string(void);
277
277
static statement * build_select_string(bool key);
278
static int generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt);
278
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
279
279
static int drop_primary_key_list(void);
280
static int create_schema(MYSQL *mysql, const char *db, statement *stmt,
280
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
281
281
option_string *engine_stmt, stats *sptr);
282
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
282
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
284
284
pthread_handler_t run_task(void *p);
285
285
pthread_handler_t timer_thread(void *p);
286
286
void statement_cleanup(statement *stmt);
287
287
void option_cleanup(option_string *stmt);
288
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr);
289
static int run_statements(MYSQL *mysql, statement *stmt);
290
void slap_connect(MYSQL *mysql, bool connect_to_schema);
291
void slap_close(MYSQL *mysql);
292
static int run_query(MYSQL *mysql, const char *query, int len);
288
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr);
289
static int run_statements(DRIZZLE *drizzle, statement *stmt);
290
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
291
void slap_close(DRIZZLE *drizzle);
292
static int run_query(DRIZZLE *drizzle, const char *query, int len);
293
293
void standard_deviation (conclusions *con, stats *sptr);
295
295
static const char ALPHANUMERICS[]=
535
535
0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
536
536
{"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
537
537
"Add GUID based primary keys to auto-generated tables.",
538
(char**) &auto_generate_sql_guid_primary,
538
(char**) &auto_generate_sql_guid_primary,
539
539
(char**) &auto_generate_sql_guid_primary,
540
540
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
541
541
{"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
542
542
"Specify test load type: mixed, update, write, key, or read; default is mixed.",
543
543
(char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
544
544
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
545
{"auto-generate-sql-secondary-indexes",
546
OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
545
{"auto-generate-sql-secondary-indexes",
546
OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
547
547
"Number of secondary indexes to add to auto-generated tables.",
548
(char**) &auto_generate_sql_secondary_indexes,
548
(char**) &auto_generate_sql_secondary_indexes,
549
549
(char**) &auto_generate_sql_secondary_indexes, 0,
550
550
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
551
{"auto-generate-sql-unique-query-number",
551
{"auto-generate-sql-unique-query-number",
552
552
OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
553
553
"Number of unique queries to generate for automatic tests.",
554
(char**) &auto_generate_sql_unique_query_number,
554
(char**) &auto_generate_sql_unique_query_number,
555
555
(char**) &auto_generate_sql_unique_query_number,
556
556
0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
557
{"auto-generate-sql-unique-write-number",
557
{"auto-generate-sql-unique-write-number",
558
558
OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
559
559
"Number of unique queries to generate for auto-generate-sql-write-number.",
560
(char**) &auto_generate_sql_unique_write_number,
560
(char**) &auto_generate_sql_unique_write_number,
561
561
(char**) &auto_generate_sql_unique_write_number,
562
562
0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
563
563
{"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
586
586
(char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
587
587
0, 0, 0, 0, 0, 0},
588
588
{"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
589
(char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
589
(char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
590
590
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
591
591
{"csv", OPT_SLAP_CSV,
592
"Generate CSV output to named file or to stdout if no file is named.",
593
(char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
592
"Generate CSV output to named file or to stdout if no file is named.",
593
(char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
594
594
OPT_ARG, 0, 0, 0, 0, 0, 0},
595
595
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
596
596
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
597
597
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
598
598
{"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
599
599
(char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
600
{"delayed-start", OPT_SLAP_DELAYED_START,
600
{"delayed-start", OPT_SLAP_DELAYED_START,
601
601
"Delay the startup of threads by a random number of microsends (the maximum of the delay)",
602
(char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
602
(char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
603
603
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
604
604
{"delimiter", 'F',
605
605
"Delimiter to use in SQL statements supplied in file or command line.",
619
619
{"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
620
620
(char**) &opt_label, (char**) &opt_label, 0,
621
621
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
622
{"number-blob-cols", OPT_SLAP_BLOB_COL,
622
{"number-blob-cols", OPT_SLAP_BLOB_COL,
623
623
"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. ",
624
624
(char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
625
625
0, 0, 0, 0, 0, 0},
626
{"number-char-cols", 'x',
626
{"number-char-cols", 'x',
627
627
"Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
628
628
(char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
629
629
0, 0, 0, 0, 0, 0},
630
{"number-int-cols", 'y',
630
{"number-int-cols", 'y',
631
631
"Number of INT columns to create in table if specifying --auto-generate-sql.",
632
(char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
632
(char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
633
633
0, 0, 0, 0, 0, 0},
634
{"number-of-queries", OPT_MYSQL_NUMBER_OF_QUERY,
634
{"number-of-queries", OPT_DRIZZLE_NUMBER_OF_QUERY,
635
635
"Limit each client to this number of queries (this is not exact).",
636
636
(char**) &num_of_query, (char**) &num_of_query, 0,
637
637
GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
638
{"only-print", OPT_MYSQL_ONLY_PRINT,
639
"This causes mysqlslap to not connect to the databases, but instead print "
638
{"only-print", OPT_DRIZZLE_ONLY_PRINT,
639
"This causes drizzleslap to not connect to the databases, but instead print "
640
640
"out what it would have done instead.",
641
641
(char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL, NO_ARG,
642
642
0, 0, 0, 0, 0, 0},
643
643
{"password", 'p',
644
644
"Password to use when connecting to server. If password is not given it's "
645
645
"asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
646
{"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
647
(char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
646
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
647
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
649
649
{"post-query", OPT_SLAP_POST_QUERY,
650
650
"Query to run or file containing query to execute after tests have completed.",
651
(char**) &user_supplied_post_statements,
651
(char**) &user_supplied_post_statements,
652
652
(char**) &user_supplied_post_statements,
653
653
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
654
654
{"post-system", OPT_SLAP_POST_SYSTEM,
655
655
"system() string to execute after tests have completed.",
656
(char**) &post_system,
656
(char**) &post_system,
657
657
(char**) &post_system,
658
658
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
659
{"pre-query", OPT_SLAP_PRE_QUERY,
659
{"pre-query", OPT_SLAP_PRE_QUERY,
660
660
"Query to run or file containing query to execute before running tests.",
661
(char**) &user_supplied_pre_statements,
661
(char**) &user_supplied_pre_statements,
662
662
(char**) &user_supplied_pre_statements,
663
663
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
664
{"pre-system", OPT_SLAP_PRE_SYSTEM,
664
{"pre-system", OPT_SLAP_PRE_SYSTEM,
665
665
"system() string to execute before running tests.",
666
(char**) &pre_system,
666
(char**) &pre_system,
667
667
(char**) &pre_system,
668
668
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
669
{"protocol", OPT_MYSQL_PROTOCOL,
669
{"protocol", OPT_DRIZZLE_PROTOCOL,
670
670
"The protocol of connection (tcp,socket,pipe,memory).",
671
671
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
672
672
{"query", 'q', "Query to run or file containing query to run.",
673
673
(char**) &user_supplied_query, (char**) &user_supplied_query,
674
674
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
675
{"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
675
{"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
676
676
"Seed for random number generator (srandom(3))",
677
677
(char**)&opt_set_random_seed,
678
678
(char**)&opt_set_random_seed,0,
681
681
(char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL, NO_ARG,
682
682
0, 0, 0, 0, 0, 0},
683
683
{"socket", 'S', "Socket file to use for connection.",
684
(char**) &opt_mysql_unix_port, (char**) &opt_mysql_unix_port, 0, GET_STR,
684
(char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
685
685
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
686
{"timer-length", OPT_SLAP_TIMER_LENGTH,
687
"Require mysqlslap to run each specific test a certain amount of time in seconds.",
688
(char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
686
{"timer-length", OPT_SLAP_TIMER_LENGTH,
687
"Require drizzleslap to run each specific test a certain amount of time in seconds.",
688
(char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
689
689
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
690
690
#ifndef DONT_ALLOW_USER_CHANGE
691
691
{"user", 'u', "User for login if not current user.", (char**) &user,
1620
1620
if (verbose >= 3)
1621
1621
printf("%.*s;\n", len, query);
1622
return mysql_real_query(mysql, query, len);
1622
return drizzle_real_query(drizzle, query, len);
1627
generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
1627
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
1629
DRIZZLE_RES *result;
1631
1631
unsigned long long counter;
1635
Blackhole is a special case, this allows us to test the upper end
1635
Blackhole is a special case, this allows us to test the upper end
1636
1636
of the server during load runs.
1638
if (opt_only_print || (engine_stmt &&
1638
if (opt_only_print || (engine_stmt &&
1639
1639
strstr(engine_stmt->string, "blackhole")))
1641
1641
primary_keys_number_of= 1;
1642
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1643
primary_keys_number_of),
1642
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1643
primary_keys_number_of),
1644
1644
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1645
1645
/* Yes, we strdup a const string to simplify the interface */
1646
primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
1646
primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
1650
if (run_query(mysql, "SELECT id from t1", strlen("SELECT id from t1")))
1650
if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
1652
1652
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1653
mysql_error(mysql));
1653
drizzle_error(drizzle));
1657
result= mysql_store_result(mysql);
1658
primary_keys_number_of= mysql_num_rows(result);
1657
result= drizzle_store_result(drizzle);
1658
primary_keys_number_of= drizzle_num_rows(result);
1660
1660
/* So why check this? Blackhole :) */
1661
1661
if (primary_keys_number_of)
2466
2466
nptr= ptr->next;
2467
2467
if (ptr->string)
2468
my_free(ptr->string, MYF(0));
2468
my_free(ptr->string, MYF(0));
2469
2469
my_free(ptr, MYF(0));
2474
slap_close(MYSQL *mysql)
2474
slap_close(DRIZZLE *drizzle)
2479
drizzle_close(drizzle);
2483
slap_connect(MYSQL *mysql, bool connect_to_schema)
2483
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
2485
2485
/* Connect to server */
2486
2486
static ulong connection_retry_sleep= 100000; /* Microseconds */
2487
2487
int x, connect_error= 1;
2492
2492
if (opt_delayed_start)
2493
2493
my_sleep(random()%opt_delayed_start);
2495
drizzle_create(drizzle);
2497
2497
if (opt_compress)
2498
mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS);
2498
drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NullS);
2499
2499
/* We always do opt_protocol to TCP/IP */
2500
mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
2501
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset);
2500
drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
2501
drizzle_options(drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
2503
2503
for (x= 0; x < 10; x++)
2507
if (mysql_real_connect(mysql, host, user, opt_password,
2507
if (drizzle_connect(drizzle, host, user, opt_password,
2508
2508
connect_to_schema ? create_schema_string : NULL,
2510
opt_mysql_unix_port,
2510
opt_drizzle_unix_port,
2511
2511
connect_flags))
2513
2513
/* Connect suceeded */