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
This commit is contained in:
Mark Robert Miller 2012-12-09 00:16:17 +00:00
parent 452a32f314
commit 9075acd9be
1 changed files with 8 additions and 2 deletions

View File

@ -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.");