lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1418337 - in /lucene/dev/trunk/solr: core/src/test/org/apache/solr/cloud/TestHashPartitioner.java solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
Date Fri, 07 Dec 2012 14:47:35 GMT
Author: yonik
Date: Fri Dec  7 14:47:34 2012
New Revision: 1418337

URL: http://svn.apache.org/viewvc?rev=1418337&view=rev
Log:
SOLR-2592: fix composite id router for full-range

Modified:
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java?rev=1418337&r1=1418336&r2=1418337&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java Fri
Dec  7 14:47:34 2012
@@ -19,6 +19,7 @@ package org.apache.solr.cloud;
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -32,6 +33,7 @@ import org.apache.solr.common.cloud.DocR
 import org.apache.solr.common.cloud.PlainIdRouter;
 import org.apache.solr.common.cloud.Slice;
 import org.apache.solr.common.util.Hash;
+import org.apache.solr.common.util.StrUtils;
 
 public class TestHashPartitioner extends SolrTestCaseJ4 {
   
@@ -95,17 +97,31 @@ public class TestHashPartitioner extends
   }
 
   public void doId(DocCollection coll, String id, String expectedShard) {
+    doIndex(coll, id, expectedShard);
+    doQuery(coll, id, expectedShard);
+  }
+
+  public void doIndex(DocCollection coll, String id, String expectedShard) {
     DocRouter router = coll.getRouter();
     Slice target = router.getTargetSlice(id, null, null, coll);
     assertEquals(expectedShard, target.getName());
+  }
 
+  public void doQuery(DocCollection coll, String id, String expectedShards) {
+    DocRouter router = coll.getRouter();
     Collection<Slice> slices = router.getSearchSlices(id, null, coll);
 
-    assertEquals(1, slices.size());
-    target = slices.iterator().next();
-    assertEquals(expectedShard, target.getName());
-  }
+    List<String> expectedShardStr = StrUtils.splitSmart(expectedShards, ",", true);
 
+    HashSet<String> expectedSet = new HashSet<String>(expectedShardStr);
+    HashSet<String> obtainedSet = new HashSet<String>();
+    for (Slice slice : slices) {
+      obtainedSet.add(slice.getName());
+    }
+
+    assertEquals(slices.size(), obtainedSet.size());  // make sure no repeated slices
+    assertEquals(expectedSet, obtainedSet);
+  }
 
   public void testCompositeHashCodes() throws Exception {
     DocRouter router = DocRouter.getDocRouter(CompositeIdRouter.NAME);
@@ -122,7 +138,8 @@ public class TestHashPartitioner extends
     doId(coll, "d!baz", "shard3");
     doId(coll, "e!qux", "shard4");
 
-    // syntax to specify bits.  Anything over 2 should give the same results as above (since
only top 2 bits
+    // syntax to specify bits.
+    // Anything over 2 bits should give the same results as above (since only top 2 bits
     // affect our 4 slice collection).
     doId(coll, "b/2!foo", "shard1");
     doId(coll, "c/2!bar", "shard2");
@@ -133,6 +150,18 @@ public class TestHashPartitioner extends
     doId(coll, "c/32!bar", "shard2");
     doId(coll, "d/32!baz", "shard3");
     doId(coll, "e/32!qux", "shard4");
+
+    // no bits allocated to the first part (kind of odd why anyone would do that though)
+    doIndex(coll, "foo/0!b", "shard1");
+    doIndex(coll, "foo/0!c", "shard2");
+    doIndex(coll, "foo/0!d", "shard3");
+    doIndex(coll, "foo/0!e", "shard4");
+
+    // means cover whole range on the query side
+    doQuery(coll, "foo/0!", "shard1,shard2,shard3,shard4");
+
+    doQuery(coll, "b/1!", "shard1,shard2");   // top bit of hash(b)==1, so shard1 and shard2
+    doQuery(coll, "d/1!", "shard3,shard4");   // top bit of hash(b)==0, so shard3 and shard4
   }
 
   /***

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java?rev=1418337&r1=1418336&r2=1418337&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
Fri Dec  7 14:47:34 2012
@@ -123,6 +123,16 @@ public class CompositeIdRouter extends H
     int lowerBound = upperBits;
     int upperBound = upperBits | m2;
 
+    if (m1 == 0) {
+      // no bits used from first part of key.. the code above will produce 0x000000000->0xffffffff
which only works on unsigned space, but we're using signed space.
+      lowerBound = Integer.MIN_VALUE;
+      upperBound = Integer.MAX_VALUE;
+    }
+
+    if (lowerBound > upperBound) {
+      // nocommit
+      throw new RuntimeException("WHAAAT?");
+    }
     // lowerBound will be greater than upperBound if we are in the negatives
     Range completeRange = new Range(lowerBound, upperBound);
 



Mime
View raw message