Commit ab734759 authored by brian@zim.(none)'s avatar brian@zim.(none)

Added a test for pre-statement call, and fixed connection/deconnect code so...

Added a test for pre-statement call, and fixed connection/deconnect code so that the rest of bbench can be ran by others. 
parent e6a478de
...@@ -73,6 +73,10 @@ enum options_client ...@@ -73,6 +73,10 @@ enum options_client
OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM, OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
OPT_SLAP_PRE_QUERY, OPT_SLAP_PRE_QUERY,
OPT_SLAP_POST_QUERY, OPT_SLAP_POST_QUERY,
OPT_SLAP_PRE_SYSTEM,
OPT_SLAP_POST_SYSTEM,
OPT_SLAP_COMMIT,
OPT_SLAP_DETACH,
OPT_MYSQL_REPLACE_INTO, OPT_BASE64_OUTPUT, OPT_SERVER_ID, OPT_MYSQL_REPLACE_INTO, OPT_BASE64_OUTPUT, OPT_SERVER_ID,
OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT, OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT,
OPT_DEBUG_INFO, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE, OPT_WRITE_BINLOG, OPT_DEBUG_INFO, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE, OPT_WRITE_BINLOG,
......
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
#define UPDATE_TYPE_REQUIRES_PREFIX 3 #define UPDATE_TYPE_REQUIRES_PREFIX 3
#define CREATE_TABLE_TYPE 4 #define CREATE_TABLE_TYPE 4
#define SELECT_TYPE_REQUIRES_PREFIX 5 #define SELECT_TYPE_REQUIRES_PREFIX 5
#define DELETE_TYPE_REQUIRES_PREFIX 6
#include "client_priv.h" #include "client_priv.h"
#include <mysqld_error.h> #include <mysqld_error.h>
...@@ -122,6 +123,8 @@ static char *host= NULL, *opt_password= NULL, *user= NULL, ...@@ -122,6 +123,8 @@ static char *host= NULL, *opt_password= NULL, *user= NULL,
*user_supplied_pre_statements= NULL, *user_supplied_pre_statements= NULL,
*user_supplied_post_statements= NULL, *user_supplied_post_statements= NULL,
*default_engine= NULL, *default_engine= NULL,
*pre_system= NULL,
*post_system= NULL,
*opt_mysql_unix_port= NULL; *opt_mysql_unix_port= NULL;
const char *delimiter= "\n"; const char *delimiter= "\n";
...@@ -142,6 +145,8 @@ const char *auto_generate_sql_type= "mixed"; ...@@ -142,6 +145,8 @@ const char *auto_generate_sql_type= "mixed";
static unsigned long connect_flags= CLIENT_MULTI_RESULTS; static unsigned long connect_flags= CLIENT_MULTI_RESULTS;
static int verbose, delimiter_length; static int verbose, delimiter_length;
static uint commit_rate;
static uint detach_rate;
const char *num_int_cols_opt; const char *num_int_cols_opt;
const char *num_char_cols_opt; const char *num_char_cols_opt;
/* Yes, we do set defaults here */ /* Yes, we do set defaults here */
...@@ -254,6 +259,8 @@ void statement_cleanup(statement *stmt); ...@@ -254,6 +259,8 @@ void statement_cleanup(statement *stmt);
void option_cleanup(option_string *stmt); void option_cleanup(option_string *stmt);
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr); void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr);
static int run_statements(MYSQL *mysql, statement *stmt); static int run_statements(MYSQL *mysql, statement *stmt);
int slap_connect(MYSQL *mysql);
static int run_query(MYSQL *mysql, const char *query, int len);
static const char ALPHANUMERICS[]= static const char ALPHANUMERICS[]=
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz"; "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
...@@ -451,6 +458,16 @@ void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr) ...@@ -451,6 +458,16 @@ void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr)
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary) if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
generate_primary_key_list(mysql, eptr); generate_primary_key_list(mysql, eptr);
if (commit_rate)
run_query(mysql, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
if (pre_system)
system(pre_system);
/*
Pre statements are always run after all other logic so they can
correct/adjust any item that they want.
*/
if (pre_statements) if (pre_statements)
run_statements(mysql, pre_statements); run_statements(mysql, pre_statements);
...@@ -459,6 +476,9 @@ void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr) ...@@ -459,6 +476,9 @@ void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr)
if (post_statements) if (post_statements)
run_statements(mysql, post_statements); run_statements(mysql, post_statements);
if (post_system)
system(post_system);
/* We are finished with this run */ /* We are finished with this run */
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary) if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
drop_primary_key_list(); drop_primary_key_list();
...@@ -527,6 +547,9 @@ static struct my_option my_long_options[] = ...@@ -527,6 +547,9 @@ static struct my_option my_long_options[] =
"Number of rows to insert to used in read and write loads (default is 100).\n", "Number of rows to insert to used in read and write loads (default is 100).\n",
(uchar**) &auto_generate_sql_number, (uchar**) &auto_generate_sql_number, (uchar**) &auto_generate_sql_number, (uchar**) &auto_generate_sql_number,
0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0}, 0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
{"commit", OPT_SLAP_COMMIT, "Commit records after X number of statements.",
(uchar**) &commit_rate, (uchar**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
{"compress", 'C', "Use compression in server/client protocol.", {"compress", 'C', "Use compression in server/client protocol.",
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0}, 0, 0, 0},
...@@ -550,6 +573,9 @@ static struct my_option my_long_options[] = ...@@ -550,6 +573,9 @@ static struct my_option my_long_options[] =
"Delimiter to use in SQL statements supplied in file or command line.", "Delimiter to use in SQL statements supplied in file or command line.",
(uchar**) &delimiter, (uchar**) &delimiter, 0, GET_STR, REQUIRED_ARG, (uchar**) &delimiter, (uchar**) &delimiter, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, 0, 0},
{"detach", OPT_SLAP_DETACH, "Detach connections after X number of requests.",
(uchar**) &detach_rate, (uchar**) &detach_rate, 0, GET_UINT, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
{"engine", 'e', "Storage engine to use for creating the table.", {"engine", 'e', "Storage engine to use for creating the table.",
(uchar**) &default_engine, (uchar**) &default_engine, 0, (uchar**) &default_engine, (uchar**) &default_engine, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
...@@ -589,11 +615,21 @@ static struct my_option my_long_options[] = ...@@ -589,11 +615,21 @@ static struct my_option my_long_options[] =
(uchar**) &user_supplied_post_statements, (uchar**) &user_supplied_post_statements,
(uchar**) &user_supplied_post_statements, (uchar**) &user_supplied_post_statements,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"post-system", OPT_SLAP_POST_SYSTEM,
"System() string to run after the load has completed.",
(uchar**) &post_system,
(uchar**) &post_system,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"pre-query", OPT_SLAP_PRE_QUERY, {"pre-query", OPT_SLAP_PRE_QUERY,
"Query to run or file containing query to run before executing.", "Query to run or file containing query to run before executing.",
(uchar**) &user_supplied_pre_statements, (uchar**) &user_supplied_pre_statements,
(uchar**) &user_supplied_pre_statements, (uchar**) &user_supplied_pre_statements,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"pre-system", OPT_SLAP_PRE_SYSTEM,
"System() string to before load has completed.",
(uchar**) &pre_system,
(uchar**) &pre_system,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"preserve-schema", OPT_MYSQL_PRESERVE_SCHEMA, {"preserve-schema", OPT_MYSQL_PRESERVE_SCHEMA,
"Preserve the schema from the mysqlslap run, this happens unless " "Preserve the schema from the mysqlslap run, this happens unless "
"--auto-generate-sql or --create are used.", "--auto-generate-sql or --create are used.",
...@@ -1715,6 +1751,7 @@ run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit) ...@@ -1715,6 +1751,7 @@ run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit)
pthread_handler_t run_task(void *p) pthread_handler_t run_task(void *p)
{ {
ulonglong counter= 0, queries; ulonglong counter= 0, queries;
ulonglong trans_counter;
MYSQL *mysql; MYSQL *mysql;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
...@@ -1749,38 +1786,28 @@ pthread_handler_t run_task(void *p) ...@@ -1749,38 +1786,28 @@ pthread_handler_t run_task(void *p)
if (!opt_only_print) if (!opt_only_print)
{ {
/* Connect to server */ if (slap_connect(mysql))
static ulong connection_retry_sleep= 100000; /* Microseconds */
int i, connect_error= 1;
for (i= 0; i < 10; i++)
{
if (mysql_real_connect(mysql, host, user, opt_password,
create_schema_string,
opt_mysql_port,
opt_mysql_unix_port,
connect_flags))
{
/* Connect suceeded */
connect_error= 0;
break;
}
my_sleep(connection_retry_sleep);
}
if (connect_error)
{
fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
my_progname, mysql_errno(mysql), mysql_error(mysql));
goto end; goto end;
}
} }
DBUG_PRINT("info", ("connected.")); DBUG_PRINT("info", ("connected."));
if (verbose >= 3) if (verbose >= 3)
printf("connected!\n"); printf("connected!\n");
queries= 0; queries= 0;
limit_not_met: limit_not_met:
for (ptr= con->stmt; ptr && ptr->length; ptr= ptr->next) for (ptr= con->stmt, trans_counter= 0;
ptr && ptr->length;
ptr= ptr->next, trans_counter++)
{ {
if (!opt_only_print && detach_rate && !(trans_counter % detach_rate))
{
mysql_close(mysql);
if (slap_connect(mysql))
goto end;
}
/* /*
We have to execute differently based on query type. This should become a function. We have to execute differently based on query type. This should become a function.
*/ */
...@@ -1837,6 +1864,9 @@ pthread_handler_t run_task(void *p) ...@@ -1837,6 +1864,9 @@ pthread_handler_t run_task(void *p)
} }
queries++; queries++;
if (commit_rate && commit_rate <= trans_counter)
run_query(mysql, "COMMIT", strlen("COMMIT"));
if (con->limit && queries == con->limit) if (con->limit && queries == con->limit)
goto end; goto end;
} }
...@@ -1845,6 +1875,8 @@ pthread_handler_t run_task(void *p) ...@@ -1845,6 +1875,8 @@ pthread_handler_t run_task(void *p)
goto limit_not_met; goto limit_not_met;
end: end:
if (commit_rate)
run_query(mysql, "COMMIT", strlen("COMMIT"));
if (!opt_only_print) if (!opt_only_print)
mysql_close(mysql); mysql_close(mysql);
...@@ -2104,3 +2136,34 @@ statement_cleanup(statement *stmt) ...@@ -2104,3 +2136,34 @@ statement_cleanup(statement *stmt)
my_free(ptr, MYF(0)); my_free(ptr, MYF(0));
} }
} }
int
slap_connect(MYSQL *mysql)
{
/* Connect to server */
static ulong connection_retry_sleep= 100000; /* Microseconds */
int x, connect_error= 1;
for (x= 0; x < 10; x++)
{
if (mysql_real_connect(mysql, host, user, opt_password,
create_schema_string,
opt_mysql_port,
opt_mysql_unix_port,
connect_flags))
{
/* Connect suceeded */
connect_error= 0;
break;
}
my_sleep(connection_retry_sleep);
}
if (connect_error)
{
fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
my_progname, mysql_errno(mysql), mysql_error(mysql));
return 1;
}
return 0;
}
...@@ -167,3 +167,47 @@ SHOW TABLES; ...@@ -167,3 +167,47 @@ SHOW TABLES;
select * from t1; select * from t1;
SHOW TABLES; SHOW TABLES;
DROP SCHEMA IF EXISTS `mysqlslap`; DROP SCHEMA IF EXISTS `mysqlslap`;
DROP SCHEMA IF EXISTS `mysqlslap`;
CREATE SCHEMA `mysqlslap`;
use mysqlslap;
set storage_engine=`heap`;
CREATE TABLE t1 (id int, name varchar(64));
create table t2(foo1 varchar(32), foo2 varchar(32));
INSERT INTO t1 VALUES (1, 'This is a test');
insert into t2 values ('test', 'test2');
SET AUTOCOMMIT=0;
SHOW TABLES;
select * from t1;
select * from t2;
COMMIT;
select * from t1;
select * from t2;
COMMIT;
select * from t1;
select * from t2;
COMMIT;
COMMIT;
SHOW TABLES;
DROP SCHEMA IF EXISTS `mysqlslap`;
DROP SCHEMA IF EXISTS `mysqlslap`;
CREATE SCHEMA `mysqlslap`;
use mysqlslap;
set storage_engine=`myisam`;
CREATE TABLE t1 (id int, name varchar(64));
create table t2(foo1 varchar(32), foo2 varchar(32));
INSERT INTO t1 VALUES (1, 'This is a test');
insert into t2 values ('test', 'test2');
SET AUTOCOMMIT=0;
SHOW TABLES;
select * from t1;
select * from t2;
COMMIT;
select * from t1;
select * from t2;
COMMIT;
select * from t1;
select * from t2;
COMMIT;
COMMIT;
SHOW TABLES;
DROP SCHEMA IF EXISTS `mysqlslap`;
...@@ -36,3 +36,5 @@ ...@@ -36,3 +36,5 @@
--exec $MYSQL_SLAP --silent --concurrency=5 --iterations=1 --number-int-cols=2 --number-char-cols=3 --auto-generate-sql --auto-generate-sql-guid-primary --auto-generate-sql-load-type=key --auto-generate-sql-execute-number=5 --auto-generate-sql-secondary-indexes=3 --exec $MYSQL_SLAP --silent --concurrency=5 --iterations=1 --number-int-cols=2 --number-char-cols=3 --auto-generate-sql --auto-generate-sql-guid-primary --auto-generate-sql-load-type=key --auto-generate-sql-execute-number=5 --auto-generate-sql-secondary-indexes=3
--exec $MYSQL_SLAP --only-print --delimiter=";" --query="select * from t1;select * from t2" --create="CREATE TABLE t1 (id int, name varchar(64)); create table t2(foo1 varchar(32), foo2 varchar(32)); INSERT INTO t1 VALUES (1, 'This is a test'); insert into t2 values ('test', 'test2')" --engine="heap,myisam" --post-query="SHOW TABLES" --pre-query="SHOW TABLES"; --exec $MYSQL_SLAP --only-print --delimiter=";" --query="select * from t1;select * from t2" --create="CREATE TABLE t1 (id int, name varchar(64)); create table t2(foo1 varchar(32), foo2 varchar(32)); INSERT INTO t1 VALUES (1, 'This is a test'); insert into t2 values ('test', 'test2')" --engine="heap,myisam" --post-query="SHOW TABLES" --pre-query="SHOW TABLES";
--exec $MYSQL_SLAP --only-print --delimiter=";" --query="select * from t1;select * from t2" --create="CREATE TABLE t1 (id int, name varchar(64)); create table t2(foo1 varchar(32), foo2 varchar(32)); INSERT INTO t1 VALUES (1, 'This is a test'); insert into t2 values ('test', 'test2')" --engine="heap,myisam" --post-query="SHOW TABLES" --pre-query="SHOW TABLES" --number-of-queries=6 --commit=1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment