Skip to content

Apache Lucene open-source search software

SOLR-5338: CompositeIdRouter.keyHashRange should not throw exception if route key is not composite

Shalin Shekhar Mangar3aacbf9f9100
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 f6ae9128692..72787457178 100644
--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
@@ -561,6 +561,11 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
throw new SolrException(ErrorCode.BAD_REQUEST,
"The split.key: " + splitKey + " has a hash range that is exactly equal to hash range of shard: " + slice);
}
+ for (DocRouter.Range subRange : subRanges) {
+ if (subRange.min == subRange.max) {
+ throw new SolrException(ErrorCode.BAD_REQUEST, "The split.key: " + splitKey + " must be a compositeId");
+ }
+ }
log.info("Partitioning parent shard " + slice + " range: " + parentSlice.getRange() + " yields: " + subRanges);
rangesStr = "";
for (int i = 0; i < subRanges.size(); i++) {
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java b/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
index 3f3b9af9edf..ab94a261cf4 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
@@ -96,7 +96,8 @@ public class CompositeIdRouter extends HashBasedRouter {
public Range keyHashRange(String routeKey) {
int idx = routeKey.indexOf(separator);
if (idx < 0) {
- throw new IllegalArgumentException("Route key must be a composite id");
+ int hash = sliceHash(routeKey, null, null, null);
+ return new Range(hash, hash);
}
String part1 = routeKey.substring(0, idx);
int commaIdx = part1.indexOf(bitsSeparator);