From 5dbff1d1c1d5a1ebf91df58df7daa59a26394c7d Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 25 Nov 2014 11:49:36 +0000 Subject: [PATCH] SOLR-6763: Shard leader elections should not persist across ZK session expiry git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1641590 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 +++ .../apache/solr/cloud/ElectionContext.java | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index baead9f1770..bbe20c8a13e 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -299,6 +299,9 @@ Bug Fixes * SOLR-3774: Solr adds RequestHandler SolrInfoMBeans twice to the JMX server. (Tomás Fernández Löbbe, hossman, Mark Miller) +* SOLR-6763: Shard leader elections should not persist across session expiry + (Alan Woodward, Mark Miller) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java index 41913438c0e..8a4278d360d 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java @@ -1,9 +1,5 @@ package org.apache.solr.cloud; -import java.io.Closeable; -import java.io.IOException; -import java.util.concurrent.TimeUnit; - import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -28,6 +24,7 @@ import org.apache.zookeeper.KeeperException.NodeExistsException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.Closeable; import java.io.IOException; import java.util.List; import java.util.concurrent.ExecutorService; @@ -136,13 +133,12 @@ class ShardLeaderElectionContextBase extends ElectionContext { try { RetryUtil.retryOnThrowable(NodeExistsException.class, 15000, 1000, new RetryCmd() { - @Override public void execute() throws Throwable { - zkClient.makePath(leaderPath, ZkStateReader.toJSON(leaderProps), - CreateMode.EPHEMERAL, true); + zkClient.makePath(leaderPath, ZkStateReader.toJSON(leaderProps), CreateMode.EPHEMERAL, true); } - }); + } + ); } catch (Throwable t) { if (t instanceof OutOfMemoryError) { throw (OutOfMemoryError) t; @@ -407,13 +403,19 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase { Slice slices = zkController.getClusterState().getSlice(collection, shardId); int cnt = 0; - while (true && !isClosed && !cc.isShutDown()) { + while (!isClosed && !cc.isShutDown()) { // wait for everyone to be up if (slices != null) { int found = 0; try { found = zkClient.getChildren(shardsElectZkPath, null, true).size(); } catch (KeeperException e) { + if (e instanceof KeeperException.SessionExpiredException) { + // if the session has expired, then another election will be launched, so + // quit here + throw new SolrException(ErrorCode.SERVER_ERROR, + "ZK session expired - cancelling election for " + collection + " " + shardId); + } SolrException.log(log, "Error checking for the number of election participants", e); }