SOLR-4585: The Collections API validates numShards with < 0 but should use <= 0.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1456979 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-03-15 15:03:02 +00:00
parent 78081caf97
commit 62fd532bae
3 changed files with 47 additions and 5 deletions

View File

@ -98,7 +98,7 @@ Bug Fixes
fields to null (Ben Pennell, Rob, shalin)
* SOLR-4543: setting shardHandlerFactory in solr.xml/solr.properties does not work.
(Ryan Ernst, Robert Muir via Erick Ericson)
(Ryan Ernst, Robert Muir via Erick Erickson)
* SOLR-4371: Admin UI - Analysis Screen shows empty result (steffkes)
@ -123,6 +123,9 @@ Bug Fixes
should still wait to see the shard id in it's current ClusterState.
(Mark Miller)
* SOLR-4585: The Collections API validates numShards with < 0 but should use
<= 0. (Mark Miller)
Optimizations
----------------------

View File

@ -316,17 +316,21 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
// if it does not, find best nodes to create more cores
int repFactor = msgStrToInt(message, REPLICATION_FACTOR, 1);
int numSlices = msgStrToInt(message, NUM_SLICES, 0);
Integer numSlices = msgStrToInt(message, NUM_SLICES, null);
if (numSlices == null) {
throw new SolrException(ErrorCode.BAD_REQUEST, "collection already exists: " + collectionName);
}
int maxShardsPerNode = msgStrToInt(message, MAX_SHARDS_PER_NODE, 1);
String createNodeSetStr;
List<String> createNodeList = ((createNodeSetStr = message.getStr(CREATE_NODE_SET)) == null)?null:StrUtils.splitSmart(createNodeSetStr, ",", true);
if (repFactor <= 0) {
SolrException.log(log, REPLICATION_FACTOR + " must be > 0");
throw new SolrException(ErrorCode.BAD_REQUEST, "collection already exists: " + collectionName);
throw new SolrException(ErrorCode.BAD_REQUEST, NUM_SLICES + " is a required paramater");
}
if (numSlices < 0) {
if (numSlices <= 0) {
throw new SolrException(ErrorCode.BAD_REQUEST, NUM_SLICES + " must be > 0");
}

View File

@ -207,6 +207,41 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
}
assertTrue(gotExp);
// No numShards should fail
params = new ModifiableSolrParams();
params.set("action", CollectionAction.CREATE.toString());
collectionName = "acollection";
params.set("name", collectionName);
params.set(OverseerCollectionProcessor.REPLICATION_FACTOR, 10);
request = new QueryRequest(params);
request.setPath("/admin/collections");
gotExp = false;
resp = null;
try {
resp = createNewSolrServer("", baseUrl).request(request);
} catch (SolrException e) {
gotExp = true;
}
assertTrue(gotExp);
// 0 numShards should fail
params = new ModifiableSolrParams();
params.set("action", CollectionAction.CREATE.toString());
collectionName = "acollection";
params.set("name", collectionName);
params.set(OverseerCollectionProcessor.REPLICATION_FACTOR, 10);
params.set("numShards", 0);
request = new QueryRequest(params);
request.setPath("/admin/collections");
gotExp = false;
resp = null;
try {
resp = createNewSolrServer("", baseUrl).request(request);
} catch (SolrException e) {
gotExp = true;
}
assertTrue(gotExp);
// Fail on one node
// first we make a core with the core name the collections api