Skip to content

Apache Lucene open-source search software

SOLR-4734: Leader election fails with an NPE if there is no UpdateLog

Mark Robert Miller93d7c7ae6ba6
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8854d0ca88e..fe087f6d3e9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -110,6 +110,9 @@ Bug Fixes
* SOLR-4796: zkcli.sh should honor JAVA_HOME (Roman Shaposhnik via Mark Miller)
+* SOLR-4734: Leader election fails with an NPE if there is no UpdateLog.
+ (Mark Miller, Alexander Eibner)
+
Other Changes
----------------------
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 8194ffdbb3e..d34aa34e493 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
@@ -172,8 +172,6 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
}
log.info("I may be the new leader - try and sync");
-
- UpdateLog ulog = core.getUpdateHandler().getUpdateLog();
// we are going to attempt to be the leader
@@ -187,7 +185,9 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
success = false;
}
- if (!success && ulog.getRecentUpdates().getVersions(1).isEmpty()) {
+ UpdateLog ulog = core.getUpdateHandler().getUpdateLog();
+
+ if (!success && (ulog == null || ulog.getRecentUpdates().getVersions(1).isEmpty())) {
// we failed sync, but we have no versions - we can't sync in that case
// - we were active
// before, so become leader anyway