You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2013/10/07 11:42:23 UTC

svn commit: r1529808 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java solr/solrj/ solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java

Author: noble
Date: Mon Oct  7 09:42:23 2013
New Revision: 1529808

URL: http://svn.apache.org/r1529808
Log:
SOLR-5258 compute full composite hash on router.field

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java?rev=1529808&r1=1529807&r2=1529808&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java Mon Oct  7 09:42:23 2013
@@ -417,6 +417,12 @@ public class CustomCollectionTest extend
     //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());
 
   }
 

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java?rev=1529808&r1=1529807&r2=1529808&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java Mon Oct  7 09:42:23 2013
@@ -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 H
   @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;