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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1330028 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2012-04-24 21:42:19 +00:00
parent 19d35e0b06
commit c0a94ba5f8
6 changed files with 22 additions and 25 deletions

View File

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

View File

@ -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<String,String> coreAttribs = new HashMap<String,String>();
CoreDescriptor dcore = solrCore.getCoreDescriptor();
String coreName = dcore.name.equals("") ? defaultCoreName
: dcore.name;
String coreName = dcore.name;
Node coreNode = null;
if (cfg != null) {

View File

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

View File

@ -533,6 +533,7 @@ public class CoreAdminHandler extends RequestHandlerBase {
NamedList<Object> status = new SimpleOrderedMap<Object>();
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());

View File

@ -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<ObjectInstance> oldBeans = mbeanServer.queryMBeans(null, null);
int oldNumberOfObjects = 0;

View File

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