Description:
Hi,
I'm fail to implement failover because I cann't get the right backend state. It alway trys to connect to the first backend, even if I shut down the Mysql service or disable the network connection.
The lua like that:
function connect_server()
print("s backend_ndx = " .. proxy.connection.backend_ndx)
print("s state = " .. proxy.global.backends[1].state)
if proxy.global.backends[1].state == proxy.BACKEND_STATE_DOWN then
proxy.connection.backend_ndx = 2
else
proxy.connection.backend_ndx = 1
end
print("s backend_ndx = " .. proxy.connection.backend_ndx)
print ("s Connecting: " .. proxy.global.backends[proxy.connection.backend_ndx].dst.name)
end
function read_query(packet)
print("q backend_ndx = " .. proxy.connection.backend_ndx)
print("q state = " .. proxy.global.backends[1].state)
if proxy.global.backends[1].state == proxy.BACKEND_STATE_DOWN then
proxy.connection.backend_ndx = 2
else
proxy.connection.backend_ndx = 1
end
print("q backend_ndx = " .. proxy.connection.backend_ndx)
print ("q Connecting: " .. proxy.global.backends[proxy.connection.backend_ndx].dst.name)
end
How to repeat:
case 1:
the config file like that:
[mysql-proxy]
proxy-backend-addresses=192.168.0.134:3306,192.168.0.100:3306
log-file=mysql-proxy.log
log-level=debug
log-back-trace-on-crash=true
pid-file=mysql-proxy.pid
proxy-lua-script=d:/mysql-proxy/lib/mysql-proxy/lua/failover.lua
1. Run Mysql Proxy on 192.168.0.100 by mysql-proxy --defaults-file=d:/mysql-proxy/mysql-proxy.cnf.
2. Connect to Mysql Proxy by mysql -uroot -p123456 -P4040.
3. Mysql Proxy showes:
s backend_ndx = 0
s state = 0
s backend_ndx = 1
s Connecting: 192.168.0.134:3306
q backend_ndx = 1
q state = 1
q backend_ndx = 1
q Connecting: 192.168.0.134:3306
4. Disable the network connection to 192.168.0.134.
5. Repeat step 2, and then the client is waiting whitout any information, and Mysql Proxy showes:
s backend_ndx = 0
s state = 1
s backend_ndx = 1
s Connecting: 192.168.0.134:3306
I waited several minutes, but nothing happen.
======================================
case 2:
the config file like that:
[mysql-proxy]
proxy-backend-addresses=192.168.0.100:3306,192.168.0.134:3306 # only change
log-file=mysql-proxy.log
log-level=debug
log-back-trace-on-crash=true
pid-file=mysql-proxy.pid
proxy-lua-script=d:/mysql-proxy/lib/mysql-proxy/lua/failover.lua
1. Run Mysql Proxy on 192.168.0.100 by mysql-proxy --defaults-file=d:/mysql-proxy/mysql-proxy.cnf.
2. Connect to Mysql Proxy by mysql -uroot -p123456 -P4040.
3. Mysql Proxy showes:
s backend_ndx = 0
s state = 0
s backend_ndx = 1
s Connecting: 192.168.0.100:3306
q backend_ndx = 1
q state = 1
q backend_ndx = 1
q Connecting: 192.168.0.100:3306
4. Shut down the Mysql service on 192.168.0.100.
5. Repeat step 2, and then the client is waiting whitout any information, and Mysql Proxy showes:
s backend_ndx = 0
s state = 1
s backend_ndx = 1
s Connecting: 192.168.0.100:3306
I waited several minutes, but nothing happen.
Suggested fix:
Can Mysql proxy keep watch over on all the backends, and then change the state?