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>
92
#if defined(CMATH_NAMESPACE)
93
using namespace CMATH_NAMESPACE;
99
96
using namespace std;
100
using namespace drizzled;
103
99
static char *shared_memory_base_name=0;
103
bool get_one_option(int optid, const struct my_option *, char *argument);
106
105
/* Global Thread counter */
107
106
uint32_t thread_counter;
108
107
pthread_mutex_t counter_mutex;
128
127
*user_supplied_post_statements= NULL,
129
128
*default_engine= NULL,
130
129
*pre_system= NULL,
131
*opt_drizzle_unix_port= NULL;
133
133
const char *delimiter= "\n";
135
135
const char *create_schema_string= "drizzleslap";
137
static bool opt_mysql= false;
138
137
static bool opt_preserve= true;
138
static bool debug_info_flag= false, debug_check_flag= false;
139
139
static bool opt_only_print= false;
140
140
static bool opt_burnin= false;
141
141
static bool opt_ignore_sql_errors= false;
142
static bool tty_password= false,
142
static bool opt_compress= false, tty_password= false,
143
143
opt_silent= false,
144
144
auto_generate_sql_autoincrement= false,
145
145
auto_generate_sql_guid_primary= false,
146
146
auto_generate_sql= false;
147
147
const char *opt_auto_generate_sql_type= "mixed";
149
static unsigned long connect_flags= CLIENT_MULTI_RESULTS |
150
CLIENT_MULTI_STATEMENTS;
149
152
static int verbose, delimiter_length;
150
153
static uint32_t commit_rate;
151
154
static uint32_t detach_rate;
168
171
static unsigned int num_int_cols_index= 0;
169
172
static unsigned int num_char_cols_index= 0;
170
173
static unsigned int iterations;
174
static uint32_t my_end_arg= 0;
171
175
static uint64_t actual_queries= 0;
172
176
static uint64_t auto_actual_queries;
173
177
static uint64_t auto_generate_sql_unique_write_number;
277
281
uint32_t parse_comma(const char *string, uint32_t **range);
278
282
uint32_t parse_delimiter(const char *script, statement **stmt, char delm);
279
283
uint32_t parse_option(const char *origin, option_string **stmt, char delm);
280
static int drop_schema(drizzle_con_st *con, const char *db);
284
static int drop_schema(DRIZZLE *drizzle, const char *db);
281
285
uint32_t get_random_string(char *buf, size_t size);
282
286
static statement *build_table_string(void);
283
287
static statement *build_insert_string(void);
284
288
static statement *build_update_string(void);
285
289
static statement * build_select_string(bool key);
286
static int generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt);
290
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
287
291
static int drop_primary_key_list(void);
288
static int create_schema(drizzle_con_st *con, const char *db, statement *stmt,
292
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
289
293
option_string *engine_stmt, stats *sptr);
290
294
static int run_scheduler(stats *sptr, statement **stmts, uint32_t concur,
293
297
extern "C" pthread_handler_t timer_thread(void *p);
294
298
void statement_cleanup(statement *stmt);
295
299
void option_cleanup(option_string *stmt);
296
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr);
297
static int run_statements(drizzle_con_st *con, statement *stmt);
298
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
299
void slap_close(drizzle_con_st *con);
300
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
300
void concurrency_loop(DRIZZLE *drizzle, uint32_t current, option_string *eptr);
301
static int run_statements(DRIZZLE *drizzle, statement *stmt);
302
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
303
void slap_close(DRIZZLE *drizzle);
304
static int run_query(DRIZZLE *drizzle, const char *query, int len);
301
305
void standard_deviation (conclusions *con, stats *sptr);
303
307
static const char ALPHANUMERICS[]=
320
324
int main(int argc, char **argv)
323
327
option_string *eptr;
328
332
MY_INIT(argv[0]);
330
internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
334
load_defaults("drizzle",load_default_groups,&argc,&argv);
331
335
defaults_argv=argv;
332
336
if (get_options(&argc,&argv))
334
internal::free_defaults(defaults_argv);
338
free_defaults(defaults_argv);
352
fprintf(stderr,"%s: Too many arguments\n",internal::my_progname);
353
internal::free_defaults(defaults_argv);
356
fprintf(stderr,"%s: Too many arguments\n",my_progname);
357
free_defaults(defaults_argv);
358
slap_connect(&con, false);
362
slap_connect(&drizzle, false);
360
364
pthread_mutex_init(&counter_mutex, NULL);
361
365
pthread_cond_init(&count_threshhold, NULL);
379
383
if (*concurrency)
381
385
for (current= concurrency; current && *current; current++)
382
concurrency_loop(&con, *current, eptr);
386
concurrency_loop(&drizzle, *current, eptr);
386
390
uint32_t infinite= 1;
388
concurrency_loop(&con, infinite, eptr);
392
concurrency_loop(&drizzle, infinite, eptr);
390
394
while (infinite++);
393
397
if (!opt_preserve)
394
drop_schema(&con, create_schema_string);
398
drop_schema(&drizzle, create_schema_string);
396
400
} while (eptr ? (eptr= eptr->next) : 0);
426
430
if (shared_memory_base_name)
427
431
free(shared_memory_base_name);
429
internal::free_defaults(defaults_argv);
433
free_defaults(defaults_argv);
435
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr)
439
void concurrency_loop(DRIZZLE *drizzle, uint32_t current, option_string *eptr)
438
442
stats *head_sptr;
465
469
data in the table.
467
471
if (opt_preserve == false)
468
drop_schema(con, create_schema_string);
472
drop_schema(drizzle, create_schema_string);
470
474
/* First we create */
471
475
if (create_statements)
472
create_schema(con, create_schema_string, create_statements, eptr, sptr);
476
create_schema(drizzle, create_schema_string, create_statements, eptr, sptr);
475
479
If we generated GUID we need to build a list of them from creation that
478
482
if (verbose >= 2)
479
483
printf("Generating primary key list\n");
480
484
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
481
generate_primary_key_list(con, eptr);
485
generate_primary_key_list(drizzle, eptr);
484
run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
488
run_query(drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
488
int ret= system(pre_system);
491
assert(system(pre_system)!=-1);
494
494
Pre statements are always run after all other logic so they can
495
495
correct/adjust any item that they want.
497
497
if (pre_statements)
498
run_statements(con, pre_statements);
498
run_statements(drizzle, pre_statements);
500
500
run_scheduler(sptr, query_statements, current, client_limit);
502
502
if (post_statements)
503
run_statements(con, post_statements);
503
run_statements(drizzle, post_statements);
507
int ret= system(post_system);
506
assert(system(post_system)!=-1);
511
508
/* We are finished with this run */
512
509
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
531
static struct option my_long_options[] =
528
static struct my_option my_long_options[] =
533
530
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
534
531
0, 0, 0, 0, 0, 0},
593
590
{"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
594
591
(char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
595
592
0, 0, 0, 0, 0, 0},
593
{"compress", 'C', "Use compression in server/client protocol.",
594
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
596
596
{"concurrency", 'c', "Number of clients to simulate for query to run.",
597
597
(char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
598
598
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
606
606
"Generate CSV output to named file or to stdout if no file is named.",
607
607
(char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
608
608
OPT_ARG, 0, 0, 0, 0, 0, 0},
609
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
610
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
611
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
612
{"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
613
(char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
609
614
{"delayed-start", OPT_SLAP_DELAYED_START,
610
615
"Delay the startup of threads by a random number of microsends (the maximum of the delay)",
611
616
(char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
628
633
{"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
629
634
(char**) &opt_label, (char**) &opt_label, 0,
630
635
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
636
{"number-blob-cols", OPT_SLAP_BLOB_COL,
635
637
"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
638
(char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
691
693
{"silent", 's', "Run program in silent mode - no output.",
692
694
(char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL, NO_ARG,
693
695
0, 0, 0, 0, 0, 0},
696
{"socket", 'S', "Socket file to use for connection.",
697
(char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
698
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
694
699
{"timer-length", OPT_SLAP_TIMER_LENGTH,
695
700
"Require drizzleslap to run each specific test a certain amount of time in seconds.",
696
701
(char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
697
702
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
703
#ifndef DONT_ALLOW_USER_CHANGE
698
704
{"user", 'u', "User for login if not current user.", (char**) &user,
699
705
(char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
701
708
"More verbose output; you can use this multiple times to get even more "
702
709
"verbose output.", (char**) &verbose, (char**) &verbose, 0,
710
717
static void print_version(void)
712
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
713
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
719
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname, SLAP_VERSION,
720
drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
722
729
\nand you are welcome to modify and redistribute it under the GPL \
724
731
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);
732
printf("Usage: %s [OPTIONS]\n",my_progname);
733
print_defaults("drizzle",load_default_groups);
727
734
my_print_help(my_long_options);
730
static int get_one_option(int optid, const struct option *, char *argument)
737
bool get_one_option(int optid, const struct my_option *, char *argument)
732
739
char *endchar= NULL;
733
740
uint64_t temp_drizzle_port= 0;
742
749
if (strlen(endchar) != 0)
744
751
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
754
/* If the port number is > 65535 it is not a valid port
748
755
This also helps with potential data loss casting unsigned long to a
1332
if ((csv_file= open(opt_csv_str, O_CREAT|O_WRONLY|O_APPEND,
1333
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1343
if ((csv_file= my_open(opt_csv_str, O_CREAT|O_WRONLY|O_APPEND, MYF(0)))
1335
1346
fprintf(stderr,"%s: Could not open csv file: %sn\n",
1336
internal::my_progname, opt_csv_str);
1347
my_progname, opt_csv_str);
1535
1546
if (create_string && !stat(create_string, &sbuf))
1538
1549
if (!S_ISREG(sbuf.st_mode))
1540
1551
fprintf(stderr,"%s: Create file was not a regular file\n",
1541
internal::my_progname);
1544
if ((data_file= open(create_string, O_RDWR)) == -1)
1555
if ((data_file= my_open(create_string, O_RDWR, MYF(0))) == -1)
1546
fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
1557
fprintf(stderr,"%s: Could not open create file\n", my_progname);
1549
1560
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1592
1603
if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1595
1606
if (!S_ISREG(sbuf.st_mode))
1597
1608
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1598
internal::my_progname);
1601
if ((data_file= open(user_supplied_query, O_RDWR)) == -1)
1612
if ((data_file= my_open(user_supplied_query, O_RDWR, MYF(0))) == -1)
1603
fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1614
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1606
1617
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1638
1649
if (user_supplied_pre_statements
1639
1650
&& !stat(user_supplied_pre_statements, &sbuf))
1642
1653
if (!S_ISREG(sbuf.st_mode))
1644
1655
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1645
internal::my_progname);
1648
if ((data_file= open(user_supplied_pre_statements, O_RDWR)) == -1)
1659
if ((data_file= my_open(user_supplied_pre_statements, O_RDWR, MYF(0))) == -1)
1650
fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1661
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1653
1664
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1685
1696
if (user_supplied_post_statements
1686
1697
&& !stat(user_supplied_post_statements, &sbuf))
1689
1700
if (!S_ISREG(sbuf.st_mode))
1691
1702
fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1692
internal::my_progname);
1695
if ((data_file= open(user_supplied_post_statements, O_RDWR)) == -1)
1706
if ((data_file= my_open(user_supplied_post_statements, O_RDWR, MYF(0))) == -1)
1697
fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1708
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1737
1748
parse_option(default_engine, &engine_options, ',');
1739
1750
if (tty_password)
1740
opt_password= client_get_tty_password(NULL);
1751
opt_password= drizzleclient_get_tty_password(NULL);
1745
static int run_query(drizzle_con_st *con, drizzle_result_st *result,
1746
const char *query, int len)
1756
static int run_query(DRIZZLE *drizzle, const char *query, int len)
1748
drizzle_return_t ret;
1749
drizzle_result_st result_buffer;
1751
1758
if (opt_only_print)
1753
1760
printf("%.*s;\n", len, query);
1757
1764
if (verbose >= 3)
1758
1765
printf("%.*s;\n", len, query);
1761
result= &result_buffer;
1763
result= drizzle_query(con, result, query, len, &ret);
1765
if (ret == DRIZZLE_RETURN_OK)
1766
ret= drizzle_result_buffer(result);
1768
if (result == &result_buffer)
1769
drizzle_result_free(result);
1766
return drizzleclient_real_query(drizzle, query, len);
1776
generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt)
1771
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
1778
drizzle_result_st result;
1773
DRIZZLE_RES *result;
1780
1775
uint64_t counter;
1810
if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1805
if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
1812
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
1813
drizzle_con_error(con));
1807
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1808
drizzleclient_error(drizzle));
1817
uint64_t num_rows_ret= drizzle_result_row_count(&result);
1812
result= drizzleclient_store_result(drizzle);
1813
uint64_t num_rows_ret= drizzleclient_num_rows(result);
1818
1814
if (num_rows_ret > SIZE_MAX)
1820
1816
fprintf(stderr, "More primary keys than than architecture supports\n");
1838
1834
memset(primary_keys, 0, (size_t)(sizeof(char *) * primary_keys_number_of));
1839
row= drizzle_row_next(&result);
1835
row= drizzleclient_fetch_row(result);
1840
1836
for (counter= 0; counter < primary_keys_number_of;
1841
counter++, row= drizzle_row_next(&result))
1837
counter++, row= drizzleclient_fetch_row(result))
1843
1839
primary_keys[counter]= strdup(row[0]);
1844
1840
if (primary_keys[counter] == NULL)
1875
create_schema(drizzle_con_st *con, const char *db, statement *stmt,
1871
create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
1876
1872
option_string *engine_stmt, stats *sptr)
1878
1874
char query[HUGE_STRING_LENGTH];
1890
1886
if (verbose >= 2)
1891
1887
printf("Loading Pre-data\n");
1893
if (run_query(con, NULL, query, len))
1889
if (run_query(drizzle, query, len))
1895
fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
1896
drizzle_con_error(con));
1891
fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1892
drizzleclient_error(drizzle));
1910
drizzle_result_st result;
1911
drizzle_return_t ret;
1913
1906
if (verbose >= 3)
1914
1907
printf("%s;\n", query);
1916
if (drizzle_select_db(con, &result, db, &ret) == NULL ||
1917
ret != DRIZZLE_RETURN_OK)
1909
if (drizzleclient_select_db(drizzle, db))
1919
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
1920
ret == DRIZZLE_RETURN_ERROR_CODE ?
1921
drizzle_result_error(&result) : drizzle_con_error(con));
1911
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1912
drizzleclient_error(drizzle));
1924
drizzle_result_free(&result);
1925
1915
sptr->create_count++;
1930
1920
len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1931
1921
engine_stmt->string);
1932
if (run_query(con, NULL, query, len))
1922
if (run_query(drizzle, query, len))
1934
fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
1935
drizzle_con_error(con));
1924
fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1925
drizzleclient_error(drizzle));
1938
1928
sptr->create_count++;
1954
1944
snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
1955
1945
engine_stmt->option);
1956
if (run_query(con, NULL, buffer, strlen(buffer)))
1946
if (run_query(drizzle, buffer, strlen(buffer)))
1958
1948
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1959
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1949
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1960
1950
if (!opt_ignore_sql_errors)
1967
if (run_query(con, NULL, ptr->string, ptr->length))
1957
if (run_query(drizzle, ptr->string, ptr->length))
1969
1959
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1970
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1960
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1971
1961
if (!opt_ignore_sql_errors)
1993
drop_schema(drizzle_con_st *con, const char *db)
1983
drop_schema(DRIZZLE *drizzle, const char *db)
1995
1985
char query[HUGE_STRING_LENGTH];
1998
1988
len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
2000
if (run_query(con, NULL, query, len))
1990
if (run_query(drizzle, query, len))
2002
1992
fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
2003
internal::my_progname, db, drizzle_con_error(con));
1993
my_progname, db, drizzleclient_error(drizzle));
2013
run_statements(drizzle_con_st *con, statement *stmt)
2003
run_statements(DRIZZLE *drizzle, statement *stmt)
2015
2005
statement *ptr;
2006
DRIZZLE_RES *result;
2017
2009
for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
2019
if (run_query(con, NULL, ptr->string, ptr->length))
2011
if (run_query(drizzle, ptr->string, ptr->length))
2021
2013
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2022
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
2014
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
2017
if (!opt_only_print)
2019
if (drizzleclient_field_count(drizzle))
2021
result= drizzleclient_store_result(drizzle);
2022
drizzleclient_free_result(result);
2083
2083
if (pthread_create(&mainthread, &attr, run_task,
2084
2084
(void *)con) != 0)
2086
fprintf(stderr,"%s: Could not create thread\n", internal::my_progname);
2086
fprintf(stderr,"%s: Could not create thread\n", my_progname);
2089
2089
thread_counter++;
2103
2103
if (pthread_create(&mainthread, &attr, timer_thread,
2104
2104
(void *)&opt_timer_length) != 0)
2106
fprintf(stderr,"%s: Could not create timer thread\n", internal::my_progname);
2106
fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
2178
2178
uint64_t counter= 0, queries;
2179
2179
uint64_t detach_counter;
2180
2180
unsigned int commit_counter;
2182
drizzle_result_st result;
2182
DRIZZLE_RES *result;
2184
2184
statement *ptr;
2185
thread_context *ctx= (thread_context *)p;
2185
thread_context *con= (thread_context *)p;
2187
2187
pthread_mutex_lock(&sleeper_mutex);
2188
2188
while (master_wakeup)
2200
2200
commit_counter= 0;
2201
2201
if (commit_rate)
2202
run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2202
run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2205
for (ptr= ctx->stmt, detach_counter= 0;
2205
for (ptr= con->stmt, detach_counter= 0;
2206
2206
ptr && ptr->length;
2207
2207
ptr= ptr->next, detach_counter++)
2209
2209
if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2212
slap_connect(&con, true);
2211
slap_close(&drizzle);
2212
slap_connect(&drizzle, true);
2241
2241
length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2242
2242
(int)ptr->length, ptr->string, key);
2244
if (run_query(&con, &result, buffer, length))
2244
if (run_query(&drizzle, buffer, length))
2246
2246
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2247
internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
2247
my_progname, (uint32_t)length, buffer, drizzleclient_error(&drizzle));
2254
if (run_query(&con, &result, ptr->string, ptr->length))
2254
if (run_query(&drizzle, ptr->string, ptr->length))
2256
2256
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2257
internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
2257
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(&drizzle));
2262
2262
if (!opt_only_print)
2264
while ((row = drizzle_row_next(&result)))
2266
drizzle_result_free(&result);
2266
if (drizzleclient_field_count(&drizzle))
2268
result= drizzleclient_store_result(&drizzle);
2269
while ((row = drizzleclient_fetch_row(result)))
2271
drizzleclient_free_result(result);
2273
} while(drizzleclient_next_result(&drizzle) == 0);
2270
2277
if (commit_rate && (++commit_counter == commit_rate))
2272
2279
commit_counter= 0;
2273
run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
2280
run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2276
2283
/* If the timer is set, and the alarm is not active then end */
2280
2287
/* If limit has been reached, and we are not in a timer_alarm just end */
2281
if (ctx->limit && queries == ctx->limit && timer_alarm == false)
2288
if (con->limit && queries == con->limit && timer_alarm == false)
2285
2292
if (opt_timer_length && timer_alarm == true)
2286
2293
goto limit_not_met;
2288
if (ctx->limit && queries < ctx->limit)
2295
if (con->limit && queries < con->limit)
2289
2296
goto limit_not_met;
2293
2300
if (commit_rate)
2294
run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
2301
run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2303
slap_close(&drizzle);
2298
2305
pthread_mutex_lock(&counter_mutex);
2299
2306
thread_counter--;
2300
2307
pthread_cond_signal(&count_threshhold);
2301
2308
pthread_mutex_unlock(&counter_mutex);
2415
2422
uint32_t length= strlen(script);
2416
2423
uint32_t count= 0; /* We know that there is always one */
2418
for (tmp= *sptr= (statement *)calloc(1, sizeof(statement));
2425
for (tmp= *sptr= (statement *)malloc(sizeof(statement));
2419
2426
(retstr= strchr(ptr, delm));
2420
tmp->next= (statement *)calloc(1, sizeof(statement)),
2427
tmp->next= (statement *)malloc(sizeof(statement)),
2421
2428
tmp= tmp->next)
2425
fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2430
memset(tmp, 0, sizeof(statement));
2430
2432
tmp->length= (size_t)(retstr - ptr);
2431
2433
tmp->string= (char *)malloc(tmp->length + 1);
2433
2434
if (tmp->string == NULL)
2435
2436
fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2439
2439
memcpy(tmp->string, ptr, tmp->length);
2440
2440
tmp->string[tmp->length]= 0;
2441
2441
ptr+= retstr - ptr + 1;
2575
2575
con->real_users, /* Children used max_timing */
2576
2576
con->avg_rows /* Queries run */
2578
internal::my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2578
my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2672
slap_close(drizzle_con_st *con)
2672
slap_close(DRIZZLE *drizzle)
2674
2674
if (opt_only_print)
2677
drizzle_free(drizzle_con_drizzle(con));
2677
drizzleclient_close(drizzle);
2681
slap_connect(drizzle_con_st *con, bool connect_to_schema)
2681
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
2683
2683
/* Connect to server */
2684
2684
static uint32_t connection_retry_sleep= 100000; /* Microseconds */
2685
2685
int x, connect_error= 1;
2686
drizzle_return_t ret;
2687
drizzle_st *drizzle;
2689
2687
if (opt_only_print)
2692
2690
if (opt_delayed_start)
2693
2691
usleep(random()%opt_delayed_start);
2695
if ((drizzle= drizzle_create(NULL)) == NULL ||
2696
drizzle_con_add_tcp(drizzle, con, host, opt_drizzle_port, user,
2698
connect_to_schema ? create_schema_string : NULL,
2699
opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
2701
fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
2693
drizzleclient_create(drizzle);
2696
drizzleclient_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
2705
2698
for (x= 0; x < 10; x++)
2707
if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
2702
if (drizzleclient_connect(drizzle, host, user, opt_password,
2703
connect_to_schema ? create_schema_string : NULL,
2705
opt_drizzle_unix_port,
2709
2708
/* Connect suceeded */
2710
2709
connect_error= 0;
2715
2714
if (connect_error)
2717
fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
2718
ret, drizzle_con_error(con));
2716
fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
2717
my_progname, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));