You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2009/08/02 00:30:55 UTC

svn commit: r799946 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: db/filter/SSTableNamesIterator.java io/SequenceFile.java

Author: jbellis
Date: Sat Aug  1 22:30:55 2009
New Revision: 799946

URL: http://svn.apache.org/viewvc?rev=799946&view=rev
Log:
r/m code in SF.next handling being called multiple times, since it can only be called once.
patch by jbellis; reviewed by Stu Hood for CASSANDRA-330

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java?rev=799946&r1=799945&r2=799946&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java Sat Aug  1 22:30:55 2009
@@ -14,7 +14,7 @@
     private Iterator<IColumn> iter;
     public final SortedSet<byte[]> columns;
 
-    // TODO make this actually iterate so we don't have to read + deserialize + filter data that we don't need due to merging other sstables
+    // TODO make this actually iterate so we don't have to read + deserialize + filter data that we don't need, only to skip it later in computeNext
     public SSTableNamesIterator(String filename, String key, String cfName, SortedSet<byte[]> columns) throws IOException
     {
         this.columns = columns;
@@ -29,17 +29,15 @@
             dataReader = SequenceFile.bufferedReader(ssTable.getFilename(), 64 * 1024);
             String decoratedKey = ssTable.getPartitioner().decorateKey(key);
             long position = ssTable.getPosition(decoratedKey);
-
-            long bytesRead = dataReader.next(decoratedKey, bufOut, cfName, columns, position);
-            if (bytesRead != -1L)
+            if (position >= 0)
             {
-                if (bufOut.getLength() > 0)
-                {
-                    bufIn.reset(bufOut.getData(), bufOut.getLength());
-                    /* read the key even though we do not use it */
-                    bufIn.readUTF();
-                    bufIn.readInt();
-                }
+                long bytesRead = dataReader.next(decoratedKey, bufOut, cfName, columns, position);
+                assert bytesRead > 0;
+                assert bufOut.getLength() > 0;
+                bufIn.reset(bufOut.getData(), bufOut.getLength());
+                /* read the key even though we do not use it */
+                bufIn.readUTF();
+                bufIn.readInt();
             }
         }
         finally
@@ -50,10 +48,9 @@
             }
         }
 
-        DataInputBuffer buffer = bufIn;
-        if (buffer.getLength() > 0)
+        if (bufIn.getLength() > 0)
         {
-            cf = ColumnFamily.serializer().deserialize(buffer);
+            cf = ColumnFamily.serializer().deserialize(bufIn);
             iter = cf.getSortedColumns().iterator();
         }
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java?rev=799946&r1=799945&r2=799946&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java Sat Aug  1 22:30:55 2009
@@ -287,35 +287,11 @@
             /* note the position where the key starts */
             long startPosition = file_.getFilePointer();
             String keyInDisk = file_.readUTF();
-            if (keyInDisk != null)
-            {
-                /*
-                 * If key on disk is greater than requested key
-                 * we can bail out since we exploit the property
-                 * of the SSTable format.
-                */
-                if (keyInDisk.compareTo(key) > 0)
-                    return bytesRead;
-
-                /*
-                 * If we found the key then we populate the buffer that
-                 * is passed in. If not then we skip over this key and
-                 * position ourselves to read the next one.
-                */
-                if (keyInDisk.equals(key))
-                {
-                    readColumns(key, bufOut, columnFamilyName, columnNames);
-                }
-                else
-                {
-                    /* skip over data portion */
-                    int dataSize = file_.readInt();
-                    file_.seek(dataSize + file_.getFilePointer());
-                }
+            assert keyInDisk.equals(key);
+            readColumns(key, bufOut, columnFamilyName, columnNames);
 
-                long endPosition = file_.getFilePointer();
-                bytesRead = endPosition - startPosition;
-            }
+            long endPosition = file_.getFilePointer();
+            bytesRead = endPosition - startPosition;
 
             return bytesRead;
         }