Remove legacy (0.5) API.

This commit is contained in:
Alexey Kopytov
2018-01-07 14:08:27 +03:00
parent 02d1fbade5
commit edb40e012a
29 changed files with 21 additions and 1964 deletions

View File

@ -50,7 +50,7 @@ sb_ck_pr.h \
sb_lua.h sb_util.h sb_util.c sb_counter.h sb_counter.c \
lua/internal/sysbench.lua.h lua/internal/sysbench.sql.lua.h \
lua/internal/sysbench.rand.lua.h lua/internal/sysbench.cmdline.lua.h \
lua/internal/sysbench.compat.lua.h lua/internal/sysbench.histogram.lua.h \
lua/internal/sysbench.histogram.lua.h \
xoroshiro128plus.h
sysbench_LDADD = tests/fileio/libsbfileio.a tests/threads/libsbthreads.a \

View File

@ -30,7 +30,7 @@ end
function event()
if (cursize == 0) then
con:bulk_insert_init("INSERT INTO sbtest" .. thread_id+1 .. " VALUES")
con:bulk_insert_init("INSERT INTO sbtest" .. sysbench.tid+1 .. " VALUES")
end
cursize = cursize + 1
@ -38,7 +38,7 @@ function event()
con:bulk_insert_next("(" .. cursize .. "," .. cursize .. ")")
end
function thread_done(thread_9d)
function thread_done()
con:bulk_insert_done()
con:disconnect()
end

View File

@ -15,7 +15,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
BUILT_SOURCES = sysbench.lua.h sysbench.rand.lua.h sysbench.sql.lua.h \
sysbench.compat.lua.h sysbench.cmdline.lua.h \
sysbench.cmdline.lua.h \
sysbench.histogram.lua.h
CLEANFILES = $(BUILT_SOURCES)

View File

@ -1,75 +0,0 @@
-- Copyright (C) 2016-2017 Alexey Kopytov <akopytov@gmail.com>
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-- ----------------------------------------------------------------------
-- Compatibility wrappers/aliases. These may be removed in later versions
-- ----------------------------------------------------------------------
thread_id = sysbench.tid
test = sysbench.cmdline.script_path
function sb_rnd()
-- Keep lower 32 bits from sysbench.rand.uniform_uint64() and convert them to
-- a Lua number
return tonumber(sysbench.rand.uniform_uint64() % 4294967296)
end
sb_rand = sysbench.rand.default
sb_rand_str = sysbench.rand.string
sb_rand_uniform = sysbench.rand.uniform
sb_rand_gaussian = sysbench.rand.gaussian
sb_rand_special = sysbench.rand.special
function sb_rand_uniq(a, b)
local res
if type(a) == "nil" then
a = 0
end
if type(b) == "nil" then
b = 4294967295
end
repeat
res = sysbench.rand.unique()
until res >= a and res <= b
return res
end
db_connect = sysbench.db.connect
db_disconnect = sysbench.db.disconnect
db_query = sysbench.db.query
db_bulk_insert_init = sysbench.db.bulk_insert_init
db_bulk_insert_next = sysbench.db.bulk_insert_next
db_bulk_insert_done = sysbench.db.bulk_insert_done
db_prepare = sysbench.db.prepare
db_bind_param = sysbench.db.bind_param
db_bind_result = sysbench.db.bind_result
db_execute = sysbench.db.execute
db_store_results = sysbench.db.store_results
db_free_results = sysbench.db.free_results
db_close = sysbench.db.close
DB_ERROR_NONE = sysbench.db.DB_ERROR_NONE
DB_ERROR_RESTART_TRANSACTION = sysbench.db.DB_ERROR_RESTART_TRANSACTION
DB_ERROR_FAILED = sysbench.db.DB_ERROR_FAILED
mysql_table_engine = mysql_table_engine or "innodb"
myisam_max_rows = 1000000

View File

@ -221,12 +221,13 @@ CREATE TABLE sbtest%d(
if (sysbench.opt.auto_inc) then
query = string.format("(%d, '%s', '%s')",
sb_rand(1, sysbench.opt.table_size), c_val,
pad_val)
sysbench.rand.default(1, sysbench.opt.table_size),
c_val, pad_val)
else
query = string.format("(%d, %d, '%s', '%s')",
i, sb_rand(1, sysbench.opt.table_size), c_val,
pad_val)
i,
sysbench.rand.default(1, sysbench.opt.table_size),
c_val, pad_val)
end
con:bulk_insert_next(query)

View File

@ -65,7 +65,7 @@ function event()
for i = 1, sysbench.opt.random_points do
local rmin = rlen * thread_id
local rmax = rmin + rlen
params[i]:set(sb_rand(rmin, rmax))
params[i]:set(sysbench.rand.default(rmin, rmax))
end
stmt:execute()

View File

@ -68,7 +68,7 @@ function event()
for i = 1, sysbench.opt.number_of_ranges*2, 2 do
local rmin = rlen * thread_id
local rmax = rmin + rlen
local val = sb_rand(rmin, rmax)
local val = sysbench.rand.default(rmin, rmax)
params[i]:set(val)
params[i+1]:set(val + sysbench.opt.delta)
end

View File

