Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

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

Mark Robert Miller62fd532bae53
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3078be2e23e..4cf470ce720 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
----------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
index 3bd1f0d91e0..fc9ddc4c017 100644
--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
@@ -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");
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
index 7f768e0f878..3f8f41a6b30 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
@@ -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