cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r981542 - in /cassandra/trunk: src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java test/unit/org/apache/cassandra/io/StreamingTest.java
Date Mon, 02 Aug 2010 15:05:29 GMT
Author: jbellis
Date: Mon Aug  2 15:05:28 2010
New Revision: 981542

URL: http://svn.apache.org/viewvc?rev=981542&view=rev
Log:
add SimpleColumnReader to optimize start-from-beginning-of-row slices
patch by jbellis; reviewed by gdusbabek for CASSANDRA-1338


Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
    cassandra/trunk/test/unit/org/apache/cassandra/io/StreamingTest.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java?rev=981542&r1=981541&r2=981542&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java Mon
Aug  2 15:05:28 2010
@@ -97,7 +97,7 @@ class SSTableSliceIterator implements IC
             }
         }
 
-        reader = new ColumnGroupReader(ssTable, file);
+        reader = startColumn.length == 0 && !reversed ? new SimpleColumnReader(ssTable,
file) : new ColumnGroupReader(ssTable, file);
     }
     
     public DecoratedKey getKey()
@@ -131,6 +131,70 @@ class SSTableSliceIterator implements IC
             reader.close();
     }
 
+    private class SimpleColumnReader extends AbstractIterator<IColumn> implements IColumnIterator
+    {
+        private final FileDataInput file;
+        private final ColumnFamily emptyColumnFamily;
+        private final int columns;
+        private int i;
+        private FileMark mark;
+
+        public SimpleColumnReader(SSTableReader ssTable, FileDataInput input)
+        {
+            this.file = input;
+            try
+            {
+                IndexHelper.skipBloomFilter(file);
+                IndexHelper.skipIndex(file);
+
+                emptyColumnFamily = ColumnFamily.serializer().deserializeFromSSTableNoColumns(ssTable.makeColumnFamily(),
file);
+                columns = file.readInt();
+                mark = file.mark();
+            }
+            catch (IOException e)
+            {
+                throw new IOError(e);
+            }
+        }
+
+        protected IColumn computeNext()
+        {
+            if (i++ >= columns)
+                return endOfData();
+
+            IColumn column;
+            try
+            {
+                file.reset(mark);
+                column = emptyColumnFamily.getColumnSerializer().deserialize(file);
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException("error reading " + i + " of " + columns, e);
+            }
+            if (finishColumn.length > 0 && comparator.compare(column.name(), finishColumn)
> 0)
+                return endOfData();
+
+            mark = file.mark();
+            return column;
+        }
+
+        public ColumnFamily getColumnFamily() throws IOException
+        {
+            return emptyColumnFamily;
+        }
+
+        public void close() throws IOException
+        {
+            file.close();
+        }
+
+        public DecoratedKey getKey()
+        {
+            throw new UnsupportedOperationException();
+        }
+    }
+
     /**
      *  This is a reader that finds the block for a starting column and returns
      *  blocks before/after it for each next call. This function assumes that

Modified: cassandra/trunk/test/unit/org/apache/cassandra/io/StreamingTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/io/StreamingTest.java?rev=981542&r1=981541&r2=981542&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/io/StreamingTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/io/StreamingTest.java Mon Aug  2 15:05:28
2010
@@ -70,6 +70,9 @@ public class StreamingTest extends Clean
         assertEquals(2, rows.size());
         assert Arrays.equals(rows.get(0).key.key, "key".getBytes());
         assert Arrays.equals(rows.get(1).key.key, "key3".getBytes());
+        assert rows.get(0).cf.getColumnsMap().size() == 1;
+        assert rows.get(1).cf.getColumnsMap().size() == 1;
+        assert rows.get(1).cf.getColumn("key3".getBytes()) != null;
 
         // and that the index and filter were properly recovered
         assert null != cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key"),
new QueryPath("Standard1")));



Mime
View raw message