@ -45,7 +45,6 @@
*/
#include "lua/internal/sysbench.lua.h"
#include "lua/internal/sysbench.cmdline.lua.h"
#include "lua/internal/sysbench.compat.lua.h"
#include "lua/internal/sysbench.rand.lua.h"
#include "lua/internal/sysbench.sql.lua.h"
#include "lua/internal/sysbench.histogram.lua.h"
@ -80,21 +79,6 @@ typedef struct {
char is_null;
} sb_lua_bind_t;
typedef struct {
db_result_t *ptr;
} sb_lua_db_rs_t;
typedef struct {
db_stmt_t *ptr;
sb_lua_bind_t *params;
unsigned int nparams;
sb_lua_bind_t *results;
unsigned int nresults;
int param_ref;
int result_ref;
sb_lua_db_rs_t *rs;
} sb_lua_db_stmt_t;
typedef struct {
const char *name;
const unsigned char *source;
@ -122,7 +106,6 @@ static TLS sb_lua_ctxt_t tls_lua_ctxt CK_CC_CACHELINE;
static internal_script_t internal_scripts[] = {
{"sysbench.rand.lua", sysbench_rand_lua, &sysbench_rand_lua_len},
{"sysbench.lua", sysbench_lua, &sysbench_lua_len},
{"sysbench.compat.lua", sysbench_compat_lua, &sysbench_compat_lua_len},
{"sysbench.cmdline.lua", sysbench_cmdline_lua, &sysbench_cmdline_lua_len},
{"sysbench.sql.lua", sysbench_sql_lua, &sysbench_sql_lua_len},
{"sysbench.histogram.lua", sysbench_histogram_lua,
@ -164,23 +147,6 @@ static lua_State *sb_lua_new_state(void);
/* Close interpretet state */
static int sb_lua_close_state(lua_State *);
/* Exported C functions for legacy Lua API */
static int sb_lua_db_connect(lua_State *);
static int sb_lua_db_disconnect(lua_State *);
static int sb_lua_db_query(lua_State *);
static int sb_lua_db_bulk_insert_init(lua_State *);
static int sb_lua_db_bulk_insert_next(lua_State *);
static int sb_lua_db_bulk_insert_done(lua_State *);
static int sb_lua_db_prepare(lua_State *);
static int sb_lua_db_bind_param(lua_State *);
static int sb_lua_db_bind_result(lua_State *);
static int sb_lua_db_execute(lua_State *);
static int sb_lua_db_close(lua_State *);
static int sb_lua_db_store_results(lua_State *);
static int sb_lua_db_free_results(lua_State *);
static unsigned int sb_lua_table_size(lua_State *, int);
static int read_cmdline_options(lua_State *L);
static bool sb_lua_hook_defined(lua_State *, const char *);
static bool sb_lua_hook_push(lua_State *, const char *);
@ -204,12 +170,6 @@ static void report_error(lua_State *L)
lua_pop(L, 1);
}
static void check_connection(lua_State *L, sb_lua_ctxt_t *ctxt)
{
if (ctxt->con == NULL)
luaL_error(L, "Uninitialized database connection");
}
static bool func_available(lua_State *L, const char *func)
{
lua_getglobal(L, func);
@ -314,9 +274,7 @@ static int do_export_options(lua_State *L, bool global)
}
/*
Export option values to the 'sysbench.opt' table. If the script does not
declare supported options with sysbench.cmdline.options also export to the
global namespace for compatibility with the legacy API.
Export option values to the 'sysbench.opt' table.
*/
static int export_options(lua_State *L)
@ -324,9 +282,6 @@ static int export_options(lua_State *L)
if (do_export_options(L, false))
return 1;
if (sbtest.args == NULL && do_export_options(L, true))
return 1;
return 0;
}
@ -552,13 +507,6 @@ static void sb_lua_var_number(lua_State *L, const char *name, lua_Number n)
lua_settable(L, -3);
}
static void sb_lua_var_func(lua_State *L, const char *name, lua_CFunction f)
{
lua_pushstring(L, name);
lua_pushcfunction(L, f);
lua_settable(L, -3);
}
static void sb_lua_var_string(lua_State *L, const char *name, const char *s)
{
lua_pushstring(L, name);
@ -717,31 +665,6 @@ static lua_State *sb_lua_new_state(void)
/* sysbench.tid */
sb_lua_var_number(L, "tid", sb_tls_thread_id);
/* Export functions into per-state 'sysbench.db' table */
lua_pushliteral(L, "db");
lua_newtable(L);
sb_lua_var_func(L, "connect", sb_lua_db_connect);
sb_lua_var_func(L, "disconnect", sb_lua_db_disconnect);
sb_lua_var_func(L, "query", sb_lua_db_query);
sb_lua_var_func(L, "bulk_insert_init", sb_lua_db_bulk_insert_init);
sb_lua_var_func(L, "bulk_insert_next", sb_lua_db_bulk_insert_next);
sb_lua_var_func(L, "bulk_insert_done", sb_lua_db_bulk_insert_done);
sb_lua_var_func(L, "prepare", sb_lua_db_prepare);
sb_lua_var_func(L, "bind_param", sb_lua_db_bind_param);
sb_lua_var_func(L, "bind_result", sb_lua_db_bind_result);
sb_lua_var_func(L, "execute", sb_lua_db_execute);
sb_lua_var_func(L, "close", sb_lua_db_close);
sb_lua_var_func(L, "store_results", sb_lua_db_store_results);
sb_lua_var_func(L, "free_results", sb_lua_db_free_results);
sb_lua_var_number(L, "DB_ERROR_NONE", DB_ERROR_NONE);
sb_lua_var_number(L, "DB_ERROR_RESTART_TRANSACTION", DB_ERROR_IGNORABLE);
sb_lua_var_number(L, "DB_ERROR_FAILED", DB_ERROR_FATAL);
lua_settable(L, -3); /* sysbench.db */
lua_pushliteral(L, "error");
lua_newtable(L);
@ -837,17 +760,7 @@ int sb_lua_close_state(lua_State *state)
lua_close(state);
if (ctxt != NULL)
{
sb_lua_db_disconnect(state);
if (ctxt->driver != NULL)
{
db_destroy(ctxt->driver);
ctxt->driver = NULL;
}
}
ctxt->L = NULL;
ctxt->L = NULL;
return 0;
}
@ -892,473 +805,6 @@ int sb_lua_cmd_help(void)
return execute_command(HELP_FUNC);
}
int sb_lua_db_connect(lua_State *L)
{
sb_lua_ctxt_t * const ctxt = &tls_lua_ctxt;
ctxt->driver = db_create(NULL);
if (ctxt->driver == NULL)
{
luaL_error(L, "DB initialization failed");
}
lua_pushstring(L, ctxt->driver->sname);
lua_setglobal(L, "db_driver");
if (ctxt->con != NULL)
return 0;
ctxt->con = db_connection_create(ctxt->driver);
if (ctxt->con == NULL)
luaL_error(L, "Failed to connect to the database");
return 0;
}
int sb_lua_db_disconnect(lua_State *L)
{
(void) L; /* unused */
if (tls_lua_ctxt.con)
{
db_connection_close(tls_lua_ctxt.con);
db_connection_free(tls_lua_ctxt.con);
tls_lua_ctxt.con = NULL;
}
return 0;
}
/*
Throw an error with the { errcode = RESTART_EVENT } table. This will make
thread_run() restart the event.
*/
static void throw_restart_event(lua_State *L)
{
log_text(LOG_DEBUG, "Ignored error encountered, restarting transaction");
lua_createtable(L, 0, 1);
lua_pushliteral(L, "errcode");
lua_pushnumber(L, SB_LUA_ERROR_RESTART_EVENT);
lua_settable(L, -3);
lua_error(L); /* this call never returns */
}
int sb_lua_db_query(lua_State *L)
{
const char *query;
db_result_t *rs;
size_t len;
if (tls_lua_ctxt.con == NULL)
sb_lua_db_connect(L);
db_conn_t * const con = tls_lua_ctxt.con;
query = luaL_checklstring(L, 1, &len);
rs = db_query(con, query, len);
if (rs == NULL)
{
if (con->error == DB_ERROR_IGNORABLE)
throw_restart_event(L);
else if (con->error == DB_ERROR_FATAL)
luaL_error(L, "db_query() failed");
}
if (rs != NULL)
db_free_results(rs);
return 0;
}
int sb_lua_db_bulk_insert_init(lua_State *L)
{
const char *query;
size_t len;
if (tls_lua_ctxt.con == NULL)
sb_lua_db_connect(L);
query = luaL_checklstring(L, 1, &len);
if (db_bulk_insert_init(tls_lua_ctxt.con, query, len))
luaL_error(L, "db_bulk_insert_init() failed");
return 0;
}
int sb_lua_db_bulk_insert_next(lua_State *L)
{
const char *query;
size_t len;
check_connection(L, &tls_lua_ctxt);
query = luaL_checklstring(L, 1, &len);
if (db_bulk_insert_next(tls_lua_ctxt.con, query, len))
luaL_error(L, "db_bulk_insert_next() failed");
return 0;
}
int sb_lua_db_bulk_insert_done(lua_State *L)
{
check_connection(L, &tls_lua_ctxt);
db_bulk_insert_done(tls_lua_ctxt.con);
return 0;
}
int sb_lua_db_prepare(lua_State *L)
{
sb_lua_db_stmt_t *stmt;
const char *query;
size_t len;
if (tls_lua_ctxt.con == NULL)
sb_lua_db_connect(L);
query = luaL_checklstring(L, 1, &len);
stmt = (sb_lua_db_stmt_t *)lua_newuserdata(L, sizeof(sb_lua_db_stmt_t));
luaL_getmetatable(L, "sysbench.stmt");
lua_setmetatable(L, -2);
memset(stmt, 0, sizeof(sb_lua_db_stmt_t));
stmt->ptr = db_prepare(tls_lua_ctxt.con, query, len);
if (stmt->ptr == NULL)
luaL_error(L, "db_prepare() failed");
stmt->param_ref = LUA_REFNIL;
return 1;
}
int sb_lua_db_bind_param(lua_State *L)
{
sb_lua_db_stmt_t *stmt;
unsigned int i, n;
db_bind_t *binds;
char needs_rebind = 0;
check_connection(L, &tls_lua_ctxt);
stmt = (sb_lua_db_stmt_t *)luaL_checkudata(L, 1, "sysbench.stmt");
luaL_argcheck(L, stmt != NULL, 1, "prepared statement expected");
if (!lua_istable(L, 2))
luaL_error(L, "table was expected");
/* Get table size */
n = sb_lua_table_size(L, 2);
if (!n)
luaL_error(L, "table is empty");
binds = (db_bind_t *)calloc(n, sizeof(db_bind_t));
stmt->params = (sb_lua_bind_t *)calloc(n, sizeof(sb_lua_bind_t));
if (binds == NULL || stmt->params == NULL)
luaL_error(L, "memory allocation failure");
lua_pushnil(L);
for (i = 0; i < n; i++)
{
lua_next(L, 2);
switch(lua_type(L, -1))
{
case LUA_TNUMBER:
stmt->params[i].buf = malloc(sizeof(int));
stmt->params[i].id = luaL_checknumber(L, -2);
binds[i].type = DB_TYPE_INT;
binds[i].buffer = stmt->params[i].buf;
break;
case LUA_TSTRING:
stmt->params[i].id = luaL_checknumber(L, -2);
stmt->params[i].buflen = 0;
binds[i].type = DB_TYPE_CHAR;
needs_rebind = 1;
break;
default:
lua_pushfstring(L, "Unsupported variable type: %s",
lua_typename(L, lua_type(L, -1)));
goto error;
}
binds[i].is_null = &stmt->params[i].is_null;
stmt->params[i].type = binds[i].type;
lua_pop(L, 1);
}
if (!needs_rebind && db_bind_param(stmt->ptr, binds, n))
goto error;
stmt->nparams = n;
/* Create reference for the params table */
lua_pushvalue(L, 2);
stmt->param_ref = luaL_ref(L, LUA_REGISTRYINDEX);
free(binds);
return 0;
error:
free(binds);
lua_error(L);
return 0;
}
int sb_lua_db_bind_result(lua_State *L)
{
sb_lua_db_stmt_t *stmt;
unsigned int i, n;
db_bind_t *binds;
char needs_rebind = 0;
check_connection(L, &tls_lua_ctxt);
stmt = (sb_lua_db_stmt_t *)luaL_checkudata(L, 1, "sysbench.stmt");
luaL_argcheck(L, stmt != NULL, 1, "prepared statement expected");
if (!lua_istable(L, 2))
luaL_error(L, "table was expected");
/* Get table size */
n = sb_lua_table_size(L, 2);
if (!n)
luaL_error(L, "table is empty");
binds = (db_bind_t *)calloc(n, sizeof(db_bind_t));
stmt->results = (sb_lua_bind_t *)calloc(n, sizeof(sb_lua_bind_t));
if (binds == NULL || stmt->results == NULL)
luaL_error(L, "memory allocation failure");
lua_pushnil(L);
for (i = 0; i < n; i++)
{
lua_next(L, 2);
switch(lua_type(L, -1))
{
case LUA_TNUMBER:
stmt->results[i].buf = malloc(sizeof(int));
stmt->results[i].id = luaL_checknumber(L, -2);
binds[i].type = DB_TYPE_BIGINT;
binds[i].buffer = stmt->results[i].buf;
break;
case LUA_TSTRING:
stmt->results[i].id = luaL_checknumber(L, -2);
binds[i].type = DB_TYPE_CHAR;
needs_rebind = 1;
break;
default:
lua_pushfstring(L, "Unsupported variable type: %s",
lua_typename(L, lua_type(L, -1)));
goto error;
}
binds[i].is_null = &stmt->results[i].is_null;
stmt->results[i].type = binds[i].type;
lua_pop(L, 1);
}
if (!needs_rebind && db_bind_result(stmt->ptr, binds, n))
goto error;
stmt->nresults = n;
/* Create reference for the params table */
lua_pushvalue(L, 2);
stmt->result_ref = luaL_ref(L, LUA_REGISTRYINDEX);
// free(binds);
return 0;
error:
free(binds);
lua_error(L);
return 0;
}
int sb_lua_db_execute(lua_State *L)
{
sb_lua_db_stmt_t *stmt;
db_result_t *ptr;
sb_lua_db_rs_t *rs;
unsigned int i;
char needs_rebind = 0;
db_bind_t *binds;
size_t length;
const char *str;
sb_lua_bind_t *param;
check_connection(L, &tls_lua_ctxt);
stmt = (sb_lua_db_stmt_t *)luaL_checkudata(L, 1, "sysbench.stmt");
luaL_argcheck(L, stmt != NULL, 1, "prepared statement expected");
/* Get params table */
lua_rawgeti(L, LUA_REGISTRYINDEX, stmt->param_ref);
if (!lua_isnil(L, -1) && !lua_istable(L, -1))
luaL_error(L, "table expected");
for (i = 0; i < stmt->nparams; lua_pop(L, 1), i++)
{
param = stmt->params + i;
lua_pushnumber(L, param->id);
lua_gettable(L, -2);
if (lua_isnil(L, -1))
{
param->is_null = 1;
continue;
}
param->is_null = 0;
switch (param->type)
{
case DB_TYPE_INT:
*((int *)param->buf) = luaL_checknumber(L, -1);
break;
case DB_TYPE_CHAR:
str = luaL_checkstring(L, -1);
length = lua_objlen(L, -1);
if (length > param->buflen)
{
param->buf = realloc(param->buf, length);
needs_rebind = 1;
}
strncpy(param->buf, str, length);
param->buflen = length;
break;
default:
luaL_error(L, "Unsupported variable type: %s",
lua_typename(L, lua_type(L, -1)));
}
}
/* Rebind if needed */
if (needs_rebind)
{
binds = (db_bind_t *)calloc(stmt->nparams, sizeof(db_bind_t));
if (binds == NULL)
luaL_error(L, "Memory allocation failure");
for (i = 0; i < stmt->nparams; i++)
{
param = stmt->params + i;
binds[i].type = param->type;
binds[i].is_null = &param->is_null;
if (*binds[i].is_null != 0)
continue;
switch (param->type)
{
case DB_TYPE_INT:
binds[i].buffer = param->buf;
break;
case DB_TYPE_CHAR:
binds[i].buffer = param->buf;
binds[i].data_len = &stmt->params[i].buflen;
binds[i].is_null = 0;
break;
default:
luaL_error(L, "Unsupported variable type");
}
}
if (db_bind_param(stmt->ptr, binds, stmt->nparams))
luaL_error(L, "db_bind_param() failed");
free(binds);
}
ptr = db_execute(stmt->ptr);
if (ptr == NULL && tls_lua_ctxt.con->error == DB_ERROR_IGNORABLE)
{
stmt->rs = NULL;
throw_restart_event(L);
}
else
{
rs = (sb_lua_db_rs_t *)lua_newuserdata(L, sizeof(sb_lua_db_rs_t));
rs->ptr = ptr;
luaL_getmetatable(L, "sysbench.rs");
lua_setmetatable(L, -2);
stmt->rs = rs;
}
return 1;
}
int sb_lua_db_close(lua_State *L)
{
sb_lua_db_stmt_t *stmt;
unsigned int i;
check_connection(L, &tls_lua_ctxt);
stmt = (sb_lua_db_stmt_t *)luaL_checkudata(L, 1, "sysbench.stmt");
luaL_argcheck(L, stmt != NULL, 1, "prepared statement expected");
for (i = 0; i < stmt->nparams; i++)
{
if (stmt->params[i].buf != NULL)
free(stmt->params[i].buf);
}
free(stmt->params);
stmt->params = NULL;
luaL_unref(L, LUA_REGISTRYINDEX, stmt->param_ref);
luaL_unref(L, LUA_REGISTRYINDEX, stmt->result_ref);
db_close(stmt->ptr);
return 0;
}
int sb_lua_db_store_results(lua_State *L)
{
sb_lua_db_rs_t *rs;
check_connection(L, &tls_lua_ctxt);
rs = (sb_lua_db_rs_t *)luaL_checkudata(L, 1, "sysbench.rs");
luaL_argcheck(L, rs != NULL, 1, "result set expected");
/* noop as db_store_results() is now performed automatically by db_query() */
return 0;
}
int sb_lua_db_free_results(lua_State *L)
{
sb_lua_db_rs_t *rs;
check_connection(L, &tls_lua_ctxt);
rs = (sb_lua_db_rs_t *)luaL_checkudata(L, 1, "sysbench.rs");
luaL_argcheck(L, rs != NULL, 1, "result set expected");
if (rs->ptr != NULL)
{
db_free_results(rs->ptr);
rs->ptr = NULL;
}
return 0;
}
unsigned int sb_lua_table_size(lua_State *L, int index)
{
unsigned int i;
lua_pushnil(L);
for (i = 0; lua_next(L, index); i++)
{
lua_pop(L, 1);
}
return i;
}
/* Check if a specified hook exists */
static bool sb_lua_hook_defined(lua_State *L, const char *name)

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2004 MySQL AB
Copyright (C) 2004-2017 Alexey Kopytov <akopytov@gmail.com>
Copyright (C) 2004-2018 Alexey Kopytov <akopytov@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -617,12 +617,8 @@ static int parse_test_arguments(sb_test_t *test, int argc, char *argv[])
if (argv[i] == NULL || strncmp(argv[i], "--", 2))
continue;
/*
At this stage an unrecognized option must throw a error, unless the test
defines no options (for compatibility with legacy Lua scripts). In the
latter case we just export all unrecognized options as strings.
*/
if (parse_option(argv[i]+2, test->args == NULL))
/* At this stage an unrecognized option must throw a error. */
if (parse_option(argv[i]+2, false))
{
fprintf(stderr, "invalid option: %s\n", argv[i]);
return 1;

View File

@ -1,4 +1,4 @@
# Copyright (C) 2016 Alexey Kopytov <akopytov@gmail.com>
# Copyright (C) 2016-2018 Alexey Kopytov <akopytov@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -27,7 +27,7 @@ EXTRA_DIST = $(test_SCRIPTS) \
testroot = $(datadir)
testdir = $(testroot)/sysbench/tests
test_dirs= t include include/oltp_legacy
test_dirs= t include
# Used by dist-hook and install-data-local to copy all
# test files into either dist or install directory

View File

@ -10,7 +10,8 @@ set -eu
cat >test.lua <<EOF
function event()
db_query("SELECT 1")
c = c or sysbench.sql.driver():connect()
c:query("SELECT 1")
end
EOF

View File

@ -1,61 +0,0 @@
-- -------------------------------------------------------------------------- --
-- Bulk insert tests --
-- -------------------------------------------------------------------------- --
cursize=0
function prepare()
local i
db_connect()
for i = 0,num_threads-1 do
if (db_driver == "pgsql") then
db_query([[
CREATE TABLE IF NOT EXISTS sbtest]] .. i .. [[ (
id INTEGER NOT NULL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
)]])
else
db_query([[
CREATE TABLE IF NOT EXISTS sbtest]] .. i .. [[ (
id INTEGER UNSIGNED NOT NULL,
k INTEGER UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB
]])
end
end --for
end
function event()
local i
if (cursize == 0) then
db_bulk_insert_init("INSERT INTO sbtest" .. thread_id .. " VALUES")
end
cursize = cursize + 1
db_bulk_insert_next("(" .. cursize .. "," .. cursize .. ")")
end
function thread_done(thread_9d)
db_bulk_insert_done()
end
function cleanup()
local i
for i = 0,num_threads-1 do
print("Dropping table 'sbtest" .. i .. "'...")
db_query("DROP TABLE IF EXISTS sbtest".. i )
end
end

View File

@ -1,190 +0,0 @@
-- Input parameters
-- oltp-tables-count - number of tables to create
-- oltp-secondary - use secondary key instead PRIMARY key for id column
--
--
function create_insert(table_id)
local index_name
local i
local j
local query
if (oltp_secondary) then
index_name = "KEY xid"
else
index_name = "PRIMARY KEY"
end
if (pgsql_variant == 'redshift') then
auto_inc_type = "INTEGER IDENTITY(1,1)"
else
auto_inc_type = "SERIAL"
end
i = table_id
print("Creating table 'sbtest" .. i .. "'...")
if ((db_driver == "mysql") or (db_driver == "attachsql")) then
query = [[
CREATE TABLE sbtest]] .. i .. [[ (
id INTEGER UNSIGNED NOT NULL ]] ..
((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,
k INTEGER UNSIGNED DEFAULT '0' NOT NULL,
c CHAR(120) DEFAULT '' NOT NULL,
pad CHAR(60) DEFAULT '' NOT NULL,
]] .. index_name .. [[ (id)
) /*! ENGINE = ]] .. mysql_table_engine ..
" MAX_ROWS = " .. myisam_max_rows .. " */ " ..
(mysql_table_options or "")
elseif (db_driver == "pgsql") then
query = [[
CREATE TABLE sbtest]] .. i .. [[ (
id ]] .. auto_inc_type .. [[ NOT NULL,
k INTEGER DEFAULT '0' NOT NULL,
c CHAR(120) DEFAULT '' NOT NULL,
pad CHAR(60) DEFAULT '' NOT NULL,
]] .. index_name .. [[ (id)
) ]]
elseif (db_driver == "drizzle") then
query = [[
CREATE TABLE sbtest (
id INTEGER NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,
k INTEGER DEFAULT '0' NOT NULL,
c CHAR(120) DEFAULT '' NOT NULL,
pad CHAR(60) DEFAULT '' NOT NULL,
]] .. index_name .. [[ (id)
) ]]
else
print("Unknown database driver: " .. db_driver)
return 1
end
db_query(query)
print("Inserting " .. oltp_table_size .. " records into 'sbtest" .. i .. "'")
if (oltp_auto_inc) then
db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(k, c, pad) VALUES")
else
db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(id, k, c, pad) VALUES")
end
local c_val
local pad_val
for j = 1,oltp_table_size do
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
if (oltp_auto_inc) then
db_bulk_insert_next("(" .. sb_rand(1, oltp_table_size) .. ", '".. c_val .."', '" .. pad_val .. "')")
else
db_bulk_insert_next("("..j.."," .. sb_rand(1, oltp_table_size) .. ",'".. c_val .."', '" .. pad_val .. "' )")
end
end
db_bulk_insert_done()
if oltp_create_secondary then
print("Creating secondary indexes on 'sbtest" .. i .. "'...")
db_query("CREATE INDEX k_" .. i .. " on sbtest" .. i .. "(k)")
end
end
function prepare()
local query
local i
local j
set_vars()
db_connect()
for i = 1,oltp_tables_count do
create_insert(i)
end
return 0
end
function cleanup()
local i
set_vars()
for i = 1,oltp_tables_count do
print("Dropping table 'sbtest" .. i .. "'...")
db_query("DROP TABLE IF EXISTS sbtest".. i )
end
end
function set_vars()
oltp_table_size = tonumber(oltp_table_size) or 10000
oltp_range_size = tonumber(oltp_range_size) or 100
oltp_tables_count = tonumber(oltp_tables_count) or 1
oltp_point_selects = tonumber(oltp_point_selects) or 10
oltp_simple_ranges = tonumber(oltp_simple_ranges) or 1
oltp_sum_ranges = tonumber(oltp_sum_ranges) or 1
oltp_order_ranges = tonumber(oltp_order_ranges) or 1
oltp_distinct_ranges = tonumber(oltp_distinct_ranges) or 1
oltp_index_updates = tonumber(oltp_index_updates) or 1
oltp_non_index_updates = tonumber(oltp_non_index_updates) or 1
oltp_delete_inserts = tonumber(oltp_delete_inserts) or 1
if (oltp_range_selects == 'off') then
oltp_range_selects = false
else
oltp_range_selects = true
end
if (oltp_auto_inc == 'off') then
oltp_auto_inc = false
else
oltp_auto_inc = true
end
if (oltp_read_only == 'on') then
oltp_read_only = true
else
oltp_read_only = false
end
if (oltp_write_only == 'on') then
oltp_write_only = true
else
oltp_write_only = false
end
if (oltp_read_only and oltp_write_only) then
error("--oltp-read-only and --oltp-write-only are mutually exclusive")
end
if (oltp_skip_trx == 'on') then
oltp_skip_trx = true
else
oltp_skip_trx = false
end
if (oltp_create_secondary == 'off') then
oltp_create_secondary = false
else
oltp_create_secondary = true
end
if (pgsql_variant == 'redshift') then
oltp_create_secondary = false
oltp_delete_inserts = 0
end
end

View File

@ -1,17 +0,0 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. sb_rand(1, oltp_table_size))
end

View File

@ -1,42 +0,0 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init(thread_id)
set_vars()
end
function event()
local table_name
local i
local c_val
local k_val
local pad_val
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
k_val = sb_rand(1, oltp_table_size)
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
if (db_driver == "pgsql" and oltp_auto_inc) then
rs = db_query("INSERT INTO " .. table_name .. " (k, c, pad) VALUES " ..
string.format("(%d, '%s', '%s')", k_val, c_val, pad_val))
else
if (oltp_auto_inc) then
i = 0
else
i = sb_rand_uniq()
end
rs = db_query("INSERT INTO " .. table_name ..
" (id, k, c, pad) VALUES " ..
string.format("(%d, %d, '%s', '%s')", i, k_val, c_val,
pad_val))
end
end

View File

@ -1,114 +0,0 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars()
if (((db_driver == "mysql") or (db_driver == "attachsql")) and mysql_table_engine == "myisam") then
local i
local tables = {}
for i=1, oltp_tables_count do
tables[i] = string.format("sbtest%i WRITE", i)
end
begin_query = "LOCK TABLES " .. table.concat(tables, " ,")
commit_query = "UNLOCK TABLES"
else
begin_query = "BEGIN"
commit_query = "COMMIT"
end
end
function get_range_str()
local start = sb_rand(1, oltp_table_size)
return string.format(" WHERE id BETWEEN %u AND %u",
start, start + oltp_range_size - 1)
end
function event()
local rs
local i
local table_name
local c_val
local pad_val
local query
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
if not oltp_skip_trx then
db_query(begin_query)
end
if not oltp_write_only then
for i=1, oltp_point_selects do
rs = db_query("SELECT c FROM ".. table_name .." WHERE id=" ..
sb_rand(1, oltp_table_size))
end
if oltp_range_selects then
for i=1, oltp_simple_ranges do
rs = db_query("SELECT c FROM ".. table_name .. get_range_str())
end
for i=1, oltp_sum_ranges do
rs = db_query("SELECT SUM(K) FROM ".. table_name .. get_range_str())
end
for i=1, oltp_order_ranges do
rs = db_query("SELECT c FROM ".. table_name .. get_range_str() ..
" ORDER BY c")
end
for i=1, oltp_distinct_ranges do
rs = db_query("SELECT DISTINCT c FROM ".. table_name .. get_range_str() ..
" ORDER BY c")
end
end
end
if not oltp_read_only then
for i=1, oltp_index_updates do
rs = db_query("UPDATE " .. table_name .. " SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size))
end
for i=1, oltp_non_index_updates do
c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
query = "UPDATE " .. table_name .. " SET c='" .. c_val .. "' WHERE id=" .. sb_rand(1, oltp_table_size)
rs = db_query(query)
if rs then
print(query)
end
end
for i=1, oltp_delete_inserts do
i = sb_rand(1, oltp_table_size)
rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. i)
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
rs = db_query("INSERT INTO " .. table_name .. " (id, k, c, pad) VALUES " .. string.format("(%d, %d, '%s', '%s')",i, sb_rand(1, oltp_table_size) , c_val, pad_val))
end
end -- oltp_read_only
if not oltp_skip_trx then
db_query(commit_query)
end
end

View File

@ -1,19 +0,0 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("SELECT c FROM ".. table_name .." WHERE id=" .. sb_rand(1, oltp_table_size))
end

View File

@ -1,30 +0,0 @@
-- for proper initialization use --max-requests = N, where N is --num-threads
--
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local index_name
local i
print("thread prepare"..thread_id)
if (oltp_secondary) then
index_name = "KEY xid"
else
index_name = "PRIMARY KEY"
end
for i=thread_id+1, oltp_tables_count, num_threads do
create_insert(i)
end
end

View File

@ -1,18 +0,0 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("SELECT pad FROM ".. table_name .." WHERE id=" .. sb_rand(1, oltp_table_size))
end

View File

@ -1,61 +0,0 @@
-- This test is designed for testing MariaDB's key_cache_segments for MyISAM,
-- and should work with other storage engines as well.
--
-- For details about key_cache_segments please refer to:
-- http://kb.askmonty.org/v/segmented-key-cache
--
-- Override oltp_tables_count, this test only supports a single table
oltp_tables_count = 1
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars_points()
points = ""
for i = 1,random_points do
points = points .. "?, "
end
-- Get rid of last comma and space.
points = string.sub(points, 1, string.len(points) - 2)
stmt = db_prepare([[
SELECT id, k, c, pad
FROM sbtest1
WHERE k IN (]] .. points .. [[)
]])
params = {}
for j = 1,random_points do
params[j] = 1
end
db_bind_param(stmt, params)
end
function event()
local rs
-- To prevent overlapping of our range queries we need to partition the whole table
-- into num_threads segments and then make each thread work with its own segment.
for i = 1,random_points do
params[i] = sb_rand(oltp_table_size / num_threads * thread_id, oltp_table_size / num_threads * (thread_id + 1))
end
rs = db_execute(stmt)
db_store_results(rs)
db_free_results(rs)
end
function set_vars_points()
set_vars()
random_points = random_points or 10
end

View File

@ -1,64 +0,0 @@
-- This test is designed for testing MariaDB's key_cache_segments for MyISAM,
-- and should work with other storage engines as well.
--
-- For details about key_cache_segments please refer to:
-- http://kb.askmonty.org/v/segmented-key-cache
--
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
-- Override oltp_tables_count, this test only supports a single table
oltp_tables_count = 1
function thread_init()
set_vars_ranges()
ranges = ""
for i = 1,number_of_ranges do
ranges = ranges .. "k BETWEEN ? AND ? OR "
end
-- Get rid of last OR and space.
ranges = string.sub(ranges, 1, string.len(ranges) - 3)
stmt = db_prepare([[
SELECT count(k)
FROM sbtest1
WHERE ]] .. ranges .. [[
]])
params = {}
for j = 1,number_of_ranges * 2 do
params[j] = 1
end
db_bind_param(stmt, params)
end
function event()
local rs
-- To prevent overlapping of our range queries we need to partition the whole table
-- into num_threads segments and then make each thread work with its own segment.
for i = 1,number_of_ranges * 2,2 do
params[i] = sb_rand(oltp_table_size / num_threads * thread_id, oltp_table_size / num_threads * (thread_id + 1))
params[i + 1] = params[i] + delta
end
rs = db_execute(stmt)
db_store_results(rs)
db_free_results(rs)
end
function set_vars_ranges()
set_vars()
number_of_ranges = number_of_ranges or 10
delta = random_ranges_delta or 5
end

View File

@ -1,17 +0,0 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("UPDATE ".. table_name .." SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size))
end

View File

@ -1,21 +0,0 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
local c_val
local query
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
query = "UPDATE " .. table_name .. " SET c='" .. c_val .. "' WHERE id=" .. sb_rand(1, oltp_table_size)
rs = db_query(query)
end

View File

@ -1,51 +0,0 @@
#!/usr/bin/env bash
#
################################################################################
# Common code for legacy OLTP tests
#
# Expects the following variables and callback functions to be defined by the
# caller:
#
# DB_DRIVER_ARGS -- extra driver-specific arguments to pass to sysbench
#
# db_show_table() -- called with a single argument to dump a specified table
# schema
################################################################################
set -eu
ARGS="--test=${SBTEST_INCDIR}/oltp_legacy/oltp.lua $DB_DRIVER_ARGS --oltp-tables-count=8"
sysbench $ARGS prepare
db_show_table sbtest1
db_show_table sbtest2
db_show_table sbtest3
db_show_table sbtest4
db_show_table sbtest5
db_show_table sbtest6
db_show_table sbtest7
db_show_table sbtest8
db_show_table sbtest9 || true # Error on non-existing table
sysbench $ARGS --max-requests=100 --num-threads=2 run
sysbench $ARGS cleanup
db_show_table sbtest1 || true # Error on non-existing table
db_show_table sbtest2 || true # Error on non-existing table
db_show_table sbtest3 || true # Error on non-existing table
db_show_table sbtest4 || true # Error on non-existing table
db_show_table sbtest5 || true # Error on non-existing table
db_show_table sbtest6 || true # Error on non-existing table
db_show_table sbtest7 || true # Error on non-existing table
db_show_table sbtest8 || true # Error on non-existing table
# Test --oltp-create-secondary=off
ARGS="--test=${SBTEST_INCDIR}/oltp_legacy/oltp.lua $DB_DRIVER_ARGS --oltp-tables-count=1"
sysbench $ARGS --oltp-create-secondary=off prepare
db_show_table sbtest1
sysbench $ARGS cleanup

View File

@ -1,40 +0,0 @@
#!/usr/bin/env bash
#
################################################################################
# Common code for select_random_* tests
#
# Expects the following variables and callback functions to be defined by the
# caller:
#
# DB_DRIVER_ARGS -- extra driver-specific arguments to pass to sysbench
#
# db_show_table() -- called with a single argument to dump a specified table
# schema
################################################################################
set -eu
for test in select_random_points select_random_ranges
do
ARGS="--test=${SBTEST_INCDIR}/oltp_legacy/${test}.lua $DB_DRIVER_ARGS --tables=8"
sysbench $ARGS prepare
db_show_table sbtest1
for i in $(seq 2 8)
do
db_show_table sbtest${i} || true # Error on non-existing table
done
sysbench $ARGS --max-requests=100 run
sysbench $ARGS cleanup
for i in $(seq 1 8)
do
db_show_table sbtest${i} || true # Error on non-existing table
done
ARGS="{SBTEST_INCDIR}/oltp_legacy/select_random_points.lua $DB_DRIVER_ARGS --tables=8"
done

View File

@ -1,74 +0,0 @@
########################################################################
Legacy basic Lua API tests
########################################################################
$ if [ -z "${SBTEST_MYSQL_ARGS:-}" ]
> then
> exit 80
> fi
$ SB_ARGS="--verbosity=0 --max-requests=2 --db-driver=mysql $SBTEST_MYSQL_ARGS --test=$CRAMTMP/api_legacy_basic.lua"
$ cat >$CRAMTMP/api_legacy_basic.lua <<EOF
> function prepare(thread_id)
> print("tid:" .. (thread_id or "(nil)") .. " prepare()")
> end
>
> function run(thread_id)
> print("tid:" .. (thread_id or "(nil)") .. " run()")
> end
>
> function cleanup(thread_id)
> print("tid:" .. (thread_id or "(nil)") .. " cleanup()")
> end
>
> function help()
> print("tid:" .. (thread_id or "(nil)") .. " help()")
> end
>
> function thread_init(thread_id)
> print(string.format("tid:%d thread_init()", thread_id))
> end
>
> function event(thread_id)
> print(string.format("tid:%d event()", thread_id))
> end
>
> function thread_done(thread_id)
> print(string.format("tid:%d thread_done()", thread_id))
> end
>
> EOF
$ sysbench $SB_ARGS prepare
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-requests is deprecated, use --events instead
tid:(nil) prepare()
$ sysbench $SB_ARGS run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-requests is deprecated, use --events instead
tid:0 thread_init()
tid:0 event()
tid:0 event()
tid:0 thread_done()
$ sysbench $SB_ARGS cleanup
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-requests is deprecated, use --events instead
tid:(nil) cleanup()
$ sysbench $SB_ARGS help
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-requests is deprecated, use --events instead
tid:0 help()
$ cat >$CRAMTMP/api_legacy_basic.lua <<EOF
> function prepare()
> print(test)
> end
> EOF
$ sysbench $SB_ARGS prepare
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-requests is deprecated, use --events instead
*/api_legacy_basic.lua (glob)

View File

@ -1,47 +0,0 @@
########################################################################
Legacy PRNG Lua API tests
########################################################################
$ SB_ARGS="--verbosity=0 --max-requests=1"
$ cat >$CRAMTMP/api_legacy_rand.lua <<EOF
> function event()
> print("sb_rand(0, 9) = " .. sb_rand(0, 9))
> print("sb_rand_uniq(0, 4294967295) = " .. sb_rand_uniq(0, 4294967295))
> print("sb_rnd() = " .. sb_rnd())
> print([[sb_rand_str("abc-###-@@@-xyz") = ]] .. sb_rand_str("abc-###-@@@-xyz"))
> print("sb_rand_uniform(0, 9) = " .. sb_rand_uniform(0, 9))
> print("sb_rand_gaussian(0, 9) = " .. sb_rand_gaussian(0, 9))
> print("sb_rand_special(0, 9) = " .. sb_rand_special(0, 9))
> end
> EOF
$ sysbench $SB_ARGS --test=$CRAMTMP/api_legacy_rand.lua run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-requests is deprecated, use --events instead
sb_rand\(0, 9\) = [0-9]{1} (re)
sb_rand_uniq\(0, 4294967295\) = [0-9]{1,10} (re)
sb_rnd\(\) = [0-9]+ (re)
sb_rand_str\(".*"\) = abc-[0-9]{3}-[a-z]{3}-xyz (re)
sb_rand_uniform\(0, 9\) = [0-9]{1} (re)
sb_rand_gaussian\(0, 9\) = [0-9]{1} (re)
sb_rand_special\(0, 9\) = [0-9]{1} (re)
########################################################################
GH-96: sb_rand_uniq(1, oltp_table_size) generate duplicate value
########################################################################
$ cat >$CRAMTMP/api_rand_uniq.lua <<EOF
> function event()
> local max = 1000000000
> local n = sb_rand_uniq(1, max)
> if n > max then
> error("n is out of range")
> end
> print(n)
> end
> EOF
$ sysbench $SB_ARGS --max-requests=100000 --test=$CRAMTMP/api_rand_uniq.lua run |
> grep -v WARNING | sort -n | uniq | wc -l | sed -e 's/ //g'
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
100000

View File

@ -1,447 +0,0 @@
########################################################################
Legacy SQL Lua API tests
########################################################################
$ if [ -z "${SBTEST_MYSQL_ARGS:-}" ]
> then
> exit 80
> fi
$ SB_ARGS="--verbosity=1 --max-requests=1 --db-driver=mysql $SBTEST_MYSQL_ARGS --test=$CRAMTMP/api_legacy_sql.lua"
$ cat >$CRAMTMP/api_legacy_sql.lua <<EOF
> function event(thread_id)
> db_query("CREATE TABLE t(a INT)")
>
> db_bulk_insert_init("INSERT INTO t VALUES")
> for i = 1,100 do
> db_bulk_insert_next(string.format("(%d)", i))
> end
> db_bulk_insert_done()
>
> db_connect()
> db_query("SELECT 1")
> db_disconnect()
> db_query("SELECT 1")
> db_connect()
>
> local stmt = db_prepare("UPDATE t SET a = a + ?")
> db_bind_param(stmt, {100})
> rs = db_execute(stmt)
> db_store_results(rs)
> db_free_results(rs)
> db_close(stmt)
>
> print("DB_ERROR_NONE = " .. DB_ERROR_NONE)
> print("DB_ERROR_RESTART_TRANSACTION = " .. DB_ERROR_RESTART_TRANSACTION)
> print("DB_ERROR_FAILED = " .. DB_ERROR_FAILED)
> end
> EOF
$ mysql -uroot sbtest -Nse "DROP TABLE IF EXISTS t"
$ sysbench $SB_ARGS run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-requests is deprecated, use --events instead
DB_ERROR_NONE = [0-9] (re)
DB_ERROR_RESTART_TRANSACTION = [0-9] (re)
DB_ERROR_FAILED = [0-9] (re)
$ mysql -uroot sbtest -Nse "SHOW CREATE TABLE t\G"
*************************** 1. row ***************************
t
CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) * (glob)
$ mysql -uroot sbtest -Nse "SELECT COUNT(DISTINCT a) FROM t"
100
$ mysql -uroot sbtest -Nse "SELECT MIN(a), MAX(a) FROM t\G"
*************************** 1. row ***************************
101
200
$ mysql -uroot sbtest -Nse "DROP TABLE t"
$ function db_show_table() {
> mysql -uroot sbtest -Nse "SHOW CREATE TABLE $1\G"
> }
$ DB_DRIVER_ARGS="--db-driver=mysql --mysql-table-engine=myisam $SBTEST_MYSQL_ARGS"
$ . $SBTEST_INCDIR/script_oltp_legacy_common.sh
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench *.* * (glob)
Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
Creating secondary indexes on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 10000 records into 'sbtest2'
Creating secondary indexes on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 10000 records into 'sbtest3'
Creating secondary indexes on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 10000 records into 'sbtest4'
Creating secondary indexes on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 10000 records into 'sbtest5'
Creating secondary indexes on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 10000 records into 'sbtest6'
Creating secondary indexes on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 10000 records into 'sbtest7'
Creating secondary indexes on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 10000 records into 'sbtest8'
Creating secondary indexes on 'sbtest8'...
*************************** 1. row ***************************
sbtest1
CREATE TABLE `sbtest1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_1` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest2
CREATE TABLE `sbtest2` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_2` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest3
CREATE TABLE `sbtest3` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_3` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest4
CREATE TABLE `sbtest4` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_4` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest5
CREATE TABLE `sbtest5` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_5` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest6
CREATE TABLE `sbtest6` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_6` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest7
CREATE TABLE `sbtest7` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_7` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest8
CREATE TABLE `sbtest8` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_8` (`k`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest9' doesn't exist
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --num-threads is deprecated, use --threads instead
WARNING: --max-requests is deprecated, use --events instead
sysbench *.* * (glob)
Running the test with following options:
Number of threads: 2
Initializing random number generator from current time
Initializing worker threads...
Threads started!
SQL statistics:
queries performed:
read: 1400
write: 400
other: 200
total: 2000
transactions: 100 (* per sec.) (glob)
queries: 2000 (* per sec.) (glob)
ignored errors: 0 (* per sec.) (glob)
reconnects: 0 (* per sec.) (glob)
Throughput:
events/s (eps): *.* (glob)
time elapsed: *s (glob)
total number of events: 100
Latency (ms):
min: *.* (glob)
avg: *.* (glob)
max: *.* (glob)
95th percentile: *.* (glob)
sum: *.* (glob)
Threads fairness:
events (avg/stddev): */* (glob)
execution time (avg/stddev): */* (glob)
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench *.* * (glob)
Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest1' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest2' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest3' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest4' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest5' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest6' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest7' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest8' doesn't exist
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench * (glob)
Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
*************************** 1. row ***************************
sbtest1
CREATE TABLE `sbtest1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench * (glob)
Dropping table 'sbtest1'...
$ DB_DRIVER_ARGS="--db-driver=mysql --mysql-table-engine=innodb $SBTEST_MYSQL_ARGS"
$ . $SBTEST_INCDIR/script_oltp_legacy_common.sh
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench *.* * (glob)
Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
Creating secondary indexes on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 10000 records into 'sbtest2'
Creating secondary indexes on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 10000 records into 'sbtest3'
Creating secondary indexes on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 10000 records into 'sbtest4'
Creating secondary indexes on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 10000 records into 'sbtest5'
Creating secondary indexes on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 10000 records into 'sbtest6'
Creating secondary indexes on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 10000 records into 'sbtest7'
Creating secondary indexes on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 10000 records into 'sbtest8'
Creating secondary indexes on 'sbtest8'...
*************************** 1. row ***************************
sbtest1
CREATE TABLE `sbtest1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_1` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest2
CREATE TABLE `sbtest2` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_2` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest3
CREATE TABLE `sbtest3` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_3` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest4
CREATE TABLE `sbtest4` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_4` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest5
CREATE TABLE `sbtest5` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_5` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest6
CREATE TABLE `sbtest6` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_6` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest7
CREATE TABLE `sbtest7` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_7` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
*************************** 1. row ***************************
sbtest8
CREATE TABLE `sbtest8` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`),
KEY `k_8` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest9' doesn't exist
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --num-threads is deprecated, use --threads instead
WARNING: --max-requests is deprecated, use --events instead
sysbench *.* * (glob)
Running the test with following options:
Number of threads: 2
Initializing random number generator from current time
Initializing worker threads...
Threads started!
SQL statistics:
queries performed:
read: 1400
write: 400
other: 200
total: 2000
transactions: 100 (* per sec.) (glob)
queries: 2000 (* per sec.) (glob)
ignored errors: 0 (* per sec.) (glob)
reconnects: 0 (* per sec.) (glob)
Throughput:
events/s (eps): *.* (glob)
time elapsed: *s (glob)
total number of events: 100
Latency (ms):
min: *.* (glob)
avg: *.* (glob)
max: *.* (glob)
95th percentile: *.* (glob)
sum: *.* (glob)
Threads fairness:
events (avg/stddev): */* (glob)
execution time (avg/stddev): */* (glob)
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench *.* * (glob)
Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest1' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest2' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest3' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest4' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest5' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest6' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest7' doesn't exist
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest8' doesn't exist
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench * (glob)
Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
*************************** 1. row ***************************
sbtest1
CREATE TABLE `sbtest1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120)* NOT NULL DEFAULT '', (glob)
`pad` char(60)* NOT NULL DEFAULT '', (glob)
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob)
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench * (glob)
Dropping table 'sbtest1'...

View File

@ -414,6 +414,7 @@ Command line options tests
[1]
$ cat >cmdline.lua <<EOF
> sysbench.cmdline.options = { opt1 = {"opt1"}, opt2 = {"opt2"} }
> function print_cmd()
> print("argv = " .. require("inspect")(sysbench.cmdline.argv))
> print(string.format("sysbench.cmdline.command = %s",sysbench.cmdline.command))