SOLR-15085 Prevent EmbeddedSolrServer calling shutdown on a CoreContainer that was passed to it

This commit is contained in:
Tim Owen 2021-01-18 12:45:47 +00:00 committed by Mike Drob
parent 0d4769e174
commit 715caaae52
No known key found for this signature in database
GPG Key ID: 3E48C0C6EF362B9E
8 changed files with 33 additions and 41 deletions

View File

@ -210,6 +210,8 @@ Improvements
--------------------- ---------------------
* SOLR-15081: Metrics for a core: add SolrCloud "isLeader" and "replicaState". (David Smiley) * SOLR-15081: Metrics for a core: add SolrCloud "isLeader" and "replicaState". (David Smiley)
* SOLR-15085: Prevent EmbeddedSolrServer calling shutdown on a CoreContainer that was passed to it. (Tim Owen via Mike Drob)
Optimizations Optimizations
--------------------- ---------------------
* SOLR-15079: Block Collapse - Faster collapse code when groups are co-located via Block Join style nested doc indexing. * SOLR-15079: Block Collapse - Faster collapse code when groups are co-located via Block Join style nested doc indexing.

View File

@ -71,6 +71,7 @@ public class EmbeddedSolrServer extends SolrClient {
protected final String coreName; protected final String coreName;
private final SolrRequestParsers _parser; private final SolrRequestParsers _parser;
private final RequestWriterSupplier supplier; private final RequestWriterSupplier supplier;
private boolean containerIsLocal = false;
public enum RequestWriterSupplier { public enum RequestWriterSupplier {
JavaBin(() -> new BinaryRequestWriter()), XML(() -> new RequestWriter()); JavaBin(() -> new BinaryRequestWriter()), XML(() -> new RequestWriter());
@ -94,6 +95,7 @@ public class EmbeddedSolrServer extends SolrClient {
*/ */
public EmbeddedSolrServer(Path solrHome, String defaultCoreName) { public EmbeddedSolrServer(Path solrHome, String defaultCoreName) {
this(load(new CoreContainer(solrHome, new Properties())), defaultCoreName); this(load(new CoreContainer(solrHome, new Properties())), defaultCoreName);
containerIsLocal = true;
} }
/** /**
@ -104,6 +106,7 @@ public class EmbeddedSolrServer extends SolrClient {
*/ */
public EmbeddedSolrServer(NodeConfig nodeConfig, String defaultCoreName) { public EmbeddedSolrServer(NodeConfig nodeConfig, String defaultCoreName) {
this(load(new CoreContainer(nodeConfig)), defaultCoreName); this(load(new CoreContainer(nodeConfig)), defaultCoreName);
containerIsLocal = true;
} }
private static CoreContainer load(CoreContainer cc) { private static CoreContainer load(CoreContainer cc) {
@ -120,9 +123,6 @@ public class EmbeddedSolrServer extends SolrClient {
/** /**
* Create an EmbeddedSolrServer wrapping a CoreContainer. * Create an EmbeddedSolrServer wrapping a CoreContainer.
* <p>
* Note that EmbeddedSolrServer will shutdown the wrapped CoreContainer when
* {@link #close()} is called.
* *
* @param coreContainer the core container * @param coreContainer the core container
* @param coreName the core to route requests to by default (optional) * @param coreName the core to route requests to by default (optional)
@ -133,8 +133,6 @@ public class EmbeddedSolrServer extends SolrClient {
/** /**
* Create an EmbeddedSolrServer wrapping a CoreContainer. * Create an EmbeddedSolrServer wrapping a CoreContainer.
* <p>
* Note that EmbeddedSolrServer will shutdown the wrapped CoreContainer when {@link #close()} is called.
* *
* @param coreContainer * @param coreContainer
* the core container * the core container
@ -354,12 +352,14 @@ public class EmbeddedSolrServer extends SolrClient {
} }
/** /**
* Shutdown all cores within the EmbeddedSolrServer instance * Closes any resources created by this instance
*/ */
@Override @Override
public void close() throws IOException { public void close() throws IOException {
if (containerIsLocal) {
coreContainer.shutdown(); coreContainer.shutdown();
} }
}
/** /**
* Getter method for the CoreContainer * Getter method for the CoreContainer

View File

@ -955,12 +955,7 @@ public class CoreContainer {
name = "localhost"; name = "localhost";
} }
cloudManager = null; cloudManager = null;
client = new EmbeddedSolrServer(this, null) { client = new EmbeddedSolrServer(this, null);
@Override
public void close() throws IOException {
// do nothing - we close the container ourselves
}
};
// enable local metrics unless specifically set otherwise // enable local metrics unless specifically set otherwise
initArgs.putIfAbsent(MetricsHistoryHandler.ENABLE_NODES_PROP, true); initArgs.putIfAbsent(MetricsHistoryHandler.ENABLE_NODES_PROP, true);
initArgs.putIfAbsent(MetricsHistoryHandler.ENABLE_REPLICAS_PROP, true); initArgs.putIfAbsent(MetricsHistoryHandler.ENABLE_REPLICAS_PROP, true);

View File

@ -58,13 +58,7 @@ public abstract class AbstractAtomicUpdatesMultivalueTestBase extends EmbeddedSo
@Override @Override
public synchronized EmbeddedSolrServer getSolrClient() { public synchronized EmbeddedSolrServer getSolrClient() {
return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME, getRequestWriterSupplier()) { return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME, getRequestWriterSupplier());
@Override
public void close() {
// do not close core container
}
};
} }
private static void assertQR(final String fieldName, final String queryValue, final int numFound) { private static void assertQR(final String fieldName, final String queryValue, final int numFound) {

View File

@ -38,6 +38,17 @@ Detailed steps for upgrading a Solr cluster are in the section <<upgrading-a-sol
If you are upgrading from 7.x, see the section <<Upgrading from 7.x Releases>> below. If you are upgrading from 7.x, see the section <<Upgrading from 7.x Releases>> below.
=== Solr 8.9
See the https://cwiki.apache.org/confluence/display/SOLR/ReleaseNote89[8.9 Release Notes^]
for an overview of the main new features of Solr 8.9.
When upgrading to 8.9.x users should be aware of the following major changes from 8.8.
*Embedded Solr Server*
* When using EmbeddedSolrServer, it will no longer close CoreContainer instances that were passed to it.
=== Solr 8.8 === Solr 8.8
See the https://cwiki.apache.org/confluence/display/SOLR/ReleaseNote88[8.8 Release Notes^] See the https://cwiki.apache.org/confluence/display/SOLR/ReleaseNote88[8.8 Release Notes^]

View File

@ -61,10 +61,10 @@ public class TestEmbeddedSolrServer extends AbstractEmbeddedSolrServerTestCase {
solrServer.close(); solrServer.close();
Assert.assertEquals(0, cores.getCores().size()); Assert.assertEquals(3, cores.getCores().size());
for (SolrCore solrCore : solrCores) { for (SolrCore solrCore : solrCores) {
Assert.assertEquals(true, solrCore.isClosed()); Assert.assertEquals(false, solrCore.isClosed());
} }
} }

View File

@ -75,12 +75,7 @@ public class DirectJsonQueryRequestFacetingEmbeddedTest extends EmbeddedSolrServ
final String schema = tempSolrHome.getAbsolutePath() + "/" + COLLECTION_NAME + "/conf/managed-schema"; final String schema = tempSolrHome.getAbsolutePath() + "/" + COLLECTION_NAME + "/conf/managed-schema";
initCore(config, schema, tempSolrHome.getAbsolutePath(), COLLECTION_NAME); initCore(config, schema, tempSolrHome.getAbsolutePath(), COLLECTION_NAME);
client = new EmbeddedSolrServer(h.getCoreContainer(), COLLECTION_NAME) { client = new EmbeddedSolrServer(h.getCoreContainer(), COLLECTION_NAME);
@Override
public void close() {
// do not close core container
}
};
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
up.setParam("collection", COLLECTION_NAME); up.setParam("collection", COLLECTION_NAME);

View File

@ -72,12 +72,7 @@ abstract public class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 {
* Create a new solr client. Subclasses should override for other options. * Create a new solr client. Subclasses should override for other options.
*/ */
public EmbeddedSolrServer createNewSolrClient() { public EmbeddedSolrServer createNewSolrClient() {
return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME) { return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME);
@Override
public void close() {
// do not close core container
}
};
} }
public void upload(final String collection, final ContentStream... contents) { public void upload(final String collection, final ContentStream... contents) {