You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2015/07/23 10:52:08 UTC

cassandra git commit: Ninja fixup for KeyspaceTest.testGetSliceFromLarge

Repository: cassandra
Updated Branches:
  refs/heads/trunk 2b0a8f6bd -> 07b89d451


Ninja fixup for KeyspaceTest.testGetSliceFromLarge


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

Branch: refs/heads/trunk
Commit: 07b89d45198cc336e2adebdd554c964b0c08e605
Parents: 2b0a8f6
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Thu Jul 23 09:35:14 2015 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Thu Jul 23 10:51:53 2015 +0200

----------------------------------------------------------------------
 .../columniterator/AbstractSSTableIterator.java | 14 +++++++---
 .../db/columniterator/SSTableIterator.java      | 23 ++++++++++++----
 .../columniterator/SSTableReversedIterator.java | 28 +++++++++++++-------
 3 files changed, 47 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/07b89d45/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java b/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
index 4a35e80..fe8d1f0 100644
--- a/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
+++ b/src/java/org/apache/cassandra/db/columniterator/AbstractSSTableIterator.java
@@ -417,7 +417,7 @@ abstract class AbstractSSTableIterator implements SliceableUnfilteredRowIterator
         private final List<IndexHelper.IndexInfo> indexes;
         private final boolean reversed;
 
-        private int currentIndexIdx = -1;
+        private int currentIndexIdx;
 
         // Marks the beginning of the block corresponding to currentIndexIdx.
         private FileMark mark;
@@ -469,16 +469,22 @@ abstract class AbstractSSTableIterator implements SliceableUnfilteredRowIterator
             return indexes.get(currentIndexIdx);
         }
 
-        // Finds the index of the first block containing the provided bound, starting at the current index.
+        // Finds the index of the first block containing the provided bound, starting at the provided index.
         // Will be -1 if the bound is before any block, and blocksCount() if it is after every block.
-        public int findBlockIndex(Slice.Bound bound)
+        public int findBlockIndex(Slice.Bound bound, int fromIdx)
         {
             if (bound == Slice.Bound.BOTTOM)
                 return -1;
             if (bound == Slice.Bound.TOP)
                 return blocksCount();
 
-            return IndexHelper.indexFor(bound, indexes, comparator, reversed, currentIndexIdx);
+            return IndexHelper.indexFor(bound, indexes, comparator, reversed, fromIdx);
+        }
+
+        @Override
+        public String toString()
+        {
+            return String.format("IndexState(indexSize=%d, currentBlock=%d, reversed=%b)", indexes.size(), currentIndexIdx, reversed);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/07b89d45/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java b/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
index 64d33dc..e985c18 100644
--- a/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
+++ b/src/java/org/apache/cassandra/db/columniterator/SSTableIterator.java
@@ -217,28 +217,41 @@ public class SSTableIterator extends AbstractSSTableIterator
             }
 
             // Find the first index block we'll need to read for the slice.
-            int startIdx = indexState.findBlockIndex(slice.start());
+            int startIdx = indexState.findBlockIndex(slice.start(), indexState.currentBlockIdx());
             if (startIdx >= indexState.blocksCount())
             {
                 sliceDone = true;
                 return;
             }
 
+            // Find the last index block we'll need to read for the slice.
+            lastBlockIdx = indexState.findBlockIndex(slice.end(), startIdx);
+
+            // If the slice end is before the very first block, we have nothing for that slice
+            if (lastBlockIdx < 0)
+            {
+                assert startIdx < 0;
+                sliceDone = true;
+                return;
+            }
+
+            // If we start before the very first block, just read from the first one.
+            if (startIdx < 0)
+                startIdx = 0;
+
             // If that's the last block we were reading, we're already where we want to be. Otherwise,
             // seek to that first block
             if (startIdx != indexState.currentBlockIdx())
                 indexState.setToBlock(startIdx);
 
-            // Find the last index block we'll need to read for the slice.
-            lastBlockIdx = indexState.findBlockIndex(slice.end());
-
             // The index search is based on the last name of the index blocks, so at that point we have that:
             //   1) indexes[currentIdx - 1].lastName < slice.start <= indexes[currentIdx].lastName
             //   2) indexes[lastBlockIdx - 1].lastName < slice.end <= indexes[lastBlockIdx].lastName
             // so if currentIdx == lastBlockIdx and slice.end < indexes[currentIdx].firstName, we're guaranteed that the
             // whole slice is between the previous block end and this block start, and thus has no corresponding
             // data. One exception is if the previous block ends with an openMarker as it will cover our slice
-            // and we need to return it.
+            // and we need to return it (we also don't skip the slice for the old format because we didn't have the openMarker
+            // info in that case and can't rely on this optimization).
             if (indexState.currentBlockIdx() == lastBlockIdx
                 && metadata().comparator.compare(slice.end(), indexState.currentIndex().firstName) < 0
                 && openMarker == null

http://git-wip-us.apache.org/repos/asf/cassandra/blob/07b89d45/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java b/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
index e15d330..4082874 100644
--- a/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
+++ b/src/java/org/apache/cassandra/db/columniterator/SSTableReversedIterator.java
@@ -213,9 +213,8 @@ public class SSTableReversedIterator extends AbstractSSTableIterator
 
         protected void init() throws IOException
         {
-            // If this is called, it means we're calling hasNext() before any call to setForSlice. Which means
-            // we're reading everything from the end. So just set us up on the last block.
-            indexState.setToBlock(indexState.blocksCount() - 1);
+            // This is actually a no-op, because if we call hasNext without having called setForSlice, then ReverseReader.hasNextInternal
+            // will call setForSlice(Slice.ALL) which does the right thing.
         }
 
         @Override
@@ -232,21 +231,32 @@ public class SSTableReversedIterator extends AbstractSSTableIterator
             }
 
             // Find the first index block we'll need to read for the slice.
-            int startIdx = indexState.findBlockIndex(slice.end());
+            int startIdx = indexState.findBlockIndex(slice.end(), indexState.currentBlockIdx());
             if (startIdx < 0)
             {
                 iterator = Collections.emptyIterator();
                 return;
             }
 
-            boolean isCurrentBlock = startIdx == indexState.currentBlockIdx();
-            if (!isCurrentBlock)
-                indexState.setToBlock(startIdx);
+            lastBlockIdx = indexState.findBlockIndex(slice.start(), startIdx);
 
-            lastBlockIdx = indexState.findBlockIndex(slice.start());
+            // If the last block to look (in reverse order) is after the very last block, we have nothing for that slice
+            if (lastBlockIdx >= indexState.blocksCount())
+            {
+                assert startIdx >= indexState.blocksCount();
+                iterator = Collections.emptyIterator();
+                return;
+            }
 
-            if (!isCurrentBlock)
+            // If we start (in reverse order) after the very last block, just read from the last one.
+            if (startIdx >= indexState.blocksCount())
+                startIdx = indexState.blocksCount() - 1;
+
+            if (startIdx != indexState.currentBlockIdx())
+            {
+                indexState.setToBlock(startIdx);
                 readCurrentBlock(true);
+            }
 
             setIterator(slice);
         }