From d36147eca70975fa70d619ace174f7007a0deceb Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Tue, 1 Oct 2013 15:01:01 +0000 Subject: [PATCH] SOLR-5258 compute full composite hash on router.field git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1528113 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/cloud/CustomCollectionTest.java | 6 ++++ .../solr/common/cloud/CompositeIdRouter.java | 32 +++++++------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java b/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java index de4415f1f1d..9cad1f07c97 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java @@ -414,6 +414,12 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase { //TODO debug the following case assertEquals(3, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "a")).getResults().getNumFound()); + collectionClient.deleteByQuery("*:*"); + collectionClient.commit(); + + collectionClient.add (getDoc( id,100,shard_fld, "b!doc1")); + collectionClient.commit(); + assertEquals(1, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "b!")).getResults().getNumFound()); } 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 dfe7ff4eaf4..7e73cd818a3 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 @@ -34,10 +34,10 @@ import java.util.List; public class CompositeIdRouter extends HashBasedRouter { public static final String NAME = "compositeId"; - private int separator = '!'; + private static final int separator = '!'; // separator used to optionally specify number of bits to allocate toward first part. - private int bitsSeparator = '/'; + private static final int bitsSeparator = '/'; private int bits = 16; private int mask1 = 0xffff0000; private int mask2 = 0x0000ffff; @@ -62,28 +62,18 @@ public class CompositeIdRouter extends HashBasedRouter { @Override public int sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection) { String shardFieldName = getRouteField(collection); - String part1 = null; - int idx = 0; - int commaIdx = 0; - - if(shardFieldName == null || doc == null) { - idx = id.indexOf(separator); - if (idx < 0) { - return Hash.murmurhash3_x86_32(id, 0, id.length(), 0); - } - part1 = id.substring(0, idx); - commaIdx = part1.indexOf(bitsSeparator); - - } else { + if (shardFieldName != null && doc != null) { Object o = doc.getFieldValue(shardFieldName); - if (o != null) { - part1 = o.toString(); - return Hash.murmurhash3_x86_32(part1, 0, part1.length(), 0); - } else { + if (o == null) throw new SolrException (SolrException.ErrorCode.BAD_REQUEST, "No value for :"+shardFieldName + ". Unable to identify shard"); - } + id = o.toString(); } - + int idx = id.indexOf(separator); + if (idx < 0) { + return Hash.murmurhash3_x86_32(id, 0, id.length(), 0); + } + String part1 = id.substring(0, idx); + int commaIdx = part1.indexOf(bitsSeparator); int m1 = mask1; int m2 = mask2;