Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 bf1ea024d -> 4eef4499b
  refs/heads/trunk 5735f2a25 -> 2bfd3c415


expand CASSANDRA-8946 behaviour to all SSTableScanner constructors


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4eef4499
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4eef4499
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4eef4499

Branch: refs/heads/cassandra-2.1
Commit: 4eef4499ba24dd5168fdd759f4e2587892e4394b
Parents: bf1ea02
Author: Benedict Elliott Smith <bened...@apache.org>
Authored: Tue Mar 24 13:35:01 2015 +0000
Committer: Benedict Elliott Smith <bened...@apache.org>
Committed: Tue Mar 24 13:35:01 2015 +0000

----------------------------------------------------------------------
 .../cassandra/io/sstable/SSTableScanner.java    | 82 +++++++++-----------
 1 file changed, 36 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4eef4499/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java 
b/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
index 46ddc24..5163107 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
@@ -87,24 +87,51 @@ public class SSTableScanner implements ISSTableScanner
         this.dataRange = dataRange;
 
         List<AbstractBounds<RowPosition>> boundsList = new ArrayList<>(2);
-        if (dataRange.isWrapAround())
+        addRange(dataRange.keyRange(), boundsList);
+        this.rangeIterator = boundsList.iterator();
+    }
+
+    /**
+     * @param sstable SSTable to scan; must not be null
+     * @param tokenRanges A set of token ranges to scan
+     * @param limiter background i/o RateLimiter; may be null
+     */
+    private SSTableScanner(SSTableReader sstable, Collection<Range<Token>> 
tokenRanges, RateLimiter limiter)
+    {
+        assert sstable != null;
+
+        this.dfile = limiter == null ? sstable.openDataReader() : 
sstable.openDataReader(limiter);
+        this.ifile = sstable.openIndexReader();
+        this.sstable = sstable;
+        this.dataRange = null;
+
+        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 (dataRange.stopKey().compareTo(sstable.first) >= 0)
+            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 = dataRange.keyRange().rightBoundary();
+                right = requested.rightBoundary();
                 right = minRight(right, sstable.last, true);
                 if (!isEmpty(left, right))
                     boundsList.add(AbstractBounds.bounds(left, right));
             }
-            if (dataRange.startKey().compareTo(sstable.last) <= 0)
+            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 = dataRange.keyRange().leftBoundary();
+                left = requested.leftBoundary();
                 left = maxLeft(left, sstable.first, true);
                 if (!isEmpty(left, right))
                     boundsList.add(AbstractBounds.bounds(left, right));
@@ -112,54 +139,17 @@ public class SSTableScanner implements ISSTableScanner
         }
         else
         {
-            assert dataRange.startKey().compareTo(dataRange.stopKey()) <= 0 || 
dataRange.stopKey().isMinimum();
+            assert requested.left.compareTo(requested.right) <= 0 || 
requested.right.isMinimum();
             Boundary<RowPosition> left, right;
-            left = dataRange.keyRange().leftBoundary();
-            right = dataRange.keyRange().rightBoundary();
+            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 = dataRange.stopKey().isMinimum() ? new 
Boundary<RowPosition>(sstable.last, true)
+            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));
         }
-        this.rangeIterator = boundsList.iterator();
-    }
-
-    /**
-     * @param sstable SSTable to scan; must not be null
-     * @param tokenRanges A set of token ranges to scan
-     * @param limiter background i/o RateLimiter; may be null
-     */
-    private SSTableScanner(SSTableReader sstable, Collection<Range<Token>> 
tokenRanges, RateLimiter limiter)
-    {
-        assert sstable != null;
-
-        this.dfile = limiter == null ? sstable.openDataReader() : 
sstable.openDataReader(limiter);
-        this.ifile = sstable.openIndexReader();
-        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));
-        }
-
-        this.rangeIterator = boundsList.iterator();
     }
 
     private void seekToCurrentRangeStart()

Reply via email to