87
/* Added this for string translation. */
88
#include <drizzled/gettext.h>
87
90
using namespace std;
90
93
static char *shared_memory_base_name=0;
97
bool get_one_option(int optid, const struct my_option *, char *argument);
93
99
/* Global Thread counter */
100
uint32_t thread_counter;
95
101
pthread_mutex_t counter_mutex;
96
102
pthread_cond_t count_threshhold;
103
uint32_t master_wakeup;
98
104
pthread_mutex_t sleeper_mutex;
99
105
pthread_cond_t sleep_threshhold;
106
112
static char **defaults_argv;
108
114
char **primary_keys;
109
uint64_t primary_keys_number_of;
115
/* This gets passed to malloc, so lets set it to an arch-dependant size */
116
size_t primary_keys_number_of;
111
118
static char *host= NULL, *opt_password= NULL, *user= NULL,
112
119
*user_supplied_query= NULL,
122
129
const char *create_schema_string= "drizzleslap";
124
131
static bool opt_preserve= true;
125
static bool debug_info_flag= 0, debug_check_flag= 0;
132
static bool debug_info_flag= false, debug_check_flag= false;
126
133
static bool opt_only_print= false;
127
134
static bool opt_burnin= false;
128
135
static bool opt_ignore_sql_errors= false;
137
144
CLIENT_MULTI_STATEMENTS;
139
146
static int verbose, delimiter_length;
140
static uint commit_rate;
141
static uint detach_rate;
142
static uint opt_timer_length;
143
static uint opt_delayed_start;
147
static uint32_t commit_rate;
148
static uint32_t detach_rate;
149
static uint32_t opt_timer_length;
150
static uint32_t opt_delayed_start;
144
151
const char *num_int_cols_opt;
145
152
const char *num_char_cols_opt;
146
153
const char *num_blob_cols_opt;
158
165
static unsigned int num_int_cols_index= 0;
159
166
static unsigned int num_char_cols_index= 0;
160
167
static unsigned int iterations;
161
static uint my_end_arg= 0;
168
static uint32_t my_end_arg= 0;
162
169
static uint64_t actual_queries= 0;
163
170
static uint64_t auto_actual_queries;
164
171
static uint64_t auto_generate_sql_unique_write_number;
168
175
static uint64_t auto_generate_sql_number;
169
176
const char *concurrency_str= NULL;
170
177
static char *create_string;
178
uint32_t *concurrency;
173
const char *default_dbug_option="d:t:o,/tmp/drizzleslap.trace";
180
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
174
181
const char *opt_csv_str;
177
184
static int get_options(int *argc,char ***argv);
178
static uint opt_drizzle_port= 0;
185
static uint32_t opt_drizzle_port= 0;
180
187
static const char *load_default_groups[]= { "drizzleslap","client",0 };
265
272
void print_conclusions(conclusions *con);
266
273
void print_conclusions_csv(conclusions *con);
267
274
void generate_stats(conclusions *con, option_string *eng, stats *sptr);
268
uint parse_comma(const char *string, uint **range);
269
uint parse_delimiter(const char *script, statement **stmt, char delm);
270
uint parse_option(const char *origin, option_string **stmt, char delm);
275
uint32_t parse_comma(const char *string, uint32_t **range);
276
uint32_t parse_delimiter(const char *script, statement **stmt, char delm);
277
uint32_t parse_option(const char *origin, option_string **stmt, char delm);
271
278
static int drop_schema(DRIZZLE *drizzle, const char *db);
272
uint get_random_string(char *buf, size_t size);
279
uint32_t get_random_string(char *buf, size_t size);
273
280
static statement *build_table_string(void);
274
281
static statement *build_insert_string(void);
275
282
static statement *build_update_string(void);
278
285
static int drop_primary_key_list(void);
279
286
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
280
287
option_string *engine_stmt, stats *sptr);
281
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
288
static int run_scheduler(stats *sptr, statement **stmts, uint32_t concur,
283
pthread_handler_t run_task(void *p);
284
pthread_handler_t timer_thread(void *p);
290
extern "C" pthread_handler_t run_task(void *p);
291
extern "C" pthread_handler_t timer_thread(void *p);
285
292
void statement_cleanup(statement *stmt);
286
293
void option_cleanup(option_string *stmt);
287
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr);
294
void concurrency_loop(DRIZZLE *drizzle, uint32_t current, option_string *eptr);
288
295
static int run_statements(DRIZZLE *drizzle, statement *stmt);
289
296
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
290
297
void slap_close(DRIZZLE *drizzle);
319
326
MY_INIT(argv[0]);
321
load_defaults("my",load_default_groups,&argc,&argv);
328
load_defaults("drizzle",load_default_groups,&argc,&argv);
322
329
defaults_argv=argv;
323
330
if (get_options(&argc,&argv))
431
438
conclusions conclusion;
432
439
uint64_t client_limit;
434
head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
435
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
441
head_sptr= (stats *)malloc(sizeof(stats) * iterations);
442
if (head_sptr == NULL)
444
fprintf(stderr,"Error allocating memory in concurrency_loop\n");
447
memset(head_sptr, 0, sizeof(stats) * iterations);
437
449
memset(&conclusion, 0, sizeof(conclusions));
636
648
"out what it would have done instead.",
637
649
(char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL, NO_ARG,
638
650
0, 0, 0, 0, 0, 0},
640
652
"Password to use when connecting to server. If password is not given it's "
641
653
"asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
642
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
643
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
654
{"port", 'p', "Port number to use for connection.",
655
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
645
656
{"post-query", OPT_SLAP_POST_QUERY,
646
657
"Query to run or file containing query to execute after tests have completed.",
647
658
(char**) &user_supplied_post_statements,
700
711
static void print_version(void)
702
713
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname, SLAP_VERSION,
703
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
714
drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
707
718
static void usage(void)
710
puts("Copyright (C) 2005 DRIZZLE AB");
721
puts("Copyright (C) 2008 Sun Microsystems");
711
722
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
712
723
\nand you are welcome to modify and redistribute it under the GPL \
714
725
puts("Run a query multiple times against the server\n");
715
726
printf("Usage: %s [OPTIONS]\n",my_progname);
716
print_defaults("my",load_default_groups);
727
print_defaults("drizzle",load_default_groups);
717
728
my_print_help(my_long_options);
721
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
731
bool get_one_option(int optid, const struct my_option *, char *argument)
734
uint64_t temp_drizzle_port= 0;
741
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
742
/* if there is an alpha character this is not a valid port */
743
if (strlen(endchar) != 0)
745
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
748
/* If the port number is > 65535 it is not a valid port
749
This also helps with potential data loss casting unsigned long to a
751
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
753
fprintf(stderr, _("Value supplied for port is not valid.\n"));
758
opt_drizzle_port= (uint32_t) temp_drizzle_port;
732
764
char *start= argument;
734
opt_password= my_strdup(argument,MYF(MY_FAE));
735
while (*argument) *argument++= 'x'; /* Destroy argument */
767
opt_password = strdup(argument);
768
if (opt_password == NULL)
770
fprintf(stderr, "Memory allocation error while copying password. "
776
/* Overwriting password with 'x' */
737
start[1]= 0; /* Cut length of argument */
781
/* Cut length of argument */
894
939
table_string.append(")");
895
ptr= (statement *)my_malloc(sizeof(statement),
896
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
897
ptr->string = (char *)my_malloc(table_string.length()+1,
898
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
940
ptr= (statement *)malloc(sizeof(statement));
943
fprintf(stderr, "Memory Allocation error in creating table\n");
946
memset(ptr, 0, sizeof(statement));
947
ptr->string = (char *)malloc(table_string.length()+1);
948
if (ptr->string == NULL)
950
fprintf(stderr, "Memory Allocation error in creating table\n");
953
memset(ptr->string, 0, table_string.length()+1);
899
954
ptr->length= table_string.length()+1;
900
955
ptr->type= CREATE_TABLE_TYPE;
901
my_stpcpy(ptr->string, table_string.c_str());
956
strcpy(ptr->string, table_string.c_str());
958
1013
update_string.append(" WHERE id = ");
961
ptr= (statement *)my_malloc(sizeof(statement),
962
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1016
ptr= (statement *)malloc(sizeof(statement));
1019
fprintf(stderr, "Memory Allocation error in creating update\n");
1022
memset(ptr, 0, sizeof(statement));
964
ptr->string= (char *)my_malloc(update_string.length() + 1,
965
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
966
1024
ptr->length= update_string.length()+1;
1025
ptr->string= (char *)malloc(ptr->length);
1026
if (ptr->string == NULL)
1028
fprintf(stderr, "Memory Allocation error in creating update\n");
1031
memset(ptr->string, 0, ptr->length);
967
1032
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
968
1033
ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
970
1035
ptr->type= UPDATE_TYPE;
971
my_stpcpy(ptr->string, update_string.c_str());
1036
strncpy(ptr->string, update_string.c_str(), ptr->length);
1056
1121
if (num_blob_cols_size > HUGE_STRING_LENGTH)
1058
blob_ptr= (char *)my_malloc(sizeof(char)*num_blob_cols_size,
1059
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1123
blob_ptr= (char *)malloc(sizeof(char)*num_blob_cols_size);
1062
1126
fprintf(stderr, "Memory Allocation error in creating select\n");
1129
memset(blob_ptr, 0, sizeof(char)*num_blob_cols_size);
1094
1159
insert_string.append(")", 1);
1096
if (!(ptr= (statement *)my_malloc(sizeof(statement), MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1098
fprintf(stderr, "Memory Allocation error in creating select\n");
1101
if (!(ptr->string= (char *)my_malloc(insert_string.length() + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1103
fprintf(stderr, "Memory Allocation error in creating select\n");
1161
if (!(ptr= (statement *)malloc(sizeof(statement))))
1163
fprintf(stderr, "Memory Allocation error in creating select\n");
1166
memset(ptr, 0, sizeof(statement));
1106
1167
ptr->length= insert_string.length()+1;
1168
if (!(ptr->string= (char *)malloc(ptr->length)))
1170
fprintf(stderr, "Memory Allocation error in creating select\n");
1173
memset(ptr->string, 0, ptr->length);
1107
1174
ptr->type= INSERT_TYPE;
1108
my_stpcpy(ptr->string, insert_string.c_str());
1175
strcpy(ptr->string, insert_string.c_str());
1181
1248
(auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1182
1249
query_string.append(" WHERE id = ");
1184
ptr= (statement *)my_malloc(sizeof(statement),
1185
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1186
ptr->string= (char *)my_malloc(query_string.length() + 1,
1187
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1251
ptr= (statement *)malloc(sizeof(statement));
1254
fprintf(stderr, "Memory Allocation error in creating select\n");
1257
memset(ptr, 0, sizeof(statement));
1188
1258
ptr->length= query_string.length()+1;
1259
ptr->string= (char *)malloc(ptr->length);
1260
if (ptr->string == NULL)
1262
fprintf(stderr, "Memory Allocation error in creating select\n");
1265
memset(ptr->string, 0, ptr->length);
1190
1267
(auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1191
1268
ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1193
1270
ptr->type= SELECT_TYPE;
1194
my_stpcpy(ptr->string, query_string.c_str());
1271
strcpy(ptr->string, query_string.c_str());
1347
1425
query_statements_count=
1348
1426
parse_option(opt_auto_generate_sql_type, &query_options, ',');
1350
query_statements= (statement **)my_malloc(sizeof(statement *) * query_statements_count,
1351
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1428
query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
1429
if (query_statements == NULL)
1431
fprintf(stderr, "Memory Allocation error in Building Query Statements\n");
1434
memset(query_statements, 0, sizeof(statement *) * query_statements_count);
1353
1436
sql_type= query_options;
1468
1551
fprintf(stderr,"%s: Could not open create file\n", my_progname);
1471
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1472
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1473
my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1554
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1556
fprintf(stderr, "Request for more memory than architecture supports\n");
1559
tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1560
if (tmp_string == NULL)
1562
fprintf(stderr, "Memory Allocation error in option processing\n");
1565
memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
1566
bytes_read= read(data_file, (unsigned char*) tmp_string,
1567
(size_t)sbuf.st_size);
1474
1568
tmp_string[sbuf.st_size]= '\0';
1475
my_close(data_file,MYF(0));
1570
if (bytes_read != sbuf.st_size)
1572
fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1476
1574
parse_delimiter(tmp_string, &create_statements, delimiter[0]);
1477
1575
free(tmp_string);
1487
1585
query_statements_count=
1488
1586
parse_option("default", &query_options, ',');
1490
query_statements= (statement **)my_malloc(sizeof(statement *),
1491
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1588
query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
1589
if (query_statements == NULL)
1591
fprintf(stderr, "Memory Allocation error in option processing\n");
1594
memset(query_statements, 0, sizeof(statement *) * query_statements_count);
1494
1597
if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1505
1608
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1508
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1509
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1510
my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1611
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1613
fprintf(stderr, "Request for more memory than architecture supports\n");
1616
tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1617
if (tmp_string == NULL)
1619
fprintf(stderr, "Memory Allocation error in option processing\n");
1622
memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
1623
bytes_read= read(data_file, (unsigned char*) tmp_string,
1624
(size_t)sbuf.st_size);
1511
1625
tmp_string[sbuf.st_size]= '\0';
1512
my_close(data_file,MYF(0));
1627
if (bytes_read != sbuf.st_size)
1629
fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1513
1631
if (user_supplied_query)
1514
1632
actual_queries= parse_delimiter(tmp_string, &query_statements[0],
1537
1655
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1540
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1541
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1542
my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1658
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1660
fprintf(stderr, "Request for more memory than architecture supports\n");
1663
tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1664
if (tmp_string == NULL)
1666
fprintf(stderr, "Memory Allocation error in option processing\n");
1669
memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
1670
bytes_read= read(data_file, (unsigned char*) tmp_string,
1671
(size_t)sbuf.st_size);
1543
1672
tmp_string[sbuf.st_size]= '\0';
1544
my_close(data_file,MYF(0));
1674
if (bytes_read != sbuf.st_size)
1676
fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1545
1678
if (user_supplied_pre_statements)
1546
1679
(void)parse_delimiter(tmp_string, &pre_statements,
1569
1702
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1572
tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1573
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1574
my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1706
if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1708
fprintf(stderr, "Request for more memory than architecture supports\n");
1711
tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1712
if (tmp_string == NULL)
1714
fprintf(stderr, "Memory Allocation error in option processing\n");
1717
memset(tmp_string, 0, (size_t)(sbuf.st_size+1));
1719
bytes_read= read(data_file, (unsigned char*) tmp_string,
1720
(size_t)(sbuf.st_size));
1575
1721
tmp_string[sbuf.st_size]= '\0';
1576
my_close(data_file,MYF(0));
1723
if (bytes_read != sbuf.st_size)
1725
fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1577
1727
if (user_supplied_post_statements)
1578
1728
(void)parse_delimiter(tmp_string, &post_statements,
1608
1758
if (verbose >= 3)
1609
1759
printf("%.*s;\n", len, query);
1610
return drizzle_real_query(drizzle, query, len);
1760
return drizzleclient_real_query(drizzle, query, len);
1627
1777
strstr(engine_stmt->string, "blackhole")))
1629
1779
primary_keys_number_of= 1;
1630
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1631
primary_keys_number_of),
1632
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1780
primary_keys= (char **)malloc((sizeof(char *) *
1781
primary_keys_number_of));
1782
if (primary_keys == NULL)
1784
fprintf(stderr, "Memory Allocation error in option processing\n");
1788
memset(primary_keys, 0, (sizeof(char *) * primary_keys_number_of));
1633
1789
/* Yes, we strdup a const string to simplify the interface */
1634
primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
1790
primary_keys[0]= strdup("796c4422-1d94-102a-9d6d-00e0812d");
1791
if (primary_keys[0] == NULL)
1793
fprintf(stderr, "Memory Allocation error in option processing\n");
1638
1799
if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
1640
1801
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1641
drizzle_error(drizzle));
1802
drizzleclient_error(drizzle));
1645
result= drizzle_store_result(drizzle);
1646
primary_keys_number_of= drizzle_num_rows(result);
1806
result= drizzleclient_store_result(drizzle);
1807
uint64_t num_rows_ret= drizzleclient_num_rows(result);
1808
if (num_rows_ret > SIZE_MAX)
1810
fprintf(stderr, "More primary keys than than architecture supports\n");
1813
primary_keys_number_of= (size_t)num_rows_ret;
1648
1815
/* So why check this? Blackhole :) */
1649
1816
if (primary_keys_number_of)
1652
1819
We create the structure and loop and create the items.
1654
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1655
primary_keys_number_of),
1656
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1657
row= drizzle_fetch_row(result);
1821
primary_keys= (char **)malloc(sizeof(char *) *
1822
primary_keys_number_of);
1823
if (primary_keys == NULL)
1825
fprintf(stderr, "Memory Allocation error in option processing\n");
1828
memset(primary_keys, 0, (size_t)(sizeof(char *) * primary_keys_number_of));
1829
row= drizzleclient_fetch_row(result);
1658
1830
for (counter= 0; counter < primary_keys_number_of;
1659
counter++, row= drizzle_fetch_row(result))
1660
primary_keys[counter]= my_strdup(row[0], MYF(0));
1831
counter++, row= drizzleclient_fetch_row(result))
1833
primary_keys[counter]= strdup(row[0]);
1834
if (primary_keys[counter] == NULL)
1836
fprintf(stderr, "Memory Allocation error in option processing\n");
1663
drizzle_free_result(result);
1842
drizzleclient_free_result(result);
1704
1883
if (run_query(drizzle, query, len))
1706
1885
fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1707
drizzle_error(drizzle));
1886
drizzleclient_error(drizzle));
1721
1900
if (verbose >= 3)
1722
1901
printf("%s;\n", query);
1724
if (drizzle_select_db(drizzle, db))
1903
if (drizzleclient_select_db(drizzle, db))
1726
1905
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1727
drizzle_error(drizzle));
1906
drizzleclient_error(drizzle));
1730
1909
sptr->create_count++;
1761
1940
if (run_query(drizzle, buffer, strlen(buffer)))
1763
1942
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1764
my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
1943
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1765
1944
if (!opt_ignore_sql_errors)
1772
1951
if (run_query(drizzle, ptr->string, ptr->length))
1774
1953
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1775
my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
1954
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1776
1955
if (!opt_ignore_sql_errors)
1805
1984
if (run_query(drizzle, query, len))
1807
1986
fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1808
my_progname, db, drizzle_error(drizzle));
1987
my_progname, db, drizzleclient_error(drizzle));
1826
2005
if (run_query(drizzle, ptr->string, ptr->length))
1828
2007
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1829
my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
2008
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1832
2011
if (!opt_only_print)
1834
if (drizzle_field_count(drizzle))
2013
if (drizzleclient_field_count(drizzle))
1836
result= drizzle_store_result(drizzle);
1837
drizzle_free_result(result);
2015
result= drizzleclient_store_result(drizzle);
2016
drizzleclient_free_result(result);
1846
run_scheduler(stats *sptr, statement **stmts, uint concur, uint64_t limit)
2025
run_scheduler(stats *sptr, statement **stmts, uint32_t concur, uint64_t limit)
1850
2029
unsigned int real_concurrency;
1851
2030
struct timeval start_time, end_time;
1852
2031
option_string *sql_type;
2054
2238
if (run_query(&drizzle, buffer, length))
2056
2240
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2057
my_progname, (uint)length, buffer, drizzle_error(&drizzle));
2241
my_progname, (uint32_t)length, buffer, drizzleclient_error(&drizzle));
2064
2248
if (run_query(&drizzle, ptr->string, ptr->length))
2066
2250
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2067
my_progname, (uint)ptr->length, ptr->string, drizzle_error(&drizzle));
2251
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(&drizzle));
2076
if (drizzle_field_count(&drizzle))
2260
if (drizzleclient_field_count(&drizzle))
2078
result= drizzle_store_result(&drizzle);
2079
while ((row = drizzle_fetch_row(result)))
2262
result= drizzleclient_store_result(&drizzle);
2263
while ((row = drizzleclient_fetch_row(result)))
2081
drizzle_free_result(result);
2265
drizzleclient_free_result(result);
2083
} while(drizzle_next_result(&drizzle) == 0);
2267
} while(drizzleclient_next_result(&drizzle) == 0);
2135
2319
option_string **sptr= stmt;
2136
2320
option_string *tmp;
2137
uint length= strlen(origin);
2138
uint count= 0; /* We know that there is always one */
2321
uint32_t length= strlen(origin);
2322
uint32_t count= 0; /* We know that there is always one */
2140
2324
end_ptr= (char *)origin + length;
2142
tmp= *sptr= (option_string *)my_malloc(sizeof(option_string),
2143
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2326
tmp= *sptr= (option_string *)malloc(sizeof(option_string));
2329
fprintf(stderr,"Error allocating memory while parsing options\n");
2332
memset(tmp, 0, sizeof(option_string));
2145
2334
for (begin_ptr= (char *)origin;
2146
2335
begin_ptr != end_ptr;
2163
size_t length= strlen(begin_ptr);
2164
memcpy(buffer, begin_ptr, length);
2352
size_t begin_len= strlen(begin_ptr);
2353
memcpy(buffer, begin_ptr, begin_len);
2165
2354
begin_ptr= end_ptr;
2174
2363
/* Move past the : and the first string */
2175
2364
tmp->option_length= strlen(buffer_ptr);
2176
tmp->option= my_strndup(buffer_ptr, (uint)tmp->option_length,
2365
tmp->option= (char *)malloc(tmp->option_length + 1);
2366
if (tmp->option == NULL)
2368
fprintf(stderr,"Error allocating memory while parsing options\n");
2371
memcpy(tmp->option, buffer_ptr, tmp->option_length);
2372
tmp->option[tmp->option_length]= 0;
2180
tmp->string= my_strndup(buffer, strlen(buffer), MYF(MY_FAE));
2181
2375
tmp->length= strlen(buffer);
2376
tmp->string= strdup(buffer);
2377
if (tmp->string == NULL)
2379
fprintf(stderr,"Error allocating memory while parsing options\n");
2183
2383
if (isspace(*begin_ptr))
2188
2388
if (begin_ptr != end_ptr)
2189
tmp->next= (option_string *)my_malloc(sizeof(option_string),
2190
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2390
tmp->next= (option_string *)malloc(sizeof(option_string));
2391
if (tmp->next == NULL)
2393
fprintf(stderr,"Error allocating memory while parsing options\n");
2396
memset(tmp->next, 0, sizeof(option_string));
2205
2413
char *ptr= (char *)script;
2206
2414
statement **sptr= stmt;
2207
2415
statement *tmp;
2208
uint length= strlen(script);
2209
uint count= 0; /* We know that there is always one */
2416
uint32_t length= strlen(script);
2417
uint32_t count= 0; /* We know that there is always one */
2211
for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
2212
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2419
for (tmp= *sptr= (statement *)malloc(sizeof(statement));
2213
2420
(retstr= strchr(ptr, delm));
2214
tmp->next= (statement *)my_malloc(sizeof(statement),
2215
MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
2421
tmp->next= (statement *)malloc(sizeof(statement)),
2424
memset(tmp, 0, sizeof(statement));
2219
tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
2220
2426
tmp->length= (size_t)(retstr - ptr);
2427
tmp->string= (char *)malloc(tmp->length + 1);
2428
if (tmp->string == NULL)
2430
fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2433
memcpy(tmp->string, ptr, tmp->length);
2434
tmp->string[tmp->length]= 0;
2221
2435
ptr+= retstr - ptr + 1;
2222
2436
if (isspace(*ptr))
2226
2440
if (ptr != script+length)
2228
tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
2230
2442
tmp->length= (size_t)((script + length) - ptr);
2443
tmp->string= (char *)malloc(tmp->length + 1);
2444
if (tmp->string == NULL)
2446
fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2449
memcpy(tmp->string, ptr, tmp->length);
2450
tmp->string[tmp->length]= 0;
2241
2461
In restrospect, this is a lousy name from this function.
2244
parse_comma(const char *string, uint **range)
2464
parse_comma(const char *string, uint32_t **range)
2246
uint count= 1,x; /* We know that there is always one */
2466
unsigned int count= 1,x; /* We know that there is always one */
2248
2468
char *ptr= (char *)string;
2251
2471
for (;*ptr; ptr++)
2252
2472
if (*ptr == ',') count++;
2254
2474
/* One extra spot for the NULL */
2255
nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
2256
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2475
nptr= *range= (uint32_t *)malloc(sizeof(unsigned int) * (count + 1));
2476
memset(nptr, 0, sizeof(unsigned int) * (count + 1));
2258
2478
ptr= (char *)string;
2349
2569
con->real_users, /* Children used max_timing */
2350
2570
con->avg_rows /* Queries run */
2352
my_write(csv_file, (unsigned char*) buffer, (uint)strlen(buffer), MYF(0));
2572
my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2464
2684
if (opt_delayed_start)
2465
my_sleep(random()%opt_delayed_start);
2685
usleep(random()%opt_delayed_start);
2467
drizzle_create(drizzle);
2687
drizzleclient_create(drizzle);
2469
2689
if (opt_compress)
2470
drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
2690
drizzleclient_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
2472
2692
for (x= 0; x < 10; x++)
2476
if (drizzle_connect(drizzle, host, user, opt_password,
2696
if (drizzleclient_connect(drizzle, host, user, opt_password,
2477
2697
connect_to_schema ? create_schema_string : NULL,
2478
2698
opt_drizzle_port,
2479
2699
opt_drizzle_unix_port,
2483
2703
connect_error= 0;
2486
my_sleep(connection_retry_sleep);
2706
usleep(connection_retry_sleep);
2488
2708
if (connect_error)
2490
2710
fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
2491
my_progname, drizzle_errno(drizzle), drizzle_error(drizzle));
2711
my_progname, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));