/** * @param that range to check for intersection * @return true if the given range intersects with this range. */ public boolean intersects(Bounds<T> that) { // Same punishment than in Bounds.contains(), we must be carefull if that.left == that.right as // as new Range<T>(that.left, that.right) will then cover the full ring which is not what we // want. return contains(that.left) || (!that.left.equals(that.right) && intersects(new Range<T>(that.left, that.right))); }
/** * @param that range to check for intersection * @return true if the given range intersects with this range. */ public boolean intersects(Range<T> that) { return intersectionWith(that).size() > 0; }
private static List<AbstractBounds<PartitionPosition>> makeBounds(SSTableReader sstable, Collection<Range<Token>> tokenRanges) { List<AbstractBounds<PartitionPosition>> boundsList = new ArrayList<>(tokenRanges.size()); for (Range<Token> range : Range.normalize(tokenRanges)) addRange(sstable, Range.makeRowRange(range), boundsList); return boundsList; }
private boolean intersects(Range<Token> filterRange, boolean isSingleToken, boolean isFullRange, Range<Token> range) { boolean intersects; if (isFullRange) intersects = true; else if (isSingleToken) intersects = range.contains(filterRange.left); else { intersects = range.intersects(filterRange); } return intersects; }
private static <T extends RingPosition<T>> Set<Range<T>> intersectionOneWrapping(Range<T> wrapping, Range<T> other) { Set<Range<T>> intersection = new HashSet<Range<T>>(2); if (other.contains(wrapping.right)) intersection.add(new Range<T>(other.left, wrapping.right)); // need the extra compareto here because ranges are asymmetrical; wrapping.left _is not_ contained by the wrapping range if (other.contains(wrapping.left) && wrapping.left.compareTo(other.right) < 0) intersection.add(new Range<T>(wrapping.left, other.right)); return Collections.unmodifiableSet(intersection); }
if (that.contains(this)) return rangeSet(this); if (this.contains(that)) return rangeSet(that); boolean thiswraps = isWrapAround(left, right); boolean thatwraps = isWrapAround(that.left, that.right); if (!thiswraps && !thatwraps) return rangeSet(new Range<T>(ObjectUtils.max(this.left, that.left), ObjectUtils.min(this.right, that.right))); ? intersectionBothWrapping(this, that) : intersectionBothWrapping(that, this); return intersectionOneWrapping(this, that); return intersectionOneWrapping(that, this);
try List<Range<Token>> normalizedRanges = Range.normalize(ranges); if (r.contains(sstableBounds.left) && r.contains(sstableBounds.right)) break; else if (r.intersects(sstableBounds) && !nonAnticompacting.contains(sstable)) anticompactRanges.add(r.toString()); shouldAnticompact = true;
Token endToken = factory.fromString(range.group(2)); logger.info("adding range: ({},{}]", startToken, endToken); ranges.add(new Range<>(startToken, endToken)); for (Range<Token> localRange : localRanges) if (localRange.contains(specifiedRange)) throw new IllegalArgumentException(String.format("The specified range %s is not a range that is owned by this node. Please ensure that all token ranges specified to be rebuilt belong to this node.", specifiedRange.toString()));
for (Range<Token> range : keyspaceLocalRanges) if (range.contains(toRepair)) else if (range.intersects(toRepair)) "imprecise repair. keyspace: %s", toRepair.toString(), range.toString(), keyspaceName));
if (jobKeyRange.end_token != null) throw new IllegalArgumentException("only start_key supported"); jobRange = new Range<>(partitioner.getToken(jobKeyRange.start_key), partitioner.getToken(jobKeyRange.end_key), partitioner); } else if (jobKeyRange.start_token != null) { jobRange = new Range<>(partitioner.getTokenFactory().fromString(jobKeyRange.start_token), partitioner.getTokenFactory().fromString(jobKeyRange.end_token), partitioner); Range<Token> dhtRange = new Range<Token>(partitioner.getTokenFactory().fromString(range.start_token), partitioner.getTokenFactory().fromString(range.end_token), partitioner); if (dhtRange.intersects(jobRange)) { for (Range<Token> intersection : dhtRange.intersectionWith(jobRange)) { range.start_token = partitioner.getTokenFactory().toString(intersection.left); range.end_token = partitioner.getTokenFactory().toString(intersection.right);
List<Future<List<Shard>>> futures = new ArrayList<>(); TokenFactory tokenFactory = this.partitioner.getTokenFactory(); TokenRange tokenRange = rangeToTokenRange(new Range<>( tokenFactory.fromString(start), tokenFactory.fromString(end)));
/** return true if @param range intersects any of the given @param ranges */ public boolean intersects(Iterable<Range<T>> ranges) { for (Range<T> range2 : ranges) { if (range2.intersects(this)) return true; } return false; }
Set<Range<T>> intersectionSet = this.intersectionWith(rhs); if (intersectionSet.isEmpty()) if (intersections.length == 1) result = new HashSet<Range<T>>(rhs.subtractContained(intersections[0])); ArrayList<Range<T>> temp = rhs.subtractContained(first); result = new HashSet<Range<T>>(single.subtractContained(second));
/** * Determine the minimal set of sections that can be extracted from this SSTable to cover the given ranges. * @return A sorted list of (offset,end) pairs that cover the given ranges in the datafile for this SSTable. */ public List<Pair<Long,Long>> getPositionsForRanges(Collection<Range<Token>> ranges) { // use the index to determine a minimal section for each range List<Pair<Long,Long>> positions = new ArrayList<>(); for (Range<Token> range : Range.normalize(ranges)) { assert !range.isWrapAround() || range.right.isMinimum(); // truncate the range so it at most covers the sstable AbstractBounds<PartitionPosition> bounds = Range.makeRowRange(range); PartitionPosition leftBound = bounds.left.compareTo(first) > 0 ? bounds.left : first.getToken().minKeyBound(); PartitionPosition rightBound = bounds.right.isMinimum() ? last.getToken().maxKeyBound() : bounds.right; if (leftBound.compareTo(last) > 0 || rightBound.compareTo(first) < 0) continue; long left = getPosition(leftBound, Operator.GT).position; long right = (rightBound.compareTo(last) > 0) ? uncompressedLength() : getPosition(rightBound, Operator.GT).position; if (left == right) // empty range continue; assert left < right : String.format("Range=%s openReason=%s first=%s last=%s left=%d right=%d", range, openReason, first, last, left, right); positions.add(Pair.create(left, right)); } return positions; }
/** * @return A copy of the given list of with all ranges unwrapped, sorted by left bound and with overlapping bounds merged. */ public static <T extends RingPosition<T>> List<Range<T>> normalize(Collection<Range<T>> ranges) { // unwrap all List<Range<T>> output = new ArrayList<Range<T>>(ranges.size()); for (Range<T> range : ranges) output.addAll(range.unwrap()); // sort by left Collections.sort(output, new Comparator<Range<T>>() { public int compare(Range<T> b1, Range<T> b2) { return b1.left.compareTo(b2.left); } }); // deoverlap return deoverlap(output); }
public static <T extends RingPosition<T>> boolean isInRanges(T token, Iterable<Range<T>> ranges) { assert ranges != null; for (Range<T> range : ranges) { if (range.contains(token)) { return true; } } return false; }
public List<Range<T>> unwrap() { T minValue = right.minValue(); if (!isWrapAround() || right.equals(minValue)) return Arrays.asList(this); List<Range<T>> unwrapped = new ArrayList<Range<T>>(2); unwrapped.add(new Range<T>(left, minValue)); unwrapped.add(new Range<T>(minValue, right)); return unwrapped; }
@Override public String toString() { StringBuilder buff = new StringBuilder("#<TreeRange "); buff.append(super.toString()).append(" depth=").append(depth); return buff.append(">").toString(); } }
public OrderedRangeContainmentChecker(Collection<Range<Token>> ranges) { normalizedRangesIterator = normalize(ranges).iterator(); assert normalizedRangesIterator.hasNext(); currentRange = normalizedRangesIterator.next(); }
/** * Determine the minimal set of sections that can be extracted from this SSTable to cover the given ranges. * @return A sorted list of (offset,end) pairs that cover the given ranges in the datafile for this SSTable. */ public List<Pair<Long,Long>> getPositionsForRanges(Collection<Range<Token>> ranges) { // use the index to determine a minimal section for each range List<Pair<Long,Long>> positions = new ArrayList<>(); for (Range<Token> range : Range.normalize(ranges)) { assert !range.isWrapAround() || range.right.isMinimum(); // truncate the range so it at most covers the sstable AbstractBounds<RowPosition> bounds = range.toRowBounds(); RowPosition leftBound = bounds.left.compareTo(first) > 0 ? bounds.left : first.getToken().minKeyBound(); RowPosition rightBound = bounds.right.isMinimum() ? last.getToken().maxKeyBound() : bounds.right; if (leftBound.compareTo(last) > 0 || rightBound.compareTo(first) < 0) continue; long left = getPosition(leftBound, Operator.GT).position; long right = (rightBound.compareTo(last) > 0) ? uncompressedLength() : getPosition(rightBound, Operator.GT).position; if (left == right) // empty range continue; assert left < right : String.format("Range=%s openReason=%s first=%s last=%s left=%d right=%d", range, openReason, first, last, left, right); positions.add(Pair.create(left, right)); } return positions; }