Apache Lucene open-source search software
SOLR-4159: When we are starting a shard from rest, a potential leader should not consider it's last published state when deciding if it can be the new leader.
Mark Robert Miller9075acd9be06
diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.javaindex 9e92584cff6..2799f01a02a 100644--- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java+++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java@@ -163,7 +163,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {}// should I be leader?- if (weAreReplacement && !shouldIBeLeader(leaderProps, core)) {+ if (weAreReplacement && !shouldIBeLeader(leaderProps, core, weAreReplacement)) {rejoinLeaderElection(leaderSeqPath, core);return;}@@ -351,7 +351,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {leaderElector.joinElection(this, true);}- private boolean shouldIBeLeader(ZkNodeProps leaderProps, SolrCore core) {+ private boolean shouldIBeLeader(ZkNodeProps leaderProps, SolrCore core, boolean weAreReplacement) {log.info("Checking if I should try and be the leader.");if (isClosed) {@@ -359,6 +359,12 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {return false;}+ if (!weAreReplacement) {+ // we are the first node starting in the shard - there is a configurable wait+ // to make sure others participate in sync and leader election, we can be leader+ return true;+ }+if (core.getCoreDescriptor().getCloudDescriptor().getLastPublished().equals(ZkStateReader.ACTIVE)) {log.info("My last published State was Active, it's okay to be the leader.");