From 715caaae52ab3ab548d37e18a173b7d744054257 Mon Sep 17 00:00:00 2001 From: Tim Owen Date: Mon, 18 Jan 2021 12:45:47 +0000 Subject: [PATCH] SOLR-15085 Prevent EmbeddedSolrServer calling shutdown on a CoreContainer that was passed to it --- solr/CHANGES.txt | 2 ++ .../solrj/embedded/EmbeddedSolrServer.java | 14 +++++++------- .../org/apache/solr/core/CoreContainer.java | 7 +------ ...bstractAtomicUpdatesMultivalueTestBase.java | 8 +------- .../solr-ref-guide/src/solr-upgrade-notes.adoc | 11 +++++++++++ .../solrj/embedded/TestEmbeddedSolrServer.java | 18 +++++++++--------- ...ctJsonQueryRequestFacetingEmbeddedTest.java | 7 +------ .../solr/EmbeddedSolrServerTestBase.java | 7 +------ 8 files changed, 33 insertions(+), 41 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 243f32392c3..a199f043495 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -210,6 +210,8 @@ Improvements --------------------- * 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 --------------------- * SOLR-15079: Block Collapse - Faster collapse code when groups are co-located via Block Join style nested doc indexing. diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java index 3c2b490bb29..62cc25e5696 100644 --- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java +++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java @@ -71,6 +71,7 @@ public class EmbeddedSolrServer extends SolrClient { protected final String coreName; private final SolrRequestParsers _parser; private final RequestWriterSupplier supplier; + private boolean containerIsLocal = false; public enum RequestWriterSupplier { JavaBin(() -> new BinaryRequestWriter()), XML(() -> new RequestWriter()); @@ -94,6 +95,7 @@ public class EmbeddedSolrServer extends SolrClient { */ public EmbeddedSolrServer(Path solrHome, String 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) { this(load(new CoreContainer(nodeConfig)), defaultCoreName); + containerIsLocal = true; } private static CoreContainer load(CoreContainer cc) { @@ -120,9 +123,6 @@ public class EmbeddedSolrServer extends SolrClient { /** * Create an EmbeddedSolrServer wrapping a CoreContainer. - *

- * Note that EmbeddedSolrServer will shutdown the wrapped CoreContainer when - * {@link #close()} is called. * * @param coreContainer the core container * @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. - *

- * Note that EmbeddedSolrServer will shutdown the wrapped CoreContainer when {@link #close()} is called. * * @param coreContainer * the core container @@ -354,11 +352,13 @@ public class EmbeddedSolrServer extends SolrClient { } /** - * Shutdown all cores within the EmbeddedSolrServer instance + * Closes any resources created by this instance */ @Override public void close() throws IOException { - coreContainer.shutdown(); + if (containerIsLocal) { + coreContainer.shutdown(); + } } /** diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index b18d2a67009..26bb7d3ac5d 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -955,12 +955,7 @@ public class CoreContainer { name = "localhost"; } cloudManager = null; - client = new EmbeddedSolrServer(this, null) { - @Override - public void close() throws IOException { - // do nothing - we close the container ourselves - } - }; + client = new EmbeddedSolrServer(this, null); // enable local metrics unless specifically set otherwise initArgs.putIfAbsent(MetricsHistoryHandler.ENABLE_NODES_PROP, true); initArgs.putIfAbsent(MetricsHistoryHandler.ENABLE_REPLICAS_PROP, true); diff --git a/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java b/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java index 1bce4222385..41c093f1f14 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java +++ b/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java @@ -58,13 +58,7 @@ public abstract class AbstractAtomicUpdatesMultivalueTestBase extends EmbeddedSo @Override public synchronized EmbeddedSolrServer getSolrClient() { - return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME, getRequestWriterSupplier()) { - - @Override - public void close() { - // do not close core container - } - }; + return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME, getRequestWriterSupplier()); } private static void assertQR(final String fieldName, final String queryValue, final int numFound) { diff --git a/solr/solr-ref-guide/src/solr-upgrade-notes.adoc b/solr/solr-ref-guide/src/solr-upgrade-notes.adoc index 13899cb2f94..c4f29b5243d 100644 --- a/solr/solr-ref-guide/src/solr-upgrade-notes.adoc +++ b/solr/solr-ref-guide/src/solr-upgrade-notes.adoc @@ -38,6 +38,17 @@ Detailed steps for upgrading a Solr cluster are in the section <> 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 See the https://cwiki.apache.org/confluence/display/SOLR/ReleaseNote88[8.8 Release Notes^] diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServer.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServer.java index d8cfb591e87..57debc5bab2 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServer.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServer.java @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory; public class TestEmbeddedSolrServer extends AbstractEmbeddedSolrServerTestCase { @Rule - public TestRule solrTestRules = + public TestRule solrTestRules = RuleChain.outerRule(new SystemPropertiesRestoreRule()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -47,24 +47,24 @@ public class TestEmbeddedSolrServer extends AbstractEmbeddedSolrServerTestCase { Assert.assertEquals(cores, ((EmbeddedSolrServer)getSolrCore0()).getCoreContainer()); Assert.assertEquals(cores, (getSolrCore1()).getCoreContainer()); } - + public void testClose() throws IOException { - + EmbeddedSolrServer solrServer = (EmbeddedSolrServer) getSolrCore0(); - + Assert.assertEquals(3, cores.getCores().size()); List solrCores = new ArrayList<>(); for (SolrCore solrCore : cores.getCores()) { Assert.assertEquals(false, solrCore.isClosed()); solrCores.add(solrCore); } - + solrServer.close(); - - Assert.assertEquals(0, cores.getCores().size()); - + + Assert.assertEquals(3, cores.getCores().size()); + for (SolrCore solrCore : solrCores) { - Assert.assertEquals(true, solrCore.isClosed()); + Assert.assertEquals(false, solrCore.isClosed()); } } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java index 606debb56d4..9fd4f1e35de 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java @@ -75,12 +75,7 @@ public class DirectJsonQueryRequestFacetingEmbeddedTest extends EmbeddedSolrServ final String schema = tempSolrHome.getAbsolutePath() + "/" + COLLECTION_NAME + "/conf/managed-schema"; initCore(config, schema, tempSolrHome.getAbsolutePath(), COLLECTION_NAME); - client = new EmbeddedSolrServer(h.getCoreContainer(), COLLECTION_NAME) { - @Override - public void close() { - // do not close core container - } - }; + client = new EmbeddedSolrServer(h.getCoreContainer(), COLLECTION_NAME); ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); diff --git a/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java b/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java index 8df8dea8ebf..5785c00ad26 100644 --- a/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java @@ -72,12 +72,7 @@ abstract public class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 { * Create a new solr client. Subclasses should override for other options. */ public EmbeddedSolrServer createNewSolrClient() { - return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME) { - @Override - public void close() { - // do not close core container - } - }; + return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME); } public void upload(final String collection, final ContentStream... contents) {