OLTP scripts: add --reconnect option.

oltp_*.lua scripts now support the --reconnect=N option. When specified,
sysbench will reconnect after every N events.

Fixes GH-90.
This commit is contained in:
Alexey Kopytov
2018-12-11 23:22:56 +03:00
parent 8c8122080c
commit a245b2f531
23 changed files with 80 additions and 2 deletions

View File

@ -116,6 +116,7 @@ static int pgsql_drv_init(void);
static int pgsql_drv_describe(drv_caps_t *);
static int pgsql_drv_connect(db_conn_t *);
static int pgsql_drv_disconnect(db_conn_t *);
static int pgsql_drv_reconnect(db_conn_t *);
static int pgsql_drv_prepare(db_stmt_t *, const char *, size_t);
static int pgsql_drv_bind_param(db_stmt_t *, db_bind_t *, size_t);
static int pgsql_drv_bind_result(db_stmt_t *, db_bind_t *, size_t);
@ -141,6 +142,7 @@ static db_driver_t pgsql_driver =
.describe = pgsql_drv_describe,
.connect = pgsql_drv_connect,
.disconnect = pgsql_drv_disconnect,
.reconnect = pgsql_drv_reconnect,
.prepare = pgsql_drv_prepare,
.bind_param = pgsql_drv_bind_param,
.bind_result = pgsql_drv_bind_result,
@ -273,6 +275,22 @@ int pgsql_drv_disconnect(db_conn_t *sb_conn)
return 0;
}
/* Disconnect from database */
int pgsql_drv_reconnect(db_conn_t *sb_conn)
{
if (pgsql_drv_disconnect(sb_conn))
return DB_ERROR_FATAL;
while (pgsql_drv_connect(sb_conn))
{
if (sb_globals.error)
return DB_ERROR_FATAL;
}
return DB_ERROR_IGNORABLE;
}
/* Prepare statement */

View File

@ -68,6 +68,9 @@ sysbench.cmdline.options = {
{"Use a secondary index in place of the PRIMARY KEY", false},
create_secondary =
{"Create a secondary index in addition to the PRIMARY KEY", true},
reconnect =
{"Reconnect after every N events. The default (0) is to not reconnect",
0},
mysql_storage_engine =
{"Storage engine, if MySQL is used", "innodb"},
pgsql_variant =
@ -505,3 +508,14 @@ function sysbench.hooks.before_restart_event(errdesc)
prepare_statements()
end
end
function check_reconnect()
if sysbench.opt.reconnect > 0 then
transactions = (transactions or 0) + 1
if transactions % sysbench.opt.reconnect == 0 then
close_statements()
con:reconnect()
prepare_statements()
end
end
end

View File

@ -31,4 +31,6 @@ function event()
param[tnum].deletes[1]:set(id)
stmt[tnum].deletes:execute()
check_reconnect()
end

View File

@ -62,4 +62,6 @@ function event()
"(%d, %d, '%s', '%s')",
table_name, i, k_val, c_val, pad_val))
end
check_reconnect()
end

View File

@ -31,4 +31,6 @@ end
function event()
execute_point_selects()
check_reconnect()
end

View File

@ -54,4 +54,6 @@ function event()
if not sysbench.opt.skip_trx then
commit()
end
check_reconnect()
end

View File

@ -62,4 +62,6 @@ function event()
if not sysbench.opt.skip_trx then
commit()
end
check_reconnect()
end

View File

@ -27,4 +27,5 @@ end
function event()
execute_index_updates(con)
check_reconnect()
end

View File

@ -27,4 +27,6 @@ end
function event()
execute_non_index_updates()
check_reconnect()
end

View File

@ -44,4 +44,6 @@ function event()
if not sysbench.opt.skip_trx then
commit()
end
check_reconnect()
end

View File

@ -69,4 +69,6 @@ function event()
end
stmt:execute()
check_reconnect()
end

View File

@ -74,4 +74,6 @@ function event()
end
stmt:execute()
check_reconnect()
end

View File

@ -84,3 +84,12 @@ ARGS="$ARGS --auto-inc=off --verbosity=1"
sysbench $ARGS prepare
sysbench $ARGS run
sysbench $ARGS cleanup
echo "# Test --reconnect"
ARGS="${OLTP_SCRIPT_PATH} ${DB_DRIVER_ARGS} ${SB_EXTRA_ARGS} --events=100 \
--reconnect=5"
sysbench $ARGS prepare >/dev/null || true
sysbench $ARGS run | grep reconnects:
sysbench $ARGS cleanup >/dev/null || true

View File

@ -66,10 +66,9 @@ SQL Lua API + PostgreSQL tests
301 400 0123456789 0123456789
--
1
ALERT: reconnect is not supported by the current driver
2
--
reconnects = 0
reconnects = 1
FATAL: Connection to database failed: could not translate host name "non-existing" to address: * (glob)
connection creation failed

View File

@ -281,3 +281,5 @@ oltp_delete.lua + MySQL tests
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)

View File

@ -308,3 +308,5 @@ oltp_delete.lua + PostgreSQL tests
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)

View File

@ -19,6 +19,7 @@ OLTP usage information test
--point_selects=N Number of point SELECT queries per transaction [10]
--range_selects[=on|off] Enable/disable all range SELECT queries [on]
--range_size=N Range size for range SELECT queries [100]
--reconnect=N Reconnect after every N events. The default (0) is to not reconnect [0]
--secondary[=on|off] Use a secondary index in place of the PRIMARY KEY [off]
--simple_ranges=N Number of simple range SELECT queries per transaction [1]
--skip_trx[=on|off] Don't start explicit transactions and execute all queries in the AUTOCOMMIT mode [off]

View File

@ -280,3 +280,5 @@ oltp_insert.lua + MySQL tests
Creating table 'sbtest1'...
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)

View File

@ -307,3 +307,5 @@ oltp_insert.lua + PostgreSQL tests
Creating table 'sbtest1'...
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)

View File

@ -281,3 +281,5 @@ oltp_point_select.lua + MySQL tests
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)

View File

@ -308,3 +308,5 @@ oltp_point_select.lua + PostgreSQL tests
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)

View File

@ -285,6 +285,8 @@ oltp_read_write.lua + MySQL tests
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)
$ DB_DRIVER_ARGS="--db-driver=mysql --mysql-storage-engine=innodb $SBTEST_MYSQL_ARGS"
@ -565,3 +567,5 @@ oltp_read_write.lua + MySQL tests
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)

View File

@ -311,3 +311,5 @@ oltp_read_write.lua + PostgreSQL tests
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Dropping table 'sbtest1'...
# Test --reconnect
reconnects: 20 (* per sec.) (glob)