Bug #64655 Mysql Proxy doesn't check the state of the backend correctly

Submitted: 15 Mar 2012 9:55 Modified: 15 Jun 2012 19:09
Reporter: Tank W Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Proxy Severity:S3 (Non-critical)
Version:0.8.2 OS:Windows (windows server 2008 32bit)
Assigned to: CPU Architecture:Any

[15 Mar 2012 9:55] Tank W
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?
[15 Jun 2012 19:09] Sveta Smirnova
Thank you for the report.

You use wrong backend_ndx: try 0 and 1. This is not MySQL Proxy bug.
[21 Jul 2015 12:28] arjun palwai
I am using mysql proxy 0.8.1.I am using the files admin.lua and reporter.lua.When i use the administrative interface,SELECT * FROM backends gives backend state as 0 ,show querycounter gives NULL and show proxy processlist gives error.How do i ensure that mysqlproxy is balancing the load??

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.