cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject git commit: fix regression when requested range does not overlap an sstable at all patch by marcuse; reviewed by jbellis for CASSANDRA-5407
Date Wed, 03 Apr 2013 20:23:32 GMT
Updated Branches:
  refs/heads/trunk 4271d19a1 -> e306a87b7


fix regression when requested range does not overlap an sstable at all
patch by marcuse; reviewed by jbellis for CASSANDRA-5407


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

Branch: refs/heads/trunk
Commit: e306a87b7d8e1ef15a5269006d7706a4c97d1798
Parents: 4271d19
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Wed Apr 3 15:23:07 2013 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Wed Apr 3 15:23:25 2013 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 +-
 .../io/sstable/SSTableBoundedScanner.java          |    5 +-
 .../apache/cassandra/io/sstable/SSTableReader.java |   46 ++++++++++++++-
 .../cassandra/io/sstable/SSTableReaderTest.java    |   25 ++++++++
 4 files changed, 73 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e306a87b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 060561f..004607e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,7 +2,7 @@
  * Add yaml network topology snitch for mixed ec2/other envs (CASSANDRA-5339)
  * Log when a node is down longer than the hint window (CASSANDRA-4554)
  * Optimize tombstone creation for ExpiringColumns (CASSANDRA-4917)
- * Improve LeveledScanner work estimation (CASSANDRA-5250)
+ * Improve LeveledScanner work estimation (CASSANDRA-5250, 5407)
  * Replace compaction lock with runWithCompactionsDisabled (CASSANDRA-3430)
  * Change Message IDs to ints (CASSANDRA-5307)
  * Move sstable level information into the Stats component, removing the

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e306a87b/src/java/org/apache/cassandra/io/sstable/SSTableBoundedScanner.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableBoundedScanner.java b/src/java/org/apache/cassandra/io/sstable/SSTableBoundedScanner.java
index af6a654..592ce28 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableBoundedScanner.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableBoundedScanner.java
@@ -35,10 +35,11 @@ public class SSTableBoundedScanner extends SSTableScanner
     private final Iterator<Pair<Long, Long>> rangeIterator;
     private Pair<Long, Long> currentRange;
 
-    SSTableBoundedScanner(SSTableReader sstable, Range<Token> range)
+    SSTableBoundedScanner(SSTableReader sstable, Iterator<Pair<Long, Long>> rangeIterator)
     {
         super(sstable);
-        this.rangeIterator = sstable.getPositionsForRanges(Collections.singletonList(range)).iterator();
+        assert rangeIterator.hasNext(); // use EmptyCompactionScanner otherwise
+        this.rangeIterator = rangeIterator;
         currentRange = rangeIterator.next();
         dfile.seek(currentRange.left);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e306a87b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
index e73bd67..4bdfebb 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
@@ -1019,8 +1019,11 @@ public class SSTableReader extends SSTable
     {
         if (range == null)
             return getScanner();
-
-        return new SSTableBoundedScanner(this, range);
+        Iterator<Pair<Long, Long>> rangeIterator = getPositionsForRanges(Collections.singletonList(range)).iterator();
+        if (rangeIterator.hasNext())
+            return new SSTableBoundedScanner(this, rangeIterator);
+        else
+            return new EmptyCompactionScanner(getFilename());
     }
 
     public FileDataInput getFileDataInput(long position)
@@ -1286,4 +1289,43 @@ public class SSTableReader extends SSTable
             FileUtils.closeQuietly(file);
         }
     }
+
+    protected class EmptyCompactionScanner implements ICompactionScanner
+    {
+        private final String filename;
+
+        public EmptyCompactionScanner(String filename)
+        {
+            this.filename = filename;
+        }
+
+        public long getLengthInBytes()
+        {
+            return 0;
+        }
+
+        public long getCurrentPosition()
+        {
+            return 0;
+        }
+
+        public String getBackingFiles()
+        {
+            return filename;
+        }
+
+        public boolean hasNext()
+        {
+            return false;
+        }
+
+        public OnDiskAtomIterator next()
+        {
+            return null;
+        }
+
+        public void close() throws IOException { }
+
+        public void remove() { }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e306a87b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
index a8b6d64..c0d7479 100644
--- a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
@@ -40,6 +40,7 @@ import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.columniterator.IdentityQueryFilter;
 import org.apache.cassandra.db.compaction.CompactionManager;
+import org.apache.cassandra.db.compaction.ICompactionScanner;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.LocalPartitioner;
 import org.apache.cassandra.dht.LocalToken;
@@ -56,6 +57,7 @@ import org.apache.cassandra.thrift.IndexOperator;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.CLibrary;
 import org.apache.cassandra.utils.Pair;
+import static org.junit.Assert.assertTrue;
 
 @RunWith(OrderedJUnit4ClassRunner.class)
 public class SSTableReaderTest extends SchemaLoader
@@ -315,6 +317,29 @@ public class SSTableReaderTest extends SchemaLoader
         assert reopened.first.token instanceof LocalToken;
     }
 
+    /** see CASSANDRA-5407 */
+    @Test
+    public void testGetScannerForNoIntersectingRanges()
+    {
+        Table table = Table.open("Keyspace1");
+        ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+        ByteBuffer key = ByteBufferUtil.bytes(String.valueOf("k1"));
+        RowMutation rm = new RowMutation("Keyspace1", key);
+        rm.add("Standard1", ByteBufferUtil.bytes("xyz"), ByteBufferUtil.bytes("abc"), 0);
+        rm.apply();
+        store.forceBlockingFlush();
+        boolean foundScanner = false;
+        for (SSTableReader s : store.getSSTables())
+        {
+            ICompactionScanner scanner = s.getScanner(new Range<Token>(t(0),
+                                                                       t(1),
+                                                                       s.partitioner));
+            scanner.next(); // throws exception pre 5407
+            foundScanner = true;
+        }
+        assertTrue(foundScanner);
+    }
+
     private void assertIndexQueryWorks(ColumnFamilyStore indexedCFS) throws IOException
     {
         assert "Indexed1".equals(indexedCFS.name);


Mime
View raw message