Github user sudheeshkatkam commented on a diff in the pull request: https://github.com/apache/drill/pull/679#discussion_r91768005 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java --- @@ -357,10 +357,54 @@ protected void afterExecute(final Runnable r, final Throwable t) { super.afterExecute(r, t); } }; - client = new UserClient(clientName, config, supportComplexTypes, allocator, eventLoopGroup, executor); - logger.debug("Connecting to server {}:{}", endpoint.getAddress(), endpoint.getUserPort()); - connect(endpoint); - connected = true; + + // "tries" is max number of unique drillbit to try connecting until successfully connected to one of them + final String connectTriesConf = (props != null) ? props.getProperty("tries", "5") : "5"; + + int connectTriesVal; + try { + connectTriesVal = Math.min(endpoints.size(), Integer.parseInt(connectTriesConf)); + } catch (NumberFormatException e) { + throw new InvalidConnectionInfoException("Invalid tries value: " + connectTriesConf + " specified in " + + "connection string"); + } + + // If the value provided in the connection string is <=0 then override with 1 since we want to try connecting + // at least once + connectTriesVal = Math.max(1, connectTriesVal); + + int triedEndpointIndex = 0; + DrillbitEndpoint endpoint; + + while (triedEndpointIndex < connectTriesVal) { + client = new UserClient(clientName, config, supportComplexTypes, allocator, eventLoopGroup, executor); + endpoint = endpoints.get(triedEndpointIndex); + logger.debug("Connecting to server {}:{}", endpoint.getAddress(), endpoint.getUserPort()); + + try { + connect(endpoint); + connected = true; + logger.info("Successfully connected to server {}:{}", endpoint.getAddress(), endpoint.getUserPort()); + break; + } catch (InvalidConnectionInfoException ex) { + logger.error("Connection to {}:{} failed with error {}. Not retrying anymore", endpoint.getAddress(), + endpoint.getUserPort(), ex.getMessage()); + throw ex; + } catch (RpcException ex) { + ++triedEndpointIndex; + logger.error("Attempt {}: Failed to connect to server {}:{}", triedEndpointIndex, endpoint.getAddress(), + endpoint.getUserPort()); + + // Close the connection + if (client.isActive()) { --- End diff -- Shouldn't the client be closed regardless of being active? There maybe other resources to close.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---