SOLR-4034: Check if a collection already exists before trying to create a new one.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1411536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-11-20 05:08:07 +00:00
parent f31b08fee2
commit 3005330649
3 changed files with 29 additions and 2 deletions

View File

@ -226,6 +226,9 @@ Bug Fixes
* SOLR-4075: A logical shard that has had all of it's SolrCores unloaded should
be removed from the cluster state. (Mark Miller, Gilles Comeau)
* SOLR-4034: Check if a collection already exists before trying to create a
new one. (Po Rui, Mark Miller)
Other Changes
----------------------

View File

@ -158,7 +158,12 @@ public class OverseerCollectionProcessor implements Runnable {
}
private boolean createCollection(ClusterState clusterState, ZkNodeProps message) {
String collectionName = message.getStr("name");
if(clusterState.getCollections().contains(collectionName)) {
SolrException.log(log, "collection already exists: " + collectionName);
return false;
}
// look at the replication factor and see if it matches reality
// if it does not, find best nodes to create more cores
@ -179,6 +184,17 @@ public class OverseerCollectionProcessor implements Runnable {
return false;
}
if (numReplicas < 0) {
SolrException.log(log, REPLICATION_FACTOR + " must be > 0");
return false;
}
if (numShards < 0) {
SolrException.log(log, "numShards must be > 0");
return false;
}
String name = message.getStr("name");
String configName = message.getStr("collection.configName");
@ -198,6 +214,14 @@ public class OverseerCollectionProcessor implements Runnable {
Collections.shuffle(nodeList);
int numNodes = numShards * (numReplicas + 1);
if (nodeList.size() < numNodes) {
log.warn("Not enough nodes available to satisfy create collection request for collection:"
+ collectionName
+ " nodes needed:"
+ numNodes
+ " nodes available:" + nodeList.size() + " - using nodes available");
}
List<String> createOnNodes = nodeList.subList(0, Math.min(nodeList.size(), numNodes));
log.info("Create collection " + name + " on " + createOnNodes);

View File

@ -739,7 +739,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
for (int i = 0; i < cnt; i++) {
createCollection(collectionInfos, i,
_TestUtil.nextInt(random(), 0, shardCount) + 1,
_TestUtil.nextInt(random(), 0, 5) + 1);
_TestUtil.nextInt(random(), 0, 3) + 1);
}
Set<Entry<String,List<Integer>>> collectionInfosEntrySet = collectionInfos.entrySet();