mirror of https://github.com/apache/cassandra
expand CASSANDRA-8946 behaviour to all SSTableScanner constructors
This commit is contained in:
parent
bf1ea024d5
commit
4eef4499ba
|
|
@ -87,42 +87,7 @@ public class SSTableScanner implements ISSTableScanner
|
|||
this.dataRange = dataRange;
|
||||
|
||||
List<AbstractBounds<RowPosition>> boundsList = new ArrayList<>(2);
|
||||
if (dataRange.isWrapAround())
|
||||
{
|
||||
if (dataRange.stopKey().compareTo(sstable.first) >= 0)
|
||||
{
|
||||
// since we wrap, we must contain the whole sstable prior to stopKey()
|
||||
Boundary<RowPosition> left = new Boundary<RowPosition>(sstable.first, true);
|
||||
Boundary<RowPosition> right;
|
||||
right = dataRange.keyRange().rightBoundary();
|
||||
right = minRight(right, sstable.last, true);
|
||||
if (!isEmpty(left, right))
|
||||
boundsList.add(AbstractBounds.bounds(left, right));
|
||||
}
|
||||
if (dataRange.startKey().compareTo(sstable.last) <= 0)
|
||||
{
|
||||
// since we wrap, we must contain the whole sstable after dataRange.startKey()
|
||||
Boundary<RowPosition> right = new Boundary<RowPosition>(sstable.last, true);
|
||||
Boundary<RowPosition> left;
|
||||
left = dataRange.keyRange().leftBoundary();
|
||||
left = maxLeft(left, sstable.first, true);
|
||||
if (!isEmpty(left, right))
|
||||
boundsList.add(AbstractBounds.bounds(left, right));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert dataRange.startKey().compareTo(dataRange.stopKey()) <= 0 || dataRange.stopKey().isMinimum();
|
||||
Boundary<RowPosition> left, right;
|
||||
left = dataRange.keyRange().leftBoundary();
|
||||
right = dataRange.keyRange().rightBoundary();
|
||||
left = maxLeft(left, sstable.first, true);
|
||||
// apparently isWrapAround() doesn't count Bounds that extend to the limit (min) as wrapping
|
||||
right = dataRange.stopKey().isMinimum() ? new Boundary<RowPosition>(sstable.last, true)
|
||||
: minRight(right, sstable.last, true);
|
||||
if (!isEmpty(left, right))
|
||||
boundsList.add(AbstractBounds.bounds(left, right));
|
||||
}
|
||||
addRange(dataRange.keyRange(), boundsList);
|
||||
this.rangeIterator = boundsList.iterator();
|
||||
}
|
||||
|
||||
|
|
@ -140,28 +105,53 @@ public class SSTableScanner implements ISSTableScanner
|
|||
this.sstable = sstable;
|
||||
this.dataRange = null;
|
||||
|
||||
List<Range<Token>> normalized = Range.normalize(tokenRanges);
|
||||
List<AbstractBounds<RowPosition>> boundsList = new ArrayList<>(normalized.size());
|
||||
for (Range<Token> range : normalized)
|
||||
{
|
||||
// cap our ranges by the start/end of the sstable
|
||||
RowPosition right = range.right.maxKeyBound(sstable.partitioner);
|
||||
if (right.compareTo(sstable.last) > 0)
|
||||
right = sstable.last;
|
||||
|
||||
RowPosition left = range.left.maxKeyBound(sstable.partitioner);
|
||||
if (left.compareTo(sstable.first) < 0)
|
||||
{
|
||||
if (sstable.first.compareTo(right) <= 0)
|
||||
boundsList.add(new Bounds<>(sstable.first, right, sstable.partitioner));
|
||||
}
|
||||
else if (left.compareTo(right) < 0)
|
||||
boundsList.add(new Range<>(left, right, sstable.partitioner));
|
||||
}
|
||||
List<AbstractBounds<RowPosition>> boundsList = new ArrayList<>(tokenRanges.size());
|
||||
for (Range<Token> range : Range.normalize(tokenRanges))
|
||||
addRange(range.toRowBounds(), boundsList);
|
||||
|
||||
this.rangeIterator = boundsList.iterator();
|
||||
}
|
||||
|
||||
private void addRange(AbstractBounds<RowPosition> requested, List<AbstractBounds<RowPosition>> boundsList)
|
||||
{
|
||||
if (requested instanceof Range && ((Range)requested).isWrapAround())
|
||||
{
|
||||
if (requested.right.compareTo(sstable.first) >= 0)
|
||||
{
|
||||
// since we wrap, we must contain the whole sstable prior to stopKey()
|
||||
Boundary<RowPosition> left = new Boundary<RowPosition>(sstable.first, true);
|
||||
Boundary<RowPosition> right;
|
||||
right = requested.rightBoundary();
|
||||
right = minRight(right, sstable.last, true);
|
||||
if (!isEmpty(left, right))
|
||||
boundsList.add(AbstractBounds.bounds(left, right));
|
||||
}
|
||||
if (requested.left.compareTo(sstable.last) <= 0)
|
||||
{
|
||||
// since we wrap, we must contain the whole sstable after dataRange.startKey()
|
||||
Boundary<RowPosition> right = new Boundary<RowPosition>(sstable.last, true);
|
||||
Boundary<RowPosition> left;
|
||||
left = requested.leftBoundary();
|
||||
left = maxLeft(left, sstable.first, true);
|
||||
if (!isEmpty(left, right))
|
||||
boundsList.add(AbstractBounds.bounds(left, right));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert requested.left.compareTo(requested.right) <= 0 || requested.right.isMinimum();
|
||||
Boundary<RowPosition> left, right;
|
||||
left = requested.leftBoundary();
|
||||
right = requested.rightBoundary();
|
||||
left = maxLeft(left, sstable.first, true);
|
||||
// apparently isWrapAround() doesn't count Bounds that extend to the limit (min) as wrapping
|
||||
right = requested.right.isMinimum() ? new Boundary<RowPosition>(sstable.last, true)
|
||||
: minRight(right, sstable.last, true);
|
||||
if (!isEmpty(left, right))
|
||||
boundsList.add(AbstractBounds.bounds(left, right));
|
||||
}
|
||||
}
|
||||
|
||||
private void seekToCurrentRangeStart()
|
||||
{
|
||||
long indexPosition = sstable.getIndexScanPosition(currentRange.left);
|
||||
|
|
|
|||
Loading…
Reference in New Issue