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/04/06 17:10:34 UTC

svn commit: r762382 - in /incubator/cassandra/trunk/src/org/apache/cassandra/io: IFileReader.java SSTable.java SequenceFile.java

Author: jbellis
Date: Mon Apr  6 15:10:34 2009
New Revision: 762382

URL: http://svn.apache.org/viewvc?rev=762382&view=rev
Log:
combine next / getData overloads.  patch by jbellis; reviewed by Jun Rau.  see #52

Modified:
    incubator/cassandra/trunk/src/org/apache/cassandra/io/IFileReader.java
    incubator/cassandra/trunk/src/org/apache/cassandra/io/SSTable.java
    incubator/cassandra/trunk/src/org/apache/cassandra/io/SequenceFile.java

Modified: incubator/cassandra/trunk/src/org/apache/cassandra/io/IFileReader.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/io/IFileReader.java?rev=762382&r1=762381&r2=762382&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/io/IFileReader.java (original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/io/IFileReader.java Mon Apr  6 15:10:34 2009
@@ -104,19 +104,6 @@
 
     /**
      * This method dumps the next key/value into the DataOuputStream
-     * passed in.
-     *
-     * @param key key we are interested in.
-     * @param bufOut DataOutputStream that needs to be filled.
-     * @param column name of the column in our format.
-     * @param section region of the file that needs to be read
-     * @throws IOException
-     * @return number of bytes that were read.
-    */
-    public long next(String key, DataOutputBuffer bufOut, String column, Coordinate section) throws IOException;
-
-    /**
-     * This method dumps the next key/value into the DataOuputStream
      * passed in. Always use this method to query for application
      * specific data as it will have indexes.
      *
@@ -125,26 +112,14 @@
      * @param columnFamilyName The name of the column family only without the ":"
      * @param columnNames - The list of columns in the cfName column family
      * 					     that we want to return
+     * OR
+     * @param timeRange - time range we are interested in
      * @param section region of the file that needs to be read
      * @throws IOException
      * @return number of bytes read.
      *
     */
-    public long next(String key, DataOutputBuffer bufOut, String columnFamilyName, List<String> columnNames, Coordinate section) throws IOException;
-    
-    /**
-     * This method dumps the next key/value into the DataOuputStream
-     * passed in.
-     *
-     * @param key key we are interested in.
-     * @param bufOut DataOutputStream that needs to be filled.
-     * @param column name of the column in our format.
-     * @param timeRange time range we are interested in.
-     * @param section region of the file that needs to be read
-     * @throws IOException
-     * @return number of bytes that were read.
-    */
-    public long next(String key, DataOutputBuffer bufOut, String column, IndexHelper.TimeRange timeRange, Coordinate section) throws IOException;
+    public long next(String key, DataOutputBuffer bufOut, String columnFamilyName, List<String> columnNames, IndexHelper.TimeRange timeRange, Coordinate section) throws IOException;
 
     /**
      * Close the file after reading.

Modified: incubator/cassandra/trunk/src/org/apache/cassandra/io/SSTable.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/io/SSTable.java?rev=762382&r1=762381&r2=762382&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/io/SSTable.java (original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/io/SSTable.java Mon Apr  6 15:10:34 2009
@@ -36,6 +36,7 @@
 import org.apache.cassandra.utils.LogUtil;
 import org.apache.log4j.Logger;
 import org.apache.cassandra.utils.*;
+import org.apache.cassandra.db.RowMutation;
 
 /**
  * This class is built on top of the SequenceFile. It stores
@@ -867,7 +868,7 @@
              * we have the position we have to read from in order to get the
              * column family, get the column family and column(s) needed.
             */          
-            bufIn = getData(dataReader, key, cf, cNames, fileCoordinate);
+            bufIn = getData(dataReader, key, cf, cNames, null, fileCoordinate);
         }
         finally
         {
@@ -920,7 +921,7 @@
              * we have the position we have to read from in order to get the
              * column family, get the column family and column(s) needed.
             */  
-            bufIn = getData(dataReader, key, cfName, timeRange, fileCoordinate);
+            bufIn = getData(dataReader, key, cfName, null, timeRange, fileCoordinate);
         }
         finally
         {
@@ -945,32 +946,20 @@
     /*
      * Get the data for the key from the position passed in. 
     */
-    private DataInputBuffer getData(IFileReader dataReader, String key, String column, Coordinate section) throws IOException
+    private DataInputBuffer getData(IFileReader dataReader, String key, String columnFamilyColumn, Coordinate section) throws IOException
     {
-        DataOutputBuffer bufOut = new DataOutputBuffer();
-        DataInputBuffer bufIn = new DataInputBuffer();
-        
-        long bytesRead = dataReader.next(key, bufOut, column, section);
-        if ( bytesRead != -1L )
-        {
-            if ( bufOut.getLength() > 0 )
-            {                              
-                bufIn.reset(bufOut.getData(), bufOut.getLength());            
-                /* read the key even though we do not use it */
-                bufIn.readUTF();
-                bufIn.readInt();            
-            }
-        }
-        
-        return bufIn;
+        String[] values = RowMutation.getColumnAndColumnFamily(columnFamilyColumn);
+        String columnFamilyName = values[0];
+        List<String> columnNames = (values.length == 1) ? null : Arrays.asList(values[1]);
+        return getData(dataReader, key, columnFamilyName, columnNames, null, section);
     }
     
-    private DataInputBuffer getData(IFileReader dataReader, String key, String cf, List<String> columns, Coordinate section) throws IOException
+    private DataInputBuffer getData(IFileReader dataReader, String key, String cf, List<String> columns, IndexHelper.TimeRange timeRange, Coordinate section) throws IOException
     {
         DataOutputBuffer bufOut = new DataOutputBuffer();
         DataInputBuffer bufIn = new DataInputBuffer();
                   
-        long bytesRead = dataReader.next(key, bufOut, cf, columns, section);
+        long bytesRead = dataReader.next(key, bufOut, cf, columns, timeRange, section);
         if ( bytesRead != -1L )
         {
             if ( bufOut.getLength() > 0 )
@@ -985,32 +974,6 @@
     }
     
     /*
-     * Get the data for the key from the position passed in. 
-    */
-    private DataInputBuffer getData(IFileReader dataReader, String key, String cfName, IndexHelper.TimeRange timeRange, Coordinate section) throws IOException
-    {
-        DataOutputBuffer bufOut = new DataOutputBuffer();
-        DataInputBuffer bufIn = new DataInputBuffer();
-                
-        try
-        {
-            dataReader.next(key, bufOut, cfName, timeRange, section);
-            if ( bufOut.getLength() > 0 )
-            {                              
-                bufIn.reset(bufOut.getData(), bufOut.getLength());            
-                /* read the key even though we do not use it */
-                bufIn.readUTF();
-                bufIn.readInt();            
-            }
-        }
-        catch ( IOException ex )
-        {
-            logger_.warn(LogUtil.throwableToString(ex));
-        }
-        return bufIn;
-    }
-    
-    /*
      * Given a key we are interested in this method gets the
      * closest index before the key on disk.
      *

Modified: incubator/cassandra/trunk/src/org/apache/cassandra/io/SequenceFile.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/io/SequenceFile.java?rev=762382&r1=762381&r2=762382&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/io/SequenceFile.java (original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/io/SequenceFile.java Mon Apr  6 15:10:34 2009
@@ -848,19 +848,6 @@
             return keyInDisk;
         }
 
-        public long next(String key, DataOutputBuffer bufOut, String cf, Coordinate section) throws IOException
-        {
-            String[] values = RowMutation.getColumnAndColumnFamily(cf);
-            String columnFamilyName = values[0];
-            List<String> columnNames = (values.length == 1) ? null : Arrays.asList(values[1]);
-            return next(key, bufOut, columnFamilyName, columnNames, section);
-        }
-
-        public long next(String key, DataOutputBuffer bufOut, String cf, IndexHelper.TimeRange timeRange, Coordinate section) throws IOException
-        {
-            return next(key, bufOut, cf, null, timeRange, section);
-        }
-
         /**
          * This method dumps the next key/value into the DataOuputStream
          * passed in. Always use this method to query for application
@@ -983,11 +970,6 @@
             bufOut.write(file_, dataSize);
         }
 
-        public long next(String key, DataOutputBuffer bufOut, String cf, List<String> columnNames, Coordinate section) throws IOException
-        {
-            return next(key, bufOut, cf, columnNames, null, section);
-        }
-
         private void readColumns(String key, DataOutputBuffer bufOut, String columnFamilyName, List<String> cNames)
                 throws IOException
         {