From 95841d9ed406def6be62ab039dba8c4dd4b552a8 Mon Sep 17 00:00:00 2001 From: Erick Date: Sun, 11 Jun 2017 12:13:25 -0700 Subject: [PATCH] SOLR-10857: Solr loads UNLOADed core on request. --- solr/CHANGES.txt | 7 +++ .../org/apache/solr/core/CoreContainer.java | 9 ++-- .../handler/admin/CoreAdminHandlerTest.java | 52 +++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 039a2c499d5..275710da640 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -397,6 +397,13 @@ Other Changes * SOLR-10761: Switch trie numeric/date fields to points in data-driven-enabled example and test schemas. (Steve Rowe) +================== 6.6.1 ================== + +Bug Fixes +---------------------- + +* SOLR-10857: standalone Solr loads UNLOADed core on request (Erick Erickson, Mikhail Khludnev) + ================== 6.6.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. 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 37842f87e62..6055acf6efc 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -1285,6 +1285,8 @@ public class CoreContainer { boolean close = solrCores.isLoadedNotPendingClose(name); SolrCore core = solrCores.remove(name); + + solrCores.removeCoreDescriptor(cd); coresLocator.delete(this, cd); if (core == null) { // transient core @@ -1298,8 +1300,8 @@ public class CoreContainer { if (zkSys.getZkController() != null) { // cancel recovery in cloud mode core.getSolrCoreState().cancelRecovery(); - if (core.getCoreDescriptor().getCloudDescriptor().getReplicaType() == Replica.Type.PULL - || core.getCoreDescriptor().getCloudDescriptor().getReplicaType() == Replica.Type.TLOG) { + if (cd.getCloudDescriptor().getReplicaType() == Replica.Type.PULL + || cd.getCloudDescriptor().getReplicaType() == Replica.Type.TLOG) { // Stop replication if this is part of a pull/tlog replica before closing the core zkSys.getZkController().stopReplicationFromLeader(name); } @@ -1319,9 +1321,6 @@ public class CoreContainer { throw new SolrException(ErrorCode.SERVER_ERROR, "Error unregistering core [" + name + "] from cloud state", e); } } - if (deleteInstanceDir) { // we aren't going to reload this if we delete the instance dir. - solrCores.removeCoreDescriptor(cd); - } } public void rename(String name, String toName) { diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java index a81cf13389d..f1770f8acbe 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java @@ -27,10 +27,12 @@ import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule; import org.apache.commons.io.FileUtils; import org.apache.lucene.util.Constants; import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.CoreStatus; +import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.params.CoreAdminParams; @@ -282,6 +284,56 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 { } + @Test + public void testUnloadForever() throws Exception { + File solrHomeDirectory = new File(initCoreDataDir, getClass().getName() + "-corex-" + + System.nanoTime()); + solrHomeDirectory.mkdirs(); + copySolrHomeToTemp(solrHomeDirectory, "corex"); + File corex = new File(solrHomeDirectory, "corex"); + FileUtils.write(new File(corex, "core.properties"), "", StandardCharsets.UTF_8); + JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr")); + runner.start(); + + try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex")) { + client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); + client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); + SolrInputDocument doc = new SolrInputDocument(); + doc.addField("id", "123"); + client.add(doc); + client.commit(); + } + + try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex")) { + client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); + client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); + QueryResponse result = client.query(new SolrQuery("id:*")); + assertEquals(1,result.getResults().getNumFound()); + } + + try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) { + client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); + client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); + CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false); + req.setDeleteInstanceDir(false);//random().nextBoolean()); + req.setCoreName("corex"); + req.process(client); + } + + try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex")) { + client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); + client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT*1000); + QueryResponse result = client.query(new SolrQuery("id:*")); + //assertEquals(1,result.getResults().getNumFound()); + fail("expect 404"); + }catch(Exception e){ + e.printStackTrace(); + } + finally{ + runner.stop(); + } + } + @Test public void testDeleteInstanceDirAfterCreateFailure() throws Exception { assumeFalse("Ignore test on windows because it does not delete data directory immediately after unload", Constants.WINDOWS);