From 976208719b2010c14f966454e552b5e496b8aeac Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Sat, 17 Feb 2018 17:55:43 +0300 Subject: [PATCH] OLTP tests: re-prepare statements after reconnects (fixes #213). 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) --- src/lua/internal/sysbench.lua | 8 ++++++-- src/lua/oltp_common.lua | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/lua/internal/sysbench.lua b/src/lua/internal/sysbench.lua index 2c8296608..ea8135628 100644 --- a/src/lua/internal/sysbench.lua +++ b/src/lua/internal/sysbench.lua @@ -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 diff --git a/src/lua/oltp_common.lua b/src/lua/oltp_common.lua index a964222cd..cb2a7a1ae 100644 --- a/src/lua/oltp_common.lua +++ b/src/lua/oltp_common.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2006-2017 Alexey Kopytov +-- Copyright (C) 2006-2018 Alexey Kopytov -- 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 @@ -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() @@ -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 @@ -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