Skip to content

Apache Lucene open-source search software

SOLR-10524: Build fix for NPE

Scott Blum972e342fee7a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index de3ce0bb1a5..cdbbcc8d217 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -256,7 +256,7 @@ Optimizations
* SOLR-10548: JSON Facet API now uses hyper-log-log++ for determining the number of buckets
when merging requests from a multi-shard distributed request. (yonik)
-* SOLR-10524: Explore in-memory partitioning for processing Overseer queue messages (Cao Manh Dat, Noble Paul, shalin, Scott Blum)
+* SOLR-10524: Better ZkStateWriter batching (Cao Manh Dat, Noble Paul, shalin, Scott Blum)
Bug Fixes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java b/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
index 48d2ecb6363..da0f57c4eb2 100644
--- a/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
+++ b/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
@@ -166,6 +166,9 @@ public class ZkStateWriter {
* @return true if a flush is required, false otherwise
*/
protected boolean maybeFlushBefore(ZkWriteCommand cmd) {
+ if (cmd.collection == null || lastStateFormat <= 0) {
+ return false;
+ }
return cmd.collection.getStateFormat() != lastStateFormat;
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java
index 85dbf4aba72..f96b5e2adba 100644
--- a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java
@@ -77,7 +77,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
ZkWriteCommand c2 = new ZkWriteCommand("c2",
new DocCollection("c2", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c2"));
- assertTrue("Different (new) collection create cannot be batched together with another create", writer.maybeFlushBefore(c2));
+ assertFalse("Different (new) collection create can be batched together with another create", writer.maybeFlushBefore(c2));
// simulate three state changes on same collection, all should be batched together before
assertFalse(writer.maybeFlushBefore(c1));
@@ -88,13 +88,13 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
assertFalse(writer.maybeFlushAfter(c1));
assertFalse(writer.maybeFlushAfter(c1));
- // simulate three state changes on two different collections with stateFormat=2, none should be batched
+ // simulate three state changes on two different collections with stateFormat=2, all should be batched
assertFalse(writer.maybeFlushBefore(c1));
// flushAfter has to be called as it updates the internal batching related info
assertFalse(writer.maybeFlushAfter(c1));
- assertTrue(writer.maybeFlushBefore(c2));
+ assertFalse(writer.maybeFlushBefore(c2));
assertFalse(writer.maybeFlushAfter(c2));
- assertTrue(writer.maybeFlushBefore(c1));
+ assertFalse(writer.maybeFlushBefore(c1));
assertFalse(writer.maybeFlushAfter(c1));
// create a collection in stateFormat = 1 i.e. inside the main cluster state
@@ -168,7 +168,7 @@ public class ZkStateWriterTest extends SolrTestCaseJ4 {
}
}
- public void testSingleExternalCollection() throws Exception{
+ public void testSingleExternalCollection() throws Exception {
String zkDir = createTempDir("testSingleExternalCollection").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);