You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ca...@apache.org on 2016/11/20 23:41:37 UTC
curator git commit: CURATOR-358 - Fixed race condition with
getLeader() -If leadership changes between the getParticipantNodes() call and
the getLeader() internal call the NoNodeException is now handled and the next
child in the list is evaluated.
Repository: curator
Updated Branches:
refs/heads/CURATOR-358 [created] 3478aca7e
CURATOR-358 - Fixed race condition with getLeader()
-If leadership changes between the getParticipantNodes() call and the getLeader() internal call the NoNodeException is now handled and the next child in the list is evaluated.
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/3478aca7
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/3478aca7
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/3478aca7
Branch: refs/heads/CURATOR-358
Commit: 3478aca7ed6852484b5574a6082f4bb75c04a1e0
Parents: e9bfb43
Author: Cam McKenzie <ca...@apache.org>
Authored: Mon Nov 21 10:38:15 2016 +1100
Committer: Cam McKenzie <ca...@apache.org>
Committed: Mon Nov 21 10:38:15 2016 +1100
----------------------------------------------------------------------
.../recipes/leader/LeaderSelector.java | 35 ++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/3478aca7/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
index c177302..4b4a0b4 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.Callable;
@@ -341,11 +342,41 @@ public class LeaderSelector implements Closeable
static Participant getLeader(CuratorFramework client, Collection<String> participantNodes) throws Exception
{
+ Participant result = null;
+
if ( participantNodes.size() > 0 )
{
- return participantForPath(client, participantNodes.iterator().next(), true);
+ Iterator<String> iter = participantNodes.iterator();
+ while ( iter.hasNext() )
+ {
+
+ try
+ {
+ result = participantForPath(client, iter.next(), true);
+ }
+ catch( KeeperException.NoNodeException e )
+ {
+ //See CURATOR-358
+ //There's a race condition between querying the list of
+ //leader nodes and then determining the content of the
+ //actual leader node. If the query fails due to the
+ //node not existing, then just move to the next
+ //participant node and try again
+ }
+
+ if ( result != null )
+ {
+ break;
+ }
+ }
+ }
+
+ if( result == null )
+ {
+ result = new Participant();
}
- return new Participant();
+
+ return result;
}
/**