Bug #75169 Add the failedOver SQLException matches condition like load balancing drive
Submitted: 11 Dec 2014 4:05 Modified: 23 Mar 2015 17:45
Reporter: Aiden Zhang Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S4 (Feature request)
Version:5.1.34 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: failedOver, SQLException matches condition

[11 Dec 2014 4:05] Aiden Zhang
Description:
I check that the FailoverConnectionProxy do failover when any exception happends, but sometimes I just want let it failover just when some given conditions, like some SQLException like the load balancing JDBC driver.

How to repeat:
JDBC URL,

"jdbc:mysql://10.228.169.99:3306,10.228.169.100:3306/rad_wifi?user=aicent&password=aicent&allowMasterDownConnections=false&autoReconnectForPools=true&secondsBeforeRetryMaster=10&failOverReadOnly=false&loadBalanceExceptionChecker=com.aicent.wifi.jdbc.ha.MyLoadBalanceExceptionChecker&retriesAllDown=10";

note that, it is a failOver JDBC, not the load balancing JDBC.
not the prefix, jdbc:mysql:loadbalance://

Suggested fix:
File: FailoverConnectionProxy.java
Method:
 synchronized void dealWithInvocationException(InvocationTargetException e)

Improvement:
        if (t != null) {

		if (this.failedOver) { // try and fall back
                    createPrimaryConnection();

                    if (this.currentConn != null) {
                        throw t;
                    }
                }
			
                failOver();

            throw t;
        }

changed to,

        if (t != null) {
           if (t instanceof SQLException && shouldExceptionTriggerFailover((SQLException) t)) {

		if (this.failedOver) { // try and fall back
                    createPrimaryConnection();

                    if (this.currentConn != null) {
                        throw t;
                    }
                }
			
                failOver();
	       }

            throw t;
        }
[12 Dec 2014 14:28] Filipe Silva
Hi Aiden,

Thank you for this feature request report.