diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 27c4f7b6f71..1d153fad9fb 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -390,6 +390,10 @@ Bug Fixes * SOLR-3361: ReplicationHandler "maxNumberOfBackups" doesn't work if backups are triggered on commit (James Dyer, Tomas Fernandez Lobbe) +* SOLR-2605: fixed tracking of the 'defaultCoreName' in CoreContainer so that + CoreAdminHandler could return consistent information regardless of wether + there is a a default core name or not. (steffkes, hossman) + Other Changes ---------------------- 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 69e6b0c278d..c5c6763f964 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -90,7 +90,7 @@ public class CoreContainer private static final String DEFAULT_HOST_CONTEXT = "solr"; private static final String DEFAULT_HOST_PORT = "8983"; private static final int DEFAULT_ZK_CLIENT_TIMEOUT = 10000; - private static final String DEFAULT_DEFAULT_CORE_NAME = "collection1"; + public static final String DEFAULT_DEFAULT_CORE_NAME = "collection1"; private static final boolean DEFAULT_SHARE_SCHEMA = false; protected static Logger log = LoggerFactory.getLogger(CoreContainer.class); @@ -113,7 +113,7 @@ public class CoreContainer protected boolean shareSchema; protected Integer zkClientTimeout; protected String solrHome; - protected String defaultCoreName = ""; + protected String defaultCoreName = null; private SolrXMLSerializer solrXMLSerializer = new SolrXMLSerializer(); private ZkController zkController; private SolrZkServer zkServer; @@ -437,7 +437,7 @@ public class CoreContainer String dcoreName = cfg.get("solr/cores/@defaultCoreName", null); - if(dcoreName != null) { + if(dcoreName != null && !dcoreName.isEmpty()) { defaultCoreName = dcoreName; } persistent = cfg.getBool("solr/@persistent", false); @@ -491,15 +491,7 @@ public class CoreContainer throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Each core in solr.xml must have a 'name'"); } - String name; - if (rawName.equals(defaultCoreName)){ - // for the default core we use a blank name, - // later on attempts to access it by it's full name will - // be mapped to this. - name=""; - } else { - name = rawName; - } + String name = rawName; CoreDescriptor p = new CoreDescriptor(this, name, DOMUtil.getAttr(node, "instanceDir", null)); // deal with optional settings @@ -941,7 +933,7 @@ public class CoreContainer } private String checkDefault(String name) { - return name.length() == 0 || defaultCoreName.equals(name) || name.trim().length() == 0 ? "" : name; + return (null == name || name.isEmpty()) ? defaultCoreName : name; } /** @@ -1035,6 +1027,9 @@ public class CoreContainer return coreAdminHandler; } + /** + * the default core name, or null if there is no default core name + */ public String getDefaultCoreName() { return defaultCoreName; } @@ -1109,8 +1104,9 @@ public class CoreContainer Boolean.toString(DEFAULT_SHARE_SCHEMA)); addCoresAttrib(coresAttribs, "host", this.host, null); - if (!defaultCoreName.equals("")) coresAttribs.put("defaultCoreName", - defaultCoreName); + if (! (null == defaultCoreName || defaultCoreName.equals("")) ) { + coresAttribs.put("defaultCoreName", defaultCoreName); + } addCoresAttrib(coresAttribs, "hostPort", this.hostPort, DEFAULT_HOST_PORT); addCoresAttrib(coresAttribs, "zkClientTimeout", @@ -1125,9 +1121,7 @@ public class CoreContainer Map coreAttribs = new HashMap(); CoreDescriptor dcore = solrCore.getCoreDescriptor(); - String coreName = dcore.name.equals("") ? defaultCoreName - : dcore.name; - + String coreName = dcore.name; Node coreNode = null; if (cfg != null) { diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java index 2a00b372419..390a036b240 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java +++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java @@ -50,7 +50,7 @@ public class CoreDescriptor { if(coreContainer != null && coreContainer.getZkController() != null) { this.cloudDesc = new CloudDescriptor(); // cloud collection defaults to core name - cloudDesc.setCollectionName(name.isEmpty() ? coreContainer.getDefaultCoreName() : name); + cloudDesc.setCollectionName(name); } if (instanceDir == null) { 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 3f6cb9952eb..daab82daee6 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 @@ -533,6 +533,7 @@ public class CoreAdminHandler extends RequestHandlerBase { NamedList status = new SimpleOrderedMap(); try { if (cname == null) { + rsp.add("defaultCoreName", coreContainer.getDefaultCoreName()); for (String name : coreContainer.getCoreNames()) { status.add(name, getCoreStatus(coreContainer, name)); } @@ -807,6 +808,7 @@ public class CoreAdminHandler extends RequestHandlerBase { if (core != null) { try { info.add("name", core.getName()); + info.add("isDefaultCore", core.getName().equals(cores.getDefaultCoreName())); info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir())); info.add("dataDir", normalizePath(core.getDataDir())); info.add("config", core.getConfigResource()); diff --git a/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java b/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java index d0c8dca7110..aae91699bf6 100644 --- a/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java +++ b/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java @@ -115,9 +115,6 @@ public class TestJmxIntegration extends AbstractSolrTestCase { MBeanServer mbeanServer = servers.get(0); String coreName = h.getCore().getName(); - if (coreName.length() == 0) { - coreName = h.getCoreContainer().getDefaultCoreName().length() > 0 ? h.getCoreContainer().getDefaultCoreName() : ""; - } Set oldBeans = mbeanServer.queryMBeans(null, null); int oldNumberOfObjects = 0; diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java index c7e795c172b..4ad7e9d8d7e 100644 --- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java +++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java @@ -133,14 +133,14 @@ public class TestHarness { public TestHarness( String dataDirectory, SolrConfig solrConfig, IndexSchema indexSchema) { - this("", new Initializer("", dataDirectory, solrConfig, indexSchema)); + this(null, new Initializer(null, dataDirectory, solrConfig, indexSchema)); } public TestHarness(String coreName, CoreContainer.Initializer init) { try { container = init.initialize(); if (coreName == null) - coreName = ""; + coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME; // get the core & decrease its refcount: // the container holds the core for the harness lifetime core = container.getCore(coreName); @@ -191,7 +191,7 @@ public class TestHarness { SolrConfig solrConfig, IndexSchema indexSchema) { if (coreName == null) - coreName = ""; + coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME; this.coreName = coreName; this.dataDirectory = dataDirectory; this.solrConfig = solrConfig;