From 6e40ba21af70aafa1db4eb9bcaa2ebdc98bce307 Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Wed, 6 Nov 2013 14:23:47 +0000 Subject: [PATCH] SOLR-5318: create HTTP API command doesn't respect transient core property git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1539343 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 + .../org/apache/solr/core/CoreContainer.java | 15 ++++- .../solr/handler/admin/CoreAdminHandler.java | 2 +- .../org/apache/solr/core/TestLazyCores.java | 55 +++++++++++++++++++ 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 64761c38b95..da8f61362b9 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -152,6 +152,9 @@ Bug Fixes * SOLR-5418: Background merge after field removed from solr.xml causes error. (Reported on user's list, Robert M's patch via Erick Erickson) + + * SOLR-5318: Creating a core via the admin API doesn't respect transient property + (Olivier Soyez via Erick Erickson) Optimizations ---------------------- 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 cb170720e66..acdd43ca374 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -452,7 +452,16 @@ public class CoreContainer { name.indexOf( '\\' ) >= 0 ){ throw new RuntimeException( "Invalid core name: "+name ); } - + // We can register a core when creating them via the admin UI, so we need to insure that the dynamic descriptors + // are up to date + CoreDescriptor cd = core.getCoreDescriptor(); + if ((cd.isTransient() || ! cd.isLoadOnStartup()) + && solrCores.getDynamicDescriptor(name) == null) { + // Store it away for later use. includes non-transient but not + // loaded at startup cores. + solrCores.putDynamicDescriptor(name, cd); + } + SolrCore old = null; if (isShutDown) { @@ -496,11 +505,11 @@ public class CoreContainer { * @return a previous core having the same name if it existed and returnPrev==true */ public SolrCore register(SolrCore core, boolean returnPrev) { - return registerCore(false, core.getName(), core, returnPrev); + return registerCore(core.getCoreDescriptor().isTransient(), core.getName(), core, returnPrev); } public SolrCore register(String name, SolrCore core, boolean returnPrev) { - return registerCore(false, name, core, returnPrev); + return registerCore(core.getCoreDescriptor().isTransient(), name, core, returnPrev); } // Helper method to separate out creating a core from local configuration files. See create() diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java index 53ebed42404..422f3ae47fb 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java @@ -497,7 +497,7 @@ public class CoreAdminHandler extends RequestHandlerBase { SolrCore core = coreContainer.create(dcore); - coreContainer.register(dcore.getName(), core, false); + coreContainer.register(core, false); if (coreContainer.getCoresLocator() instanceof SolrXMLCoresLocator) { // hack - in this case we persist once more because a core create race might diff --git a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java index cdb8850b49d..416107e8998 100644 --- a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java +++ b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java @@ -338,6 +338,61 @@ public class TestLazyCores extends SolrTestCaseJ4 { } } + private void createViaAdmin(CoreContainer cc, String name, String instanceDir, boolean isTransient, + boolean loadOnStartup) throws Exception { + + final CoreAdminHandler admin = new CoreAdminHandler(cc); + SolrQueryResponse resp = new SolrQueryResponse(); + admin.handleRequestBody + (req(CoreAdminParams.ACTION, + CoreAdminParams.CoreAdminAction.CREATE.toString(), + CoreAdminParams.INSTANCE_DIR, instanceDir, + CoreAdminParams.NAME, name, + CoreAdminParams.TRANSIENT, Boolean.toString(isTransient), + CoreAdminParams.LOAD_ON_STARTUP, Boolean.toString(loadOnStartup)), + resp); + + } + + // Make sure that creating a transient core from the admin handler correctly respects the transient limits etc. + @Test + public void testCreateTransientFromAdmin() throws Exception { + final CoreContainer cc = init(); + try { + copyMinConf(new File(solrHomeDirectory, "core1")); + copyMinConf(new File(solrHomeDirectory, "core2")); + copyMinConf(new File(solrHomeDirectory, "core3")); + copyMinConf(new File(solrHomeDirectory, "core4")); + copyMinConf(new File(solrHomeDirectory, "core5")); + + createViaAdmin(cc, "core1", "./core1", true, true); + createViaAdmin(cc, "core2", "./core2", true, false); + createViaAdmin(cc, "core3", "./core3", true, true); + createViaAdmin(cc, "core4", "./core4", true, false); + createViaAdmin(cc, "core5", "./core5", true, false); + + SolrCore c1 = cc.getCore("core1"); + SolrCore c2 = cc.getCore("core2"); + SolrCore c3 = cc.getCore("core3"); + SolrCore c4 = cc.getCore("core4"); + SolrCore c5 = cc.getCore("core5"); + + checkNotInCores(cc, "core1", "collectionLazy2", "collectionLazy3", "collectionLazy4", "collectionLazy6" + , "collectionLazy7", "collectionLazy8", "collectionLazy9"); + + checkInCores(cc, "collection1", "collectionLazy5", "core2", "core3", "core4", "core5"); + + c1.close(); + c2.close(); + c3.close(); + c4.close(); + c5.close(); + + } finally { + cc.shutdown(); + } + } + //Make sure persisting not-loaded lazy cores is done. See SOLR-4347 @Test