Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5380318DEB for ; Tue, 1 Sep 2015 13:27:54 +0000 (UTC) Received: (qmail 31479 invoked by uid 500); 1 Sep 2015 13:27:54 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 31260 invoked by uid 500); 1 Sep 2015 13:27:54 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 30677 invoked by uid 99); 1 Sep 2015 13:27:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2015 13:27:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B1B4EDFF82; Tue, 1 Sep 2015 13:27:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Tue, 01 Sep 2015 13:28:09 -0000 Message-Id: <0d208bd919a249e3809b05d0e15af358@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [17/45] curator git commit: When the connection timeout elapses and there is more than one server in the connection string, reset the connection and try again When the connection timeout elapses and there is more than one server in the connection string, reset the connection and try again Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/05d241da Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/05d241da Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/05d241da Branch: refs/heads/CURATOR-248 Commit: 05d241da642c6ba0d16b3ce97557128fad4dfe41 Parents: 2355447 Author: randgalt Authored: Sat Aug 22 20:32:41 2015 -0500 Committer: randgalt Committed: Sat Aug 22 20:32:41 2015 -0500 ---------------------------------------------------------------------- .../src/main/java/org/apache/curator/RetryLoop.java | 5 +++++ .../curator/connection/ConnectionHandlingPolicy.java | 5 +++++ .../connection/StandardConnectionHandlingPolicy.java | 13 ++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/05d241da/curator-client/src/main/java/org/apache/curator/RetryLoop.java ---------------------------------------------------------------------- diff --git a/curator-client/src/main/java/org/apache/curator/RetryLoop.java b/curator-client/src/main/java/org/apache/curator/RetryLoop.java index 35d55a1..a17cbf3 100644 --- a/curator-client/src/main/java/org/apache/curator/RetryLoop.java +++ b/curator-client/src/main/java/org/apache/curator/RetryLoop.java @@ -121,6 +121,11 @@ public class RetryLoop break; } + case WAIT_FOR_CONNECTION: + { + break; // just loop + } + case EXIT_RETRIES: { retryLoop.markComplete(); http://git-wip-us.apache.org/repos/asf/curator/blob/05d241da/curator-client/src/main/java/org/apache/curator/connection/ConnectionHandlingPolicy.java ---------------------------------------------------------------------- diff --git a/curator-client/src/main/java/org/apache/curator/connection/ConnectionHandlingPolicy.java b/curator-client/src/main/java/org/apache/curator/connection/ConnectionHandlingPolicy.java index f3ecce6..7f19159 100644 --- a/curator-client/src/main/java/org/apache/curator/connection/ConnectionHandlingPolicy.java +++ b/curator-client/src/main/java/org/apache/curator/connection/ConnectionHandlingPolicy.java @@ -63,6 +63,11 @@ public interface ConnectionHandlingPolicy CALL_PROC, /** + * Wait again for connection success or timeout + */ + WAIT_FOR_CONNECTION, + + /** * Do not call the procedure and exit the retry loop */ EXIT_RETRIES, http://git-wip-us.apache.org/repos/asf/curator/blob/05d241da/curator-client/src/main/java/org/apache/curator/connection/StandardConnectionHandlingPolicy.java ---------------------------------------------------------------------- diff --git a/curator-client/src/main/java/org/apache/curator/connection/StandardConnectionHandlingPolicy.java b/curator-client/src/main/java/org/apache/curator/connection/StandardConnectionHandlingPolicy.java index 06285ca..cbbceac 100644 --- a/curator-client/src/main/java/org/apache/curator/connection/StandardConnectionHandlingPolicy.java +++ b/curator-client/src/main/java/org/apache/curator/connection/StandardConnectionHandlingPolicy.java @@ -1,10 +1,15 @@ package org.apache.curator.connection; +import com.google.common.base.Splitter; import org.apache.curator.CuratorZookeeperClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.Callable; public class StandardConnectionHandlingPolicy implements ConnectionHandlingPolicy { + private final Logger log = LoggerFactory.getLogger(getClass()); + @Override public boolean isEmulatingClassicHandling() { @@ -24,9 +29,15 @@ public class StandardConnectionHandlingPolicy implements ConnectionHandlingPolic @Override public PreRetryResult preRetry(CuratorZookeeperClient client) throws Exception { - // TODO - see if there are other servers to connect to if ( !client.isConnected() ) { + int serverCount = Splitter.on(",").omitEmptyStrings().splitToList(client.getCurrentConnectionString()).size(); + if ( serverCount > 1 ) + { + log.info("Connection timed out and connection string is > 1. Resetting connection and trying again."); + client.reset(); // unfortunately, there's no way to guarantee that ZK tries a different server. Internally it calls Collections.shuffle(). Hopefully, this will result in a different server each time. + return PreRetryResult.WAIT_FOR_CONNECTION; + } return PreRetryResult.CONNECTION_TIMEOUT; }