current mysql-proxy
dpkg -l | grep mysql-proxy
ii mysql-proxy 0.8.0-1.2 high availability, load balancing and query modification for mysql
I have followed lots of tutorial found online soem are on the following links
http://dev.mysql.com/doc/refman/5.1/en/mysql-proxy-scripting-read-query-result.html
http://theory.uwinnipeg.ca/mysql/mysql-proxy.html#mysql-proxy-scripting-connect-server
I cannot seem to find a lua script that combines ro-balance and rw-splitting.
What I am testing out is how to execute show slave status in lua within mysql proxy.
the following is my test file
function connect_server()
print("--> a client really wants to talk to a server")
if (tonumber(os.date("%M")) % 2 == 0) then
proxy.connection.backend_ndx = 2
print("Choosing backend 2")
else
proxy.connection.backend_ndx = 1
print("Choosing backend 1")
end
print("Using " .. proxy.global.backends[proxy.connection.backend_ndx].dst.name)
end
function read_query( packet )
if packet:byte() == proxy.COM_QUERY then
proxy.queries:append(5, string.char(proxy.COM_QUERY) .. "SHOW SLAVE STATUS", {resultset_is_needed = true} )
--, {resultset_is_needed = true} )
proxy.queries:append(1, packet, {resultset_is_needed = true})
proxy.queries:append(5, string.char(proxy.COM_QUERY) .. "SHOW SLAVE STATUS", {resultset_is_needed = true} )
return proxy.PROXY_SEND_QUERY
end
end
function read_query_result(inj)
if inj.id == 5 then
-- for row in inj.resultset.rows do
-- print("injected query returned: " .. row[1])
-- end
local res = inj.resultset
local fields = res.fields
local show_slave_status = {}
-- turn the resultset into local hash
for row in res.rows do
for field_id, field in pairs(row) do
show_slave_status[fields[field_id].name] = tostring(field)
if config.is_debug then
print(("[%d] '%s' = '%s'"):format(field_id, fields[field_id].name, tostring(field)))
end
end
end
return proxy.PROXY_IGNORE_RESULT
else
-- print("query-time: " .. (inj.query_time / 1000) .. "ms")
-- print("response-time: " .. (inj.response_time / 1000) .. "ms")
end
end
This produces an error in the log file and does not return anything from the database. However if i change the "SHOW SLAVE STATUS" TO "SELECT NOW()" it works fine. How do i get to execute show slave status.
error is
2011-07-05 17:51:58: (critical) (read_query_result) [string "/usr/share/mysql-proxy/test.lua"]:48: attempt to call a nil value
2011-07-05 17:51:58: (critical) proxy-plugin.c.303: got asked to send a resultset, but ignoring it as we already have sent 2 resultset(s). injection-id: 5
or can be
2011-07-05 17:45:31: (critical) (read_query_result) [string "/usr/share/mysql-proxy/test.lua"]:47: .resultset.fields isn't available if 'resultset_is_needed ~= true'
2011-07-05 17:45:31: (critical) proxy-plugin.c:1235: proxy.queries:append() in /usr/share/mysql-proxy/test.lua can only have one injected query without { resultset_is_needed = true } set. We close the client connection now.
Does anyone know how to do this as there are no good documentation or samples on how to get this to work.
My overall goal is to combine rw-splitting and ro-balance in one lua script.
Edited 1 time(s). Last edit at 07/06/2011 02:18AM by sharif uddin.