Skip to content

Apache Lucene open-source search software

SOLR-6880: Harden ZkStateReader to expect that getCollectionLive may return null as it's contract states.

Mark Robert Millerbba930a5b3ab
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index fca58ddabf5..8e12f573dba 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -413,6 +413,8 @@ Bug Fixes
* SOLR-6907: URLEncode documents directory in MorphlineMapperTest to handle spaces etc.
in file name. (Ramkumar Aiyengar via Erick Erickson)
+* SOLR-6880: Harden ZkStateReader to expect that getCollectionLive may return null
+ as it's contract states. (Mark Miller, shalin)
Optimizations
----------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index 01ae2657655..09d710561ca 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -273,6 +273,7 @@ public class ZkStateReader implements Closeable {
if (collection.getZNodeVersion() < version) {
log.debug("server older than client {}<{}", collection.getZNodeVersion(), version);
DocCollection nu = getCollectionLive(this, coll);
+ if (nu == null) return null;
if (nu.getZNodeVersion() > collection.getZNodeVersion()) {
updateWatchedCollection(nu);
collection = nu;
@@ -454,9 +455,12 @@ public class ZkStateReader implements Closeable {
synchronized (this) {
if (watchedCollections.contains(s)) {
DocCollection live = getCollectionLive(this, s);
- watchedCollectionStates.put(s, live);
- // if it is a watched collection, add too
- result.put(s, new ClusterState.CollectionRef(live));
+ assert live != null;
+ if (live != null) {
+ watchedCollectionStates.put(s, live);
+ // if it is a watched collection, add too
+ result.put(s, new ClusterState.CollectionRef(live));
+ }
} else {
// if it is not collection, then just create a reference which can fetch
// the collection object just in time from ZK
@@ -527,7 +531,11 @@ public class ZkStateReader implements Closeable {
}
synchronized (ZkStateReader.this) {
for (String watchedCollection : watchedCollections) {
- updateWatchedCollection(getCollectionLive(this, watchedCollection));
+ DocCollection live = getCollectionLive(this, watchedCollection);
+ assert live != null;
+ if (live != null) {
+ updateWatchedCollection(live);
+ }
}
}
@@ -585,7 +593,11 @@ public class ZkStateReader implements Closeable {
synchronized (ZkStateReader.this) {
for (String watchedCollection : watchedCollections) {
- updateWatchedCollection(getCollectionLive(ZkStateReader.this, watchedCollection));
+ DocCollection live = getCollectionLive(ZkStateReader.this, watchedCollection);
+ assert live != null;
+ if (live != null) {
+ updateWatchedCollection(live);
+ }
}
}
}
@@ -878,7 +890,10 @@ public class ZkStateReader implements Closeable {
};
zkClient.exists(fullpath, watcher, true);
}
- updateWatchedCollection(getCollectionLive(this, coll));
+ DocCollection collection = getCollectionLive(this, coll);
+ if (collection != null) {
+ updateWatchedCollection(collection);
+ }
}
private void updateWatchedCollection(DocCollection newState) {