public List<Range> partitionRangeByKey(String key, Range range) { List<Range> result = new ArrayList<>(3); Range keyRange = keyHashRange(key); if (!keyRange.overlaps(range)) { throw new IllegalArgumentException("Key range does not overlap given range"); } if (keyRange.equals(range)) { return Collections.singletonList(keyRange); } else if (keyRange.isSubsetOf(range)) { result.add(new Range(range.min, keyRange.min - 1)); result.add(keyRange); result.add((new Range(keyRange.max + 1, range.max))); } else if (range.includes(keyRange.max)) { result.add(new Range(range.min, keyRange.max)); result.add(new Range(keyRange.max + 1, range.max)); } else { result.add(new Range(range.min, keyRange.min - 1)); result.add(new Range(keyRange.min, range.max)); } return result; }
public List<Range> partitionRangeByKey(String key, Range range) { List<Range> result = new ArrayList<>(3); Range keyRange = keyHashRange(key); if (!keyRange.overlaps(range)) { throw new IllegalArgumentException("Key range does not overlap given range"); } if (keyRange.equals(range)) { return Collections.singletonList(keyRange); } else if (keyRange.isSubsetOf(range)) { result.add(new Range(range.min, keyRange.min - 1)); result.add(keyRange); result.add((new Range(keyRange.max + 1, range.max))); } else if (range.includes(keyRange.max)) { result.add(new Range(range.min, keyRange.max)); result.add(new Range(keyRange.max + 1, range.max)); } else { result.add(new Range(range.min, keyRange.min - 1)); result.add(new Range(keyRange.min, range.max)); } return result; }
@Override public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) { if (shardKey == null) { // search across whole collection // TODO: this may need modification in the future when shard splitting could cause an overlap return collection.getActiveSlices(); } String id = shardKey; if (shardKey.indexOf(SEPARATOR) < 0) { // shardKey is a simple id, so don't do a range return Collections.singletonList(hashToSlice(Hash.murmurhash3_x86_32(id, 0, id.length(), 0), collection)); } Range completeRange = new KeyParser(id).getRange(); List<Slice> targetSlices = new ArrayList<>(1); for (Slice slice : collection.getActiveSlicesArr()) { Range range = slice.getRange(); if (range != null && range.overlaps(completeRange)) { targetSlices.add(slice); } } return targetSlices; }
@Override public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) { if (shardKey == null) { // search across whole collection // TODO: this may need modification in the future when shard splitting could cause an overlap return collection.getActiveSlices(); } String id = shardKey; if (shardKey.indexOf(SEPARATOR) < 0) { // shardKey is a simple id, so don't do a range return Collections.singletonList(hashToSlice(Hash.murmurhash3_x86_32(id, 0, id.length(), 0), collection)); } Range completeRange = new KeyParser(id).getRange(); List<Slice> targetSlices = new ArrayList<>(1); for (Slice slice : collection.getActiveSlices()) { Range range = slice.getRange(); if (range != null && range.overlaps(completeRange)) { targetSlices.add(slice); } } return targetSlices; }