Skip to content

Commit

Permalink
OLTP tests: re-prepare statements after reconnects (fixes #213).
Browse files Browse the repository at this point in the history
Fix oltp_common.lua to re-prepare prepared statements after
reconnecting, i.e. if a connection to the server has been lost and one
of the following MySQL errors is in the --mysql-ignore-errors list:

- 2013 (CR_SERVER_LOST)
- 2055 (CR_SERVER_LOST_EXTENDED)
- 2006 (CR_SERVER_GONE_ERROR)
- 2011 (CR_TCP_CONNECTION)
  • Loading branch information
akopytov committed Feb 17, 2018
1 parent 4ed79a7 commit 9762087
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/lua/internal/sysbench.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ function thread_run(thread_id)
success, ret = pcall(event, thread_id)

if not success then
if type(ret) ~= "table" or
ret.errcode ~= sysbench.error.RESTART_EVENT
if type(ret) == "table" and
ret.errcode == sysbench.error.RESTART_EVENT
then
if sysbench.hooks.before_restart_event then
sysbench.hooks.before_restart_event(ret)
end
else
error(ret, 2) -- propagate unknown errors
end
end
Expand Down
23 changes: 20 additions & 3 deletions src/lua/oltp_common.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (C) 2006-2017 Alexey Kopytov <[email protected]>
-- Copyright (C) 2006-2018 Alexey Kopytov <[email protected]>

-- 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
Expand Down Expand Up @@ -363,8 +363,8 @@ function thread_init()
prepare_statements()
end

function thread_done()
-- Close prepared statements
-- Close prepared statements
function close_statements()
for t = 1, sysbench.opt.tables do
for k, s in pairs(stmt[t]) do
stmt[t][k]:close()
Expand All @@ -376,6 +376,10 @@ function thread_done()
if (stmt.commit ~= nil) then
stmt.commit:close()
end
end

function thread_done()
close_statements()
con:disconnect()
end

Expand Down Expand Up @@ -484,3 +488,16 @@ function execute_delete_inserts()
stmt[tnum].inserts:execute()
end
end

-- Re-prepare statements if we have reconnected, which is possible when some of
-- the listed error codes are in the --mysql-ignore-errors list
function sysbench.hooks.before_restart_event(errdesc)
if errdesc.sql_errno == 2013 or -- CR_SERVER_LOST
errdesc.sql_errno == 2055 or -- CR_SERVER_LOST_EXTENDED
errdesc.sql_errno == 2006 or -- CR_SERVER_GONE_ERROR
errdesc.sql_errno == 2011 -- CR_TCP_CONNECTION
then
close_statements()
prepare_statements()
end
end

0 comments on commit 9762087

Please sign in to comment.