mirror of https://github.com/apache/lucene.git
SOLR-14040: restore legacy Collection auto-creation
This commit is contained in:
parent
95dfddc7d4
commit
f1db918e20
|
@ -18,8 +18,11 @@ package org.apache.solr.cloud;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
|
|
||||||
|
import org.apache.solr.cloud.api.collections.CreateCollectionCmd;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.cloud.ZkConfigManager;
|
import org.apache.solr.common.cloud.ZkConfigManager;
|
||||||
|
import org.apache.solr.common.cloud.ZkStateReader;
|
||||||
|
import org.apache.solr.common.cloud.ZooKeeperException;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.ConfigSetProperties;
|
import org.apache.solr.core.ConfigSetProperties;
|
||||||
import org.apache.solr.core.ConfigSetService;
|
import org.apache.solr.core.ConfigSetService;
|
||||||
|
@ -46,7 +49,33 @@ public class CloudConfigSetService extends ConfigSetService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd) {
|
public SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd) {
|
||||||
return new ZkSolrResourceLoader(cd.getInstanceDir(), cd.getConfigSet(), parentLoader.getClassLoader(),
|
final String colName = cd.getCollectionName();
|
||||||
|
|
||||||
|
// For back compat with cores that can create collections without the collections API
|
||||||
|
try {
|
||||||
|
if (!zkController.getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + colName, true)) {
|
||||||
|
// TODO remove this functionality or maybe move to a CLI mechanism
|
||||||
|
log.warn("Auto-creating collection (in ZK) from core descriptor (on disk). This feature may go away!");
|
||||||
|
CreateCollectionCmd.createCollectionZkNode(zkController.getSolrCloudManager().getDistribStateManager(), colName, cd.getCloudDescriptor().getParams());
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Interrupted auto-creating collection", e);
|
||||||
|
} catch (KeeperException e) {
|
||||||
|
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Failure auto-creating collection", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The configSet is read from ZK and populated. Ignore CD's pre-existing configSet; only populated in standalone
|
||||||
|
final String configSetName;
|
||||||
|
try {
|
||||||
|
//TODO readConfigName() also validates the configSet exists but seems needless. We'll get errors soon enough.
|
||||||
|
configSetName = zkController.getZkStateReader().readConfigName(colName);
|
||||||
|
cd.setConfigSet(configSetName);
|
||||||
|
} catch (KeeperException ex) {
|
||||||
|
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Trouble resolving configSet for collection " + colName + ": " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ZkSolrResourceLoader(cd.getInstanceDir(), configSetName, parentLoader.getClassLoader(),
|
||||||
cd.getSubstitutableProperties(), zkController);
|
cd.getSubstitutableProperties(), zkController);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,10 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.common.StringUtils;
|
import org.apache.solr.common.StringUtils;
|
||||||
import org.apache.solr.common.cloud.Replica;
|
import org.apache.solr.common.cloud.Replica;
|
||||||
import org.apache.solr.common.cloud.ZooKeeperException;
|
|
||||||
import org.apache.solr.core.CoreDescriptor;
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.util.PropertiesUtil;
|
import org.apache.solr.util.PropertiesUtil;
|
||||||
import org.apache.zookeeper.KeeperException;
|
|
||||||
|
|
||||||
import static org.apache.solr.core.CoreDescriptor.CORE_CONFIGSET;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SolrCloud metadata attached to a {@link CoreDescriptor}.
|
* SolrCloud metadata attached to a {@link CoreDescriptor}.
|
||||||
|
@ -61,7 +56,7 @@ public class CloudDescriptor {
|
||||||
*/
|
*/
|
||||||
private final Replica.Type replicaType;
|
private final Replica.Type replicaType;
|
||||||
|
|
||||||
public CloudDescriptor(CoreDescriptor cd, String coreName, Properties props, ZkController zkController) {
|
public CloudDescriptor(CoreDescriptor cd, String coreName, Properties props) {
|
||||||
this.cd = cd;
|
this.cd = cd;
|
||||||
this.shardId = props.getProperty(CoreDescriptor.CORE_SHARD, null);
|
this.shardId = props.getProperty(CoreDescriptor.CORE_SHARD, null);
|
||||||
if (Strings.isNullOrEmpty(shardId))
|
if (Strings.isNullOrEmpty(shardId))
|
||||||
|
@ -84,19 +79,6 @@ public class CloudDescriptor {
|
||||||
collectionParams.put(propName.substring(ZkController.COLLECTION_PARAM_PREFIX.length()), props.getProperty(propName));
|
collectionParams.put(propName.substring(ZkController.COLLECTION_PARAM_PREFIX.length()), props.getProperty(propName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The configSet comes from ZK, not from CD's properties like it does in standalone.
|
|
||||||
// But we want to put it on CD because CD has getConfigSet() which is sensible; don't want that to return null.
|
|
||||||
if (zkController != null) { // there's a test where we pass null 'cause it wanted a dummy instance. Yuck?
|
|
||||||
try {
|
|
||||||
//TODO readConfigName() also validates the configSet exists but seems needless. We'll get errors soon enough.
|
|
||||||
String configSetName = zkController.getZkStateReader().readConfigName(collectionName);
|
|
||||||
props.setProperty(CORE_CONFIGSET, configSetName);
|
|
||||||
//noinspection StringEquality
|
|
||||||
assert cd.getConfigSet() == configSetName;
|
|
||||||
} catch (KeeperException ex) {
|
|
||||||
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Trouble resolving configSet for collection " + collectionName + ": " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresTransactionLog() {
|
public boolean requiresTransactionLog() {
|
||||||
|
|
|
@ -211,7 +211,7 @@ public class CoreDescriptor {
|
||||||
|
|
||||||
// TODO maybe make this a CloudCoreDescriptor subclass?
|
// TODO maybe make this a CloudCoreDescriptor subclass?
|
||||||
if (zkController != null) {
|
if (zkController != null) {
|
||||||
cloudDesc = new CloudDescriptor(this, name, coreProperties, zkController);
|
cloudDesc = new CloudDescriptor(this, name, coreProperties);
|
||||||
} else {
|
} else {
|
||||||
cloudDesc = null;
|
cloudDesc = null;
|
||||||
}
|
}
|
||||||
|
@ -371,6 +371,11 @@ public class CoreDescriptor {
|
||||||
return coreProperties.getProperty(CORE_CONFIGSET);
|
return coreProperties.getProperty(CORE_CONFIGSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** TODO remove mutability or at least make this non-public? */
|
||||||
|
public void setConfigSet(String configSetName) {
|
||||||
|
coreProperties.setProperty(CORE_CONFIGSET, configSetName);
|
||||||
|
}
|
||||||
|
|
||||||
public String getConfigSetPropertiesName() {
|
public String getConfigSetPropertiesName() {
|
||||||
return coreProperties.getProperty(CORE_CONFIGSET_PROPERTIES);
|
return coreProperties.getProperty(CORE_CONFIGSET_PROPERTIES);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class CoreSorterTest extends SolrTestCaseJ4 {
|
||||||
p.setProperty(CoreDescriptor.CORE_SHARD, "shard_" + slice);
|
p.setProperty(CoreDescriptor.CORE_SHARD, "shard_" + slice);
|
||||||
p.setProperty(CoreDescriptor.CORE_COLLECTION, "coll_" + slice);
|
p.setProperty(CoreDescriptor.CORE_COLLECTION, "coll_" + slice);
|
||||||
p.setProperty(CoreDescriptor.CORE_NODE_NAME, replicaName);
|
p.setProperty(CoreDescriptor.CORE_NODE_NAME, replicaName);
|
||||||
cd = new CloudDescriptor(null, replicaName, p, null);
|
cd = new CloudDescriptor(null, replicaName, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue