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
This commit is contained in:
Erick Erickson 2013-11-06 14:23:47 +00:00
parent 50b5e3ec7c
commit 6e40ba21af
4 changed files with 71 additions and 4 deletions

View File

@ -153,6 +153,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
----------------------

View File

@ -452,6 +452,15 @@ 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;
@ -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()

View File

@ -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

View File

@ -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