From 80cce99ebc9ced8b6af0af3fa813af8ea4241454 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Wed, 2 Apr 2014 17:20:11 +0000 Subject: [PATCH] SOLR-5795: harden leader check to log cleanly (no NPE) in transient situations when there is no leader due to election in progress git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1584097 13f79535-47bb-0310-9956-ffa450edef68 --- .../DocExpirationUpdateProcessorFactory.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java index 756f0f3b7ab..a006ebbb257 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java @@ -23,7 +23,7 @@ import org.apache.solr.common.SolrException; import static org.apache.solr.common.SolrException.ErrorCode.*; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; import org.apache.solr.core.CloseHook; @@ -469,7 +469,17 @@ public final class DocExpirationUpdateProcessorFactory List slices = new ArrayList(zk.getClusterState().getActiveSlices(col)); Collections.sort(slices, COMPARE_SLICES_BY_NAME); - String leaderInCharge = slices.get(0).getLeader().getName(); + if (slices.isEmpty()) { + log.error("Collection {} has no active Slices?", col); + return false; + } + Replica firstSliceLeader = slices.get(0).getLeader(); + if (null == firstSliceLeader) { + log.warn("Slice in charge of periodic deletes for {} does not currently have a leader", + col); + return false; + } + String leaderInCharge = firstSliceLeader.getName(); String myCoreNodeName = desc.getCoreNodeName(); boolean inChargeOfDeletesRightNow = leaderInCharge.equals(myCoreNodeName);