Package org.apache.cassandra.dht
Class Range<T extends RingPosition<T>>
- java.lang.Object
-
- org.apache.cassandra.dht.AbstractBounds<T>
-
- org.apache.cassandra.dht.Range<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Range<T>>
- Direct Known Subclasses:
MerkleTree.TreeRange
public class Range<T extends RingPosition<T>> extends AbstractBounds<T> implements java.lang.Comparable<Range<T>>, java.io.Serializable
A representation of the range that a node is responsible for on the DHT ring. A Range is responsible for the tokens between (left, right]. Used by the partitioner and by map/reduce by-token range scans. Note: this class has a natural ordering that is inconsistent with equals- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Range.OrderedRangeContainmentChecker
Helper class to check if a token is contained within a given collection of ranges-
Nested classes/interfaces inherited from class org.apache.cassandra.dht.AbstractBounds
AbstractBounds.AbstractBoundsSerializer<T extends RingPosition<T>>, AbstractBounds.Boundary<T extends RingPosition<T>>
-
-
Field Summary
Fields Modifier and Type Field Description static long
serialVersionUID
-
Fields inherited from class org.apache.cassandra.dht.AbstractBounds
left, right, rowPositionSerializer, tokenSerializer
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.String>
asList()
static <T extends RingPosition<T>>
voidassertNormalized(java.util.List<Range<T>> ranges)
int
compareTo(Range<T> rhs)
Note: this class has a natural ordering that is inconsistent with equalsboolean
contains(Range<T> that)
boolean
contains(T point)
Helps determine if a given point on the DHT ring is contained in the range in question.static <T extends RingPosition<T>>
booleancontains(T left, T right, T point)
static <T extends RingPosition<T>>
java.util.List<Range<T>>deoverlap(java.util.List<Range<T>> ranges)
Given a list of unwrapped ranges sorted by left position, return an equivalent list of ranges but with no overlapping ranges.java.util.Set<Range<T>>
differenceToFetch(Range<T> rhs)
Calculate set of the difference ranges of given two ranges (as current (A, B] and rhs is (C, D]) which node will need to fetch when moving to a given new tokenboolean
equals(java.lang.Object o)
protected java.lang.String
getClosingString()
protected java.lang.String
getOpeningString()
boolean
inclusiveLeft()
boolean
inclusiveRight()
Range<T>
intersectionNonWrapping(Range<T> that)
Returns the intersection of this range with the provided one, assuming neither are wrapping.java.util.Set<Range<T>>
intersectionWith(Range<T> that)
static boolean
intersects(java.lang.Iterable<Range<Token>> l, java.lang.Iterable<Range<Token>> r)
boolean
intersects(AbstractBounds<T> that)
boolean
intersects(Bounds<T> that)
boolean
intersects(Range<T> that)
boolean
isEndInclusive()
static <T extends RingPosition<T>>
booleanisInRanges(T token, java.lang.Iterable<Range<T>> ranges)
boolean
isStartInclusive()
boolean
isTrulyWrapAround()
Checks if the range truly wraps around.static <T extends RingPosition<T>>
booleanisTrulyWrapAround(T left, T right)
boolean
isWrapAround()
static <T extends RingPosition<T>>
booleanisWrapAround(T left, T right)
Tells if the given range is a wrap around.static Range<PartitionPosition>
makeRowRange(Range<Token> tokenBounds)
static Range<PartitionPosition>
makeRowRange(Token left, Token right)
Compute a range of keys corresponding to a given range of token.static <T extends RingPosition<T>>
java.util.List<Range<T>>normalize(java.util.Collection<Range<T>> ranges)
static <T extends RingPosition<T>>
java.util.Set<Range<T>>rangeSet(Range<T> range)
static <T extends RingPosition<T>>
java.util.Set<Range<T>>rangeSet(Range<T>... ranges)
static <T extends RingPosition<T>>
java.util.List<Range<T>>sort(java.util.Collection<Range<T>> ranges)
Pair<AbstractBounds<T>,AbstractBounds<T>>
split(T position)
Given token T and AbstractBounds ?L,R?, returns Pair(?L,T], (T,R?), where ? means that the same type of AbstractBounds is returned as the original.static <T extends RingPosition<T>>
java.util.Set<Range<T>>subtract(java.util.Collection<Range<T>> ranges, java.util.Collection<Range<T>> subtract)
java.util.Set<Range<T>>
subtract(Range<T> rhs)
java.util.Set<Range<T>>
subtractAll(java.util.Collection<Range<T>> ranges)
java.lang.String
toString()
java.util.List<Range<T>>
unwrap()
AbstractBounds<T>
withNewRight(T newRight)
-
Methods inherited from class org.apache.cassandra.dht.AbstractBounds
bounds, bounds, getString, hashCode, intersects, isEmpty, leftBoundary, maxLeft, maxLeft, minRight, minRight, noneStrictlyWrapsAround, rightBoundary, strictlyWrapsAround
-
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
contains
public static <T extends RingPosition<T>> boolean contains(T left, T right, T point)
-
contains
public boolean contains(T point)
Helps determine if a given point on the DHT ring is contained in the range in question.- Specified by:
contains
in classAbstractBounds<T extends RingPosition<T>>
- Parameters:
point
- point in question- Returns:
- true if the point contains within the range else false.
-
intersects
public boolean intersects(Range<T> that)
- Parameters:
that
- range to check for intersection- Returns:
- true if the given range intersects with this range.
-
intersects
public boolean intersects(AbstractBounds<T> that)
-
intersects
public boolean intersects(Bounds<T> that)
- Parameters:
that
- range to check for intersection- Returns:
- true if the given range intersects with this range.
-
intersects
public static boolean intersects(java.lang.Iterable<Range<Token>> l, java.lang.Iterable<Range<Token>> r)
-
rangeSet
@SafeVarargs public static <T extends RingPosition<T>> java.util.Set<Range<T>> rangeSet(Range<T>... ranges)
-
rangeSet
public static <T extends RingPosition<T>> java.util.Set<Range<T>> rangeSet(Range<T> range)
-
intersectionWith
public java.util.Set<Range<T>> intersectionWith(Range<T> that)
- Parameters:
that
-- Returns:
- the intersection of the two Ranges. this can be two disjoint Ranges if one is wrapping and one is not. say you have nodes G and M, with query range (D,T]; the intersection is (M-T] and (D-G]. If there is no intersection, an empty list is returned.
-
intersectionNonWrapping
public Range<T> intersectionNonWrapping(Range<T> that)
Returns the intersection of this range with the provided one, assuming neither are wrapping.- Parameters:
that
- the other range to return the intersection with. It must not be wrapping.- Returns:
- the intersection of
this
andthat
, ornull
if both ranges don't intersect.
-
split
public Pair<AbstractBounds<T>,AbstractBounds<T>> split(T position)
Description copied from class:AbstractBounds
Given token T and AbstractBounds ?L,R?, returns Pair(?L,T], (T,R?), where ? means that the same type of AbstractBounds is returned as the original. Put another way, returns a Pair of everything this AbstractBounds contains up to and including the split position, and everything it contains after (not including the split position). The original AbstractBounds must either contain the position T, or T should be equals to the left bound L. If the split would only yield the same AbstractBound, null is returned instead.- Specified by:
split
in classAbstractBounds<T extends RingPosition<T>>
-
inclusiveLeft
public boolean inclusiveLeft()
- Specified by:
inclusiveLeft
in classAbstractBounds<T extends RingPosition<T>>
-
inclusiveRight
public boolean inclusiveRight()
- Specified by:
inclusiveRight
in classAbstractBounds<T extends RingPosition<T>>
-
unwrap
public java.util.List<Range<T>> unwrap()
- Specified by:
unwrap
in classAbstractBounds<T extends RingPosition<T>>
-
isWrapAround
public static <T extends RingPosition<T>> boolean isWrapAround(T left, T right)
Tells if the given range is a wrap around.
-
isTrulyWrapAround
public boolean isTrulyWrapAround()
Checks if the range truly wraps around. This exists only becauseisWrapAround()
is a tad dumb and return true if right is the minimum token, no matter what left is, but for most intent and purposes, such range doesn't truly warp around (unwrap produces the identity in this case).Also note that it could be that the remaining uses of
isWrapAround()
could be replaced by this method, but that is to be checked carefully at some other time (Sylvain).The one thing this method guarantees is that if it's true, then
unwrap()
will return a list with exactly 2 ranges, never one.
-
isTrulyWrapAround
public static <T extends RingPosition<T>> boolean isTrulyWrapAround(T left, T right)
-
compareTo
public int compareTo(Range<T> rhs)
Note: this class has a natural ordering that is inconsistent with equals- Specified by:
compareTo
in interfacejava.lang.Comparable<T extends RingPosition<T>>
-
subtract
public static <T extends RingPosition<T>> java.util.Set<Range<T>> subtract(java.util.Collection<Range<T>> ranges, java.util.Collection<Range<T>> subtract)
-
differenceToFetch
public java.util.Set<Range<T>> differenceToFetch(Range<T> rhs)
Calculate set of the difference ranges of given two ranges (as current (A, B] and rhs is (C, D]) which node will need to fetch when moving to a given new token- Parameters:
rhs
- range to calculate difference- Returns:
- set of difference ranges
-
isInRanges
public static <T extends RingPosition<T>> boolean isInRanges(T token, java.lang.Iterable<Range<T>> ranges)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getOpeningString
protected java.lang.String getOpeningString()
- Specified by:
getOpeningString
in classAbstractBounds<T extends RingPosition<T>>
-
getClosingString
protected java.lang.String getClosingString()
- Specified by:
getClosingString
in classAbstractBounds<T extends RingPosition<T>>
-
isStartInclusive
public boolean isStartInclusive()
- Specified by:
isStartInclusive
in classAbstractBounds<T extends RingPosition<T>>
-
isEndInclusive
public boolean isEndInclusive()
- Specified by:
isEndInclusive
in classAbstractBounds<T extends RingPosition<T>>
-
asList
public java.util.List<java.lang.String> asList()
-
isWrapAround
public boolean isWrapAround()
-
normalize
public static <T extends RingPosition<T>> java.util.List<Range<T>> normalize(java.util.Collection<Range<T>> ranges)
- Returns:
- A copy of the given list of with all ranges unwrapped, sorted by left bound and with overlapping bounds merged.
-
deoverlap
public static <T extends RingPosition<T>> java.util.List<Range<T>> deoverlap(java.util.List<Range<T>> ranges)
Given a list of unwrapped ranges sorted by left position, return an equivalent list of ranges but with no overlapping ranges.
-
withNewRight
public AbstractBounds<T> withNewRight(T newRight)
- Specified by:
withNewRight
in classAbstractBounds<T extends RingPosition<T>>
-
sort
public static <T extends RingPosition<T>> java.util.List<Range<T>> sort(java.util.Collection<Range<T>> ranges)
-
makeRowRange
public static Range<PartitionPosition> makeRowRange(Token left, Token right)
Compute a range of keys corresponding to a given range of token.
-
makeRowRange
public static Range<PartitionPosition> makeRowRange(Range<Token> tokenBounds)
-
assertNormalized
public static <T extends RingPosition<T>> void assertNormalized(java.util.List<Range<T>> ranges)
-
-