From 9075acd9be063ebe08d03002511adda9d2101844 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Sun, 9 Dec 2012 00:16:17 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1418790 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/solr/cloud/ElectionContext.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 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.");