SOLR-10524: Build fix for NPE

Introduced by ZkStateWriter batching optimizations.
This commit is contained in:
Scott Blum 2017-05-08 20:32:38 -04:00
parent 6f978c5878
commit 972e342fee
3 changed files with 9 additions and 6 deletions

View File

@ -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
----------------------

View File

@ -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;
}

View File

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