From 6c81041ea49a34aaaddcde1692423a934be371a7 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Wed, 27 Aug 2008 14:20:40 +0000 Subject: [PATCH] SOLR-722: CoreContainer.reload should make core aliases point to reloaded core git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@689489 13f79535-47bb-0310-9956-ffa450edef68 --- .../client/solrj/MultiCoreExampleTestBase.java | 14 ++++++++++++++ src/java/org/apache/solr/core/CoreContainer.java | 12 +++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java b/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java index 2981b3a5e51..3d7c9739f1d 100644 --- a/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java +++ b/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java @@ -137,6 +137,20 @@ SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames()); assertEquals( 1, getSolrCore1().query( new SolrQuery( "id:BBB" ) ).getResults().size() ); assertEquals( 1, getSolrCore("corefoo").query( new SolrQuery( "id:BBB" ) ).getResults().size() ); + // test that reload affects aliases + CoreAdminRequest.reloadCore("core1", coreadmin); + + // this is only an effective test for embedded, where we have + // direct access to the core container. + SolrCore c1 = cores.getCore("core1"); + SolrCore c2 = cores.getCore("corefoo"); + assertTrue(c1 == c2); + if (c1 != null) c1.close(); + if (c2 != null) c2.close(); + + // retest core query + assertEquals( 1, getSolrCore1().query( new SolrQuery( "id:BBB" ) ).getResults().size() ); + // test close CoreAdminRequest.unloadCore("corefoo",coreadmin); try { diff --git a/src/java/org/apache/solr/core/CoreContainer.java b/src/java/org/apache/solr/core/CoreContainer.java index 0ad5b7ac2ad..c1900a0e92f 100644 --- a/src/java/org/apache/solr/core/CoreContainer.java +++ b/src/java/org/apache/solr/core/CoreContainer.java @@ -381,7 +381,17 @@ public class CoreContainer if (core == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name ); - register(name, create(core.getCoreDescriptor()), false); + SolrCore newCore = create(core.getCoreDescriptor()); + + // point all aliases to the reloaded core + for (String alias : getCoreNames(core)) { + if (!name.equals(alias)) { + newCore.open(); + register(alias, newCore, false); + } + } + + register(name, newCore, false); }