SOLR-2592: fix composite id router slice selection

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1418116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2012-12-06 22:36:52 +00:00
parent 5cb909b11f
commit c08e5eaf20
2 changed files with 16 additions and 4 deletions

View File

@ -17,6 +17,7 @@ package org.apache.solr.cloud;
* the License.
*/
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -97,6 +98,15 @@ public class TestHashPartitioner extends SolrTestCaseJ4 {
DocRouter router = coll.getRouter();
Slice target = router.getTargetSlice(id, null, null, coll);
assertEquals(expectedShard, target.getName());
Collection<Slice> slices = router.getSearchSlices(id, null, coll);
if (slices.size() != 1) { // nocommit
slices = router.getSearchSlices(id, null, coll);
}
assertEquals(1, slices.size());
target = slices.iterator().next();
assertEquals(expectedShard, target.getName());
}

View File

@ -122,16 +122,18 @@ public class CompositeIdRouter extends HashBasedRouter {
int upperBits = hash1 & m1;
int lowerBound = upperBits;
int upperBound = upperBits | m2;
// lowerBound will be greater than upperBound if we are in the negatives
Range completeRange = new Range(lowerBound, upperBound);
List<Slice> slices = new ArrayList(1);
for (Slice slice : slices) {
List<Slice> targetSlices = new ArrayList<Slice>(1);
for (Slice slice : collection.getSlices()) {
Range range = slice.getRange();
if (range != null && range.overlaps(completeRange)) {
slices.add(slice);
targetSlices.add(slice);
}
}
return slices;
return targetSlices;
}
}