140
140
auto_generate_sql= false;
141
141
const char *opt_auto_generate_sql_type= "mixed";
143
static unsigned long connect_flags= CLIENT_MULTI_RESULTS |
144
CLIENT_MULTI_STATEMENTS;
146
143
static int verbose, delimiter_length;
147
144
static uint32_t commit_rate;
148
145
static uint32_t detach_rate;
275
272
uint32_t parse_comma(const char *string, uint32_t **range);
276
273
uint32_t parse_delimiter(const char *script, statement **stmt, char delm);
277
274
uint32_t parse_option(const char *origin, option_string **stmt, char delm);
278
static int drop_schema(DRIZZLE *drizzle, const char *db);
275
static int drop_schema(drizzle_con_st *con, const char *db);
279
276
uint32_t get_random_string(char *buf, size_t size);
280
277
static statement *build_table_string(void);
281
278
static statement *build_insert_string(void);
282
279
static statement *build_update_string(void);
283
280
static statement * build_select_string(bool key);
284
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
281
static int generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt);
285
282
static int drop_primary_key_list(void);
286
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
283
static int create_schema(drizzle_con_st *con, const char *db, statement *stmt,
287
284
option_string *engine_stmt, stats *sptr);
288
285
static int run_scheduler(stats *sptr, statement **stmts, uint32_t concur,
291
288
extern "C" pthread_handler_t timer_thread(void *p);
292
289
void statement_cleanup(statement *stmt);
293
290
void option_cleanup(option_string *stmt);
294
void concurrency_loop(DRIZZLE *drizzle, uint32_t current, option_string *eptr);
295
static int run_statements(DRIZZLE *drizzle, statement *stmt);
296
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
297
void slap_close(DRIZZLE *drizzle);
298
static int run_query(DRIZZLE *drizzle, const char *query, int len);
291
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr);
292
static int run_statements(drizzle_con_st *con, statement *stmt);
293
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
294
void slap_close(drizzle_con_st *con);
295
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
299
296
void standard_deviation (conclusions *con, stats *sptr);
301
298
static const char ALPHANUMERICS[]=
356
slap_connect(&drizzle, false);
353
slap_connect(&con, false);
358
355
pthread_mutex_init(&counter_mutex, NULL);
359
356
pthread_cond_init(&count_threshhold, NULL);
377
374
if (*concurrency)
379
376
for (current= concurrency; current && *current; current++)
380
concurrency_loop(&drizzle, *current, eptr);
377
concurrency_loop(&con, *current, eptr);
384
381
uint32_t infinite= 1;
386
concurrency_loop(&drizzle, infinite, eptr);
383
concurrency_loop(&con, infinite, eptr);
388
385
while (infinite++);
391
388
if (!opt_preserve)
392
drop_schema(&drizzle, create_schema_string);
389
drop_schema(&con, create_schema_string);
394
391
} while (eptr ? (eptr= eptr->next) : 0);
463
460
data in the table.
465
462
if (opt_preserve == false)
466
drop_schema(drizzle, create_schema_string);
463
drop_schema(con, create_schema_string);
468
465
/* First we create */
469
466
if (create_statements)
470
create_schema(drizzle, create_schema_string, create_statements, eptr, sptr);
467
create_schema(con, create_schema_string, create_statements, eptr, sptr);
473
470
If we generated GUID we need to build a list of them from creation that
476
473
if (verbose >= 2)
477
474
printf("Generating primary key list\n");
478
475
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
479
generate_primary_key_list(drizzle, eptr);
476
generate_primary_key_list(con, eptr);
482
run_query(drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
479
run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
485
482
assert(system(pre_system)!=-1);
489
486
correct/adjust any item that they want.
491
488
if (pre_statements)
492
run_statements(drizzle, pre_statements);
489
run_statements(con, pre_statements);
494
491
run_scheduler(sptr, query_statements, current, client_limit);
496
493
if (post_statements)
497
run_statements(drizzle, post_statements);
494
run_statements(con, post_statements);
500
497
assert(system(post_system)!=-1);
711
708
static void print_version(void)
713
710
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname, SLAP_VERSION,
714
drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
711
drizzle_version(),SYSTEM_TYPE,MACHINE_TYPE);
1742
1739
parse_option(default_engine, &engine_options, ',');
1744
1741
if (tty_password)
1745
opt_password= drizzleclient_get_tty_password(NULL);
1742
opt_password= client_get_tty_password(NULL);
1750
static int run_query(DRIZZLE *drizzle, const char *query, int len)
1747
static int run_query(drizzle_con_st *con, drizzle_result_st *result,
1748
const char *query, int len)
1750
drizzle_return_t ret;
1751
drizzle_result_st result_buffer;
1752
1753
if (opt_only_print)
1754
1755
printf("%.*s;\n", len, query);
1758
1759
if (verbose >= 3)
1759
1760
printf("%.*s;\n", len, query);
1760
return drizzleclient_real_query(drizzle, query, len);
1763
result= &result_buffer;
1765
result= drizzle_query(con, result, query, len, &ret);
1767
if (ret == DRIZZLE_RETURN_OK)
1768
ret= drizzle_result_buffer(result);
1770
if (result == &result_buffer)
1771
drizzle_result_free(result);
1765
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
1778
generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt)
1767
DRIZZLE_RES *result;
1780
drizzle_result_st result;
1769
1782
uint64_t counter;
1799
if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
1812
if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1801
1814
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1802
drizzleclient_error(drizzle));
1815
drizzle_con_error(con));
1806
result= drizzleclient_store_result(drizzle);
1807
uint64_t num_rows_ret= drizzleclient_num_rows(result);
1819
uint64_t num_rows_ret= drizzle_result_row_count(&result);
1808
1820
if (num_rows_ret > SIZE_MAX)
1810
1822
fprintf(stderr, "More primary keys than than architecture supports\n");
1828
1840
memset(primary_keys, 0, (size_t)(sizeof(char *) * primary_keys_number_of));
1829
row= drizzleclient_fetch_row(result);
1841
row= drizzle_row_next(&result);
1830
1842
for (counter= 0; counter < primary_keys_number_of;
1831
counter++, row= drizzleclient_fetch_row(result))
1843
counter++, row= drizzle_row_next(&result))
1833
1845
primary_keys[counter]= strdup(row[0]);
1834
1846
if (primary_keys[counter] == NULL)
1865
create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
1877
create_schema(drizzle_con_st *con, const char *db, statement *stmt,
1866
1878
option_string *engine_stmt, stats *sptr)
1868
1880
char query[HUGE_STRING_LENGTH];
1880
1892
if (verbose >= 2)
1881
1893
printf("Loading Pre-data\n");
1883
if (run_query(drizzle, query, len))
1895
if (run_query(con, NULL, query, len))
1885
1897
fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1886
drizzleclient_error(drizzle));
1898
drizzle_con_error(con));
1912
drizzle_result_st result;
1913
drizzle_return_t ret;
1900
1915
if (verbose >= 3)
1901
1916
printf("%s;\n", query);
1903
if (drizzleclient_select_db(drizzle, db))
1918
if (drizzle_select_db(con, &result, db, &ret) == NULL ||
1919
ret != DRIZZLE_RETURN_OK)
1905
1921
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1906
drizzleclient_error(drizzle));
1922
ret == DRIZZLE_RETURN_ERROR_CODE ?
1923
drizzle_result_error(&result) : drizzle_con_error(con));
1926
drizzle_result_free(&result);
1909
1927
sptr->create_count++;
1914
1932
len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1915
1933
engine_stmt->string);
1916
if (run_query(drizzle, query, len))
1934
if (run_query(con, NULL, query, len))
1918
1936
fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1919
drizzleclient_error(drizzle));
1937
drizzle_con_error(con));
1922
1940
sptr->create_count++;
1938
1956
snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
1939
1957
engine_stmt->option);
1940
if (run_query(drizzle, buffer, strlen(buffer)))
1958
if (run_query(con, NULL, buffer, strlen(buffer)))
1942
1960
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1943
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1961
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1944
1962
if (!opt_ignore_sql_errors)
1951
if (run_query(drizzle, ptr->string, ptr->length))
1969
if (run_query(con, NULL, ptr->string, ptr->length))
1953
1971
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1954
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1972
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1955
1973
if (!opt_ignore_sql_errors)
1977
drop_schema(DRIZZLE *drizzle, const char *db)
1995
drop_schema(drizzle_con_st *con, const char *db)
1979
1997
char query[HUGE_STRING_LENGTH];
1982
2000
len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
1984
if (run_query(drizzle, query, len))
2002
if (run_query(con, NULL, query, len))
1986
2004
fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1987
my_progname, db, drizzleclient_error(drizzle));
2005
my_progname, db, drizzle_con_error(con));
1997
run_statements(DRIZZLE *drizzle, statement *stmt)
2015
run_statements(drizzle_con_st *con, statement *stmt)
1999
2017
statement *ptr;
2000
DRIZZLE_RES *result;
2003
2019
for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
2005
if (run_query(drizzle, ptr->string, ptr->length))
2021
if (run_query(con, NULL, ptr->string, ptr->length))
2007
2023
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2008
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
2024
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
2011
if (!opt_only_print)
2013
if (drizzleclient_field_count(drizzle))
2015
result= drizzleclient_store_result(drizzle);
2016
drizzleclient_free_result(result);
2172
2180
uint64_t counter= 0, queries;
2173
2181
uint64_t detach_counter;
2174
2182
unsigned int commit_counter;
2176
DRIZZLE_RES *result;
2184
drizzle_result_st result;
2178
2186
statement *ptr;
2179
thread_context *con= (thread_context *)p;
2187
thread_context *ctx= (thread_context *)p;
2181
2189
pthread_mutex_lock(&sleeper_mutex);
2182
2190
while (master_wakeup)
2194
2202
commit_counter= 0;
2195
2203
if (commit_rate)
2196
run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2204
run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2199
for (ptr= con->stmt, detach_counter= 0;
2207
for (ptr= ctx->stmt, detach_counter= 0;
2200
2208
ptr && ptr->length;
2201
2209
ptr= ptr->next, detach_counter++)
2203
2211
if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2205
slap_close(&drizzle);
2206
slap_connect(&drizzle, true);
2214
slap_connect(&con, true);
2235
2243
length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2236
2244
(int)ptr->length, ptr->string, key);
2238
if (run_query(&drizzle, buffer, length))
2246
if (run_query(&con, &result, buffer, length))
2240
2248
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2241
my_progname, (uint32_t)length, buffer, drizzleclient_error(&drizzle));
2249
my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
2248
if (run_query(&drizzle, ptr->string, ptr->length))
2256
if (run_query(&con, &result, ptr->string, ptr->length))
2250
2258
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2251
my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(&drizzle));
2259
my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
2256
2264
if (!opt_only_print)
2260
if (drizzleclient_field_count(&drizzle))
2262
result= drizzleclient_store_result(&drizzle);
2263
while ((row = drizzleclient_fetch_row(result)))
2265
drizzleclient_free_result(result);
2267
} while(drizzleclient_next_result(&drizzle) == 0);
2266
while ((row = drizzle_row_next(&result)))
2268
drizzle_result_free(&result);
2271
2272
if (commit_rate && (++commit_counter == commit_rate))
2273
2274
commit_counter= 0;
2274
run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2275
run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
2277
2278
/* If the timer is set, and the alarm is not active then end */
2281
2282
/* If limit has been reached, and we are not in a timer_alarm just end */
2282
if (con->limit && queries == con->limit && timer_alarm == false)
2283
if (ctx->limit && queries == ctx->limit && timer_alarm == false)
2286
2287
if (opt_timer_length && timer_alarm == true)
2287
2288
goto limit_not_met;
2289
if (con->limit && queries < con->limit)
2290
if (ctx->limit && queries < ctx->limit)
2290
2291
goto limit_not_met;
2294
2295
if (commit_rate)
2295
run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2296
run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
2297
slap_close(&drizzle);
2299
2300
pthread_mutex_lock(&counter_mutex);
2300
2301
thread_counter--;
2301
2302
pthread_cond_signal(&count_threshhold);
2302
2303
pthread_mutex_unlock(&counter_mutex);
2666
slap_close(DRIZZLE *drizzle)
2667
slap_close(drizzle_con_st *con)
2668
2669
if (opt_only_print)
2671
drizzleclient_close(drizzle);
2672
drizzle_free(drizzle_con_drizzle(con));
2675
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
2676
slap_connect(drizzle_con_st *con, bool connect_to_schema)
2677
2678
/* Connect to server */
2678
2679
static uint32_t connection_retry_sleep= 100000; /* Microseconds */
2679
2680
int x, connect_error= 1;
2681
drizzle_return_t ret;
2682
drizzle_st *drizzle;
2681
2684
if (opt_only_print)
2684
2687
if (opt_delayed_start)
2685
2688
usleep(random()%opt_delayed_start);
2687
drizzleclient_create(drizzle);
2690
drizzleclient_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
2690
if ((drizzle= drizzle_create(NULL)) == NULL ||
2691
drizzle_con_add_tcp(drizzle, con, host, opt_drizzle_port, user,
2693
connect_to_schema ? create_schema_string : NULL,
2694
DRIZZLE_CON_NONE) == NULL)
2696
fprintf(stderr,"%s: Error creating drizzle object\n", my_progname);
2692
2700
for (x= 0; x < 10; x++)
2696
if (drizzleclient_connect(drizzle, host, user, opt_password,
2697
connect_to_schema ? create_schema_string : NULL,
2699
opt_drizzle_unix_port,
2702
if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
2702
2704
/* Connect suceeded */
2703
2705
connect_error= 0;
2708
2710
if (connect_error)
2710
fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
2711
my_progname, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
2712
fprintf(stderr,"%s: Error when connecting to server: %d %s\n", my_progname,
2713
ret, drizzle_con_error(con));