Bug #38785 Clarification of retriesAllDown parameter
Submitted: 13 Aug 2008 21:53 Modified: 26 Jun 2013 21:21
Reporter: Todd Farmer (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.6 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any

[13 Aug 2008 21:53] Todd Farmer
Description:
The retriesAllDown parameter isn't documented (and isn't part of ConnectionPropertiesImpl.java).  The release notes aren't specific on the intended behavior:

We solve this problem with a black list that is used during the picking of new hosts. If the black list ends up including all configured hosts, the driver will retry for a configurable number of times (the retriesAllDown  configuration property, with a default of 120 times), sleeping 250ms between attempts to pick a new connection. 

The way this is implemented in both Random and BestResponse starts compares the number of connections attempted against retriesAllDown.  If retriesAllDown is less than the number of servers in the server list, it could exhaust the number of attempts against unavailable servers, never attempting to check available servers.

How to repeat:
Start one server on localhost:3310, then repeatedly run:

			Class.forName ("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection ( "jdbc:mysql:loadbalance://localhost:3310,localhost:3311/test?retriesAllDown=1", "root", null);

Suggested fix:
1.  Add retriesAllDown to ConnectionPropertiesImpl.java
2.  Redefine and reimplement retriesAllDown to control the number of times C/J will cycle through the *full* list of servers.

Changes:

for (int attempts = 0; attempts < numRetries; attempts++) {
...

becomes:

for (int attempts = 0; attempts < numRetries;) {
...

and the cases where no available servers are found should increment attempts instead:

if (blackList.size() == configuredHosts.size()) {
  attempts++
...

and 

if (whiteList.size() == 0) {
  attempts++
...

in BestResponseTimeBalanceStrategy and RandomBalanceStrategy, respectively.
[26 Jun 2013 21:21] Daniel So
Added entry to changelog of version 5.1.7:

"When using loadbalancing, Connector/J might not cycle through the whole list of configured hosts in its attempt to make a connection. This fix corrects the implementation of the configuration parameter 'retriesAllDown,' making sure that Connector/J cycles through the whole list of hosts for each of its attempt to connect."