lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1418100 - 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 Thu, 06 Dec 2012 21:51:33 GMT
Author: yonik
Date: Thu Dec  6 21:51:32 2012
New Revision: 1418100

URL: http://svn.apache.org/viewvc?rev=1418100&view=rev
Log:
SOLR-2592: fix shifting by 32 bits in compositeId router

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=1418100&r1=1418099&r2=1418100&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 Thu
Dec  6 21:51:32 2012
@@ -115,12 +115,17 @@ public class TestHashPartitioner extends
     doId(coll, "d!baz", "shard3");
     doId(coll, "e!qux", "shard4");
 
-    // syntax to specify bits
+    // syntax to specify bits.  Anything over 2 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");
     doId(coll, "d/2!baz", "shard3");
     doId(coll, "e/2!qux", "shard4");
 
+    doId(coll, "b/32!foo", "shard1");
+    doId(coll, "c/32!bar", "shard2");
+    doId(coll, "d/32!baz", "shard3");
+    doId(coll, "e/32!qux", "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=1418100&r1=1418099&r2=1418100&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
Thu Dec  6 21:51:32 2012
@@ -41,10 +41,11 @@ public class CompositeIdRouter extends H
   private int mask1 = 0xffff0000;
   private int mask2 = 0x0000ffff;
 
-  protected void setBits(int bits) {
-    this.bits = bits;
-    mask1 = -1 << (32-bits);
-    mask2 = -1 >>> bits;
+  protected void setBits(int firstBits) {
+    this.bits = firstBits;
+    // java can't shift 32 bits
+    mask1 = firstBits==0 ? 0 : (-1 << (32-firstBits));
+    mask2 = firstBits==32 ? 0 : (-1 >>> firstBits);
   }
 
   protected int getBits(String firstPart, int commaIdx) {
@@ -72,8 +73,8 @@ public class CompositeIdRouter extends H
     if (commaIdx > 0) {
       int firstBits = getBits(part1, commaIdx);
       if (firstBits >= 0) {
-        m1 = -1 << (32-firstBits);
-        m2 = -1 >>> firstBits;
+        m1 = firstBits==0 ? 0 : (-1 << (32-firstBits));
+        m2 = firstBits==32 ? 0 : (-1 >>> firstBits);
         part1 = part1.substring(0, commaIdx);
       }
     }
@@ -108,8 +109,8 @@ public class CompositeIdRouter extends H
     if (bitsSepIdx > 0) {
       int firstBits = getBits(part1, bitsSepIdx);
       if (firstBits >= 0) {
-        m1 = -1 << (32-firstBits);
-        m2 = -1 >>> firstBits;
+        m1 = firstBits==0 ? 0 : (-1 << (32-firstBits));
+        m2 = firstBits==32 ? 0 : (-1 >>> firstBits);
         part1 = part1.substring(0, bitsSepIdx);
       }
     }



Mime
View raw message