Skip to content

Apache Lucene open-source search software

SOLR-5502: A "/" in a document id will cause an exception to be thrown when using the composite id router.

Mark Robert Miller1f57856b9039
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3250c726e60..961a2e1e9be 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -189,6 +189,9 @@ Bug Fixes
* SOLR-5527: DIH logs spurious warning for special commands. (shalin)
+* SOLR-5502: A "/" in a document id will cause an exception to be thrown
+ when using the composite id router. (Anshum Gupta via Mark Miller)
+
Optimizations
----------------------
@@ -220,9 +223,6 @@ Other Changes
* SOLR-5499: Log a warning if /get is not registered when using SolrCloud.
(Daniel Collins via shalin)
-* SOLR-5517: Return HTTP error on POST requests with no Content-Type.
- (Ryan Ernst, Uwe Schindler)
-
================== 4.6.0 ==================
Versions of Major Components
diff --git a/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java b/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java
index 679b1dd9c78..4275aad7f00 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java
@@ -148,30 +148,33 @@ public class ShardRoutingTest extends AbstractFullDistribZkTestBase {
doAddDoc("d!doc3");
doAddDoc("e!doc4");
doAddDoc("f1!f2!doc5");
+ // Check successful addition of a document with a '/' in the id part.
+ doAddDoc("f1!f2!doc5/5");
doRTG("b!doc1");
doRTG("c!doc2");
doRTG("d!doc3");
doRTG("e!doc4");
doRTG("f1!f2!doc5");
+ doRTG("f1!f2!doc5/5");
doRTG("b!doc1,c!doc2");
doRTG("d!doc3,e!doc4");
commit();
- doQuery("b!doc1,c!doc2,d!doc3,e!doc4,f1!f2!doc5", "q","*:*");
- doQuery("b!doc1,c!doc2,d!doc3,e!doc4,f1!f2!doc5", "q","*:*", "shards","shard1,shard2,shard3,shard4");
- doQuery("b!doc1,c!doc2,d!doc3,e!doc4,f1!f2!doc5", "q","*:*", shardKeys,"b!,c!,d!,e!,f1!f2!");
+ doQuery("b!doc1,c!doc2,d!doc3,e!doc4,f1!f2!doc5,f1!f2!doc5/5", "q","*:*");
+ doQuery("b!doc1,c!doc2,d!doc3,e!doc4,f1!f2!doc5,f1!f2!doc5/5", "q","*:*", "shards","shard1,shard2,shard3,shard4");
+ doQuery("b!doc1,c!doc2,d!doc3,e!doc4,f1!f2!doc5,f1!f2!doc5/5", "q","*:*", shardKeys,"b!,c!,d!,e!,f1!f2!");
doQuery("b!doc1", "q","*:*", shardKeys,"b!");
doQuery("c!doc2", "q","*:*", shardKeys,"c!");
- doQuery("d!doc3,f1!f2!doc5", "q","*:*", shardKeys,"d!");
+ doQuery("d!doc3,f1!f2!doc5,f1!f2!doc5/5", "q","*:*", shardKeys,"d!");
doQuery("e!doc4", "q","*:*", shardKeys,"e!");
- doQuery("f1!f2!doc5,d!doc3", "q","*:*", shardKeys,"f1/8!");
+ doQuery("f1!f2!doc5,d!doc3,f1!f2!doc5/5", "q","*:*", shardKeys,"f1/8!");
// try using shards parameter
doQuery("b!doc1", "q","*:*", "shards",bucket1);
doQuery("c!doc2", "q","*:*", "shards",bucket2);
- doQuery("d!doc3,f1!f2!doc5", "q","*:*", "shards",bucket3);
+ doQuery("d!doc3,f1!f2!doc5,f1!f2!doc5/5", "q","*:*", "shards",bucket3);
doQuery("e!doc4", "q","*:*", "shards",bucket4);
@@ -181,16 +184,16 @@ public class ShardRoutingTest extends AbstractFullDistribZkTestBase {
doQuery("b!doc1,c!doc2", "q","*:*", shardKeys,"b,c"); // query shards that would contain *documents* "b" and "c" (i.e. not prefixes). The upper bits are the same, so the shards should be the same.
doQuery("b!doc1,c!doc2", "q","*:*", shardKeys,"b/1!"); // top bit of hash(b)==1, so shard1 and shard2
- doQuery("d!doc3,e!doc4,f1!f2!doc5", "q","*:*", shardKeys,"d/1!"); // top bit of hash(b)==0, so shard3 and shard4
+ doQuery("d!doc3,e!doc4,f1!f2!doc5,f1!f2!doc5/5", "q","*:*", shardKeys,"d/1!"); // top bit of hash(b)==0, so shard3 and shard4
doQuery("b!doc1,c!doc2", "q","*:*", shardKeys,"b!,c!");
- doQuery("b!doc1,f1!f2!doc5,c!doc2,d!doc3,e!doc4", "q","*:*", shardKeys,"foo/0!");
+ doQuery("b!doc1,f1!f2!doc5,c!doc2,d!doc3,e!doc4,f1!f2!doc5/5", "q","*:*", shardKeys,"foo/0!");
// test targeting deleteByQuery at only certain shards
doDBQ("*:*", shardKeys,"b!");
commit();
- doQuery("c!doc2,d!doc3,e!doc4,f1!f2!doc5", "q","*:*");
+ doQuery("c!doc2,d!doc3,e!doc4,f1!f2!doc5,f1!f2!doc5/5", "q","*:*");
doAddDoc("b!doc1");
doDBQ("*:*", shardKeys,"f1!");
diff --git a/solr/core/src/test/org/apache/solr/cloud/TriLevelCompositeIdRoutingTest.java b/solr/core/src/test/org/apache/solr/cloud/TriLevelCompositeIdRoutingTest.java
index 024cc016e0f..26aa92c414c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TriLevelCompositeIdRoutingTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TriLevelCompositeIdRoutingTest.java
@@ -143,7 +143,6 @@ public class TriLevelCompositeIdRoutingTest extends ShardRoutingTest {
Set<String> doQueryGetUniqueIdKeys(String... queryParams) throws Exception {
QueryResponse rsp = cloudClient.query(params(queryParams));
Set<String> obtainedIdKeys = new HashSet<String>();
- Set<String> obtainedIdKeys2 = new HashSet<String>();
for (SolrDocument doc : rsp.getResults()) {
obtainedIdKeys.add(getKey((String) doc.get("id")));
}
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 862e41759a4..766b115d605 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
@@ -202,15 +202,16 @@ public class CompositeIdRouter extends HashBasedRouter {
} else {
numBits[0] = 16;
triLevel = false;
-
}
for (int i = 0; i < parts.length; i++) {
- int commaIdx = parts[i].indexOf(bitsSeparator);
+ if (i < pieces - 1) {
+ int commaIdx = parts[i].indexOf(bitsSeparator);
- if (commaIdx > 0) {
- numBits[i] = getNumBits(parts[i], commaIdx);
- parts[i] = parts[i].substring(0, commaIdx);
+ if (commaIdx > 0) {
+ numBits[i] = getNumBits(parts[i], commaIdx);
+ parts[i] = parts[i].substring(0, commaIdx);
+ }
}
hashes[i] = Hash.murmurhash3_x86_32(parts[i], 0, parts[i].length(), 0);
}