diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 638acc0d846..9e6ffb9ec47 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -144,6 +144,8 @@ Bug Fixes * SOLR-9028: Fixed some test related bugs preventing SSL + ClientAuth from ever being tested (hossman) +* SOLR-9059: NPE in SolrClientCache following collection reload (Joel Bernstein, Ryan Yacyshyn) + Optimizations ---------------------- * SOLR-8722: Don't force a full ZkStateReader refresh on every Overseer operation. diff --git a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java index 9eca6db26b8..bf111d67e7e 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java @@ -30,6 +30,8 @@ import org.apache.solr.client.solrj.io.stream.ExceptionStream; import org.apache.solr.client.solrj.io.stream.SolrStream; import org.apache.solr.client.solrj.io.stream.TupleStream; import org.apache.solr.cloud.AbstractFullDistribZkTestBase; +import org.apache.solr.common.cloud.DocCollection; +import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.params.CommonParams; import org.junit.After; import org.junit.AfterClass; @@ -424,6 +426,36 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase { assert(tuple.getLong("myInt") == 7); assert(tuple.get("myString").equals("a")); + //Test after reload SOLR-9059// + Replica leader = getShardLeader("collection1", "shard1", 30 /* timeout secs */); + + // reload collection and wait to see the core report it has been reloaded + boolean wasReloaded = reloadCollection(leader, "collection1"); + assertTrue(wasReloaded); + + params = new HashMap(); + params.put(CommonParams.QT, "/sql"); + params.put("stmt", "select id as myId, field_i as myInt, str_s as myString from collection1 where text='XXXX' AND id='(1 2 3)' order by field_i desc"); + + solrStream = new SolrStream(jetty.url, params); + tuples = getTuples(solrStream); + + assert(tuples.size() == 3); + + tuple = tuples.get(0); + assert(tuple.getLong("myId") == 3); + assert(tuple.getLong("myInt") == 20); + assert(tuple.get("myString").equals("a")); + + tuple = tuples.get(1); + assert(tuple.getLong("myId") == 2); + assert(tuple.getLong("myInt") == 8); + assert(tuple.get("myString").equals("b")); + + tuple = tuples.get(2); + assert(tuple.getLong("myId") == 1); + assert(tuple.getLong("myInt") == 7); + assert(tuple.get("myString").equals("a")); } finally { delete(); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java index cd992a4215c..da9416211d1 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java @@ -66,7 +66,7 @@ public class SolrClientCache implements Serializable { return client; } - public void close() { + public synchronized void close() { for(Map.Entry entry : solrClients.entrySet()) { try { entry.getValue().close(); @@ -74,5 +74,6 @@ public class SolrClientCache implements Serializable { log.error("Error closing SolrClient for " + entry.getKey(), e); } } + solrClients.clear(); } }