2
Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; version 2 of the
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22
print the statements of all transactions as soon as one of them aborted
24
for now we know about:
25
* Lock wait timeout exceeded
26
* Deadlock found when trying to get lock
30
if not proxy.global.trxs then
31
proxy.global.trxs = { }
34
function read_query(packet)
35
if packet:byte() ~= proxy.COM_QUERY then return end
37
if not proxy.global.trxs[proxy.connection.server.thread_id] then
38
proxy.global.trxs[proxy.connection.server.thread_id] = { }
41
proxy.queries:append(1, packet, { resultset_is_needed = true })
43
local t = proxy.global.trxs[proxy.connection.server.thread_id]
45
t[#t + 1] = packet:sub(2)
47
return proxy.PROXY_SEND_QUERY
50
function read_query_result(inj)
51
local res = inj.resultset
52
local flags = res.flags
54
if res.query_status == proxy.MYSQLD_PACKET_ERR then
55
local err_code = res.raw:byte(2) + (res.raw:byte(3) * 256)
56
local err_sqlstate = res.raw:sub(5, 9)
57
local err_msg = res.raw:sub(10)
58
-- print("-- error-packet: " .. err_code)
60
if err_code == 1205 or -- Lock wait timeout exceeded
61
err_code == 1213 then -- Deadlock found when trying to get lock
62
print(("[%d] received a ERR(%d, %s), dumping all active transactions"):format(
63
proxy.connection.server.thread_id,
67
for thread_id, statements in pairs(proxy.global.trxs) do
68
for stmt_id, statement in ipairs(statements) do
69
print((" [%d].%d: %s"):format(thread_id, stmt_id, statement))
75
-- we are done, free the statement list
76
if not flags.in_trans then
77
proxy.global.trxs[proxy.connection.server.thread_id] = nil
81
function disconnect_client()
82
proxy.global.trxs[proxy.connection.server.thread_id] = nil