Author: jbellis
Date: Mon Apr 6 15:10:38 2009
New Revision: 762383
URL: http://svn.apache.org/viewvc?rev=762383&view=rev
Log:
combine overloads of SSTable.next; inline getData. patch by jbellis; reviewed
by Jun Rau. see #52
Modified:
incubator/cassandra/trunk/src/org/apache/cassandra/db/NamesFilter.java
incubator/cassandra/trunk/src/org/apache/cassandra/db/TimeFilter.java
incubator/cassandra/trunk/src/org/apache/cassandra/io/SSTable.java
Modified: incubator/cassandra/trunk/src/org/apache/cassandra/db/NamesFilter.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/db/NamesFilter.java?rev=762383&r1=762382&r2=762383&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/db/NamesFilter.java
(original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/db/NamesFilter.java Mon
Apr 6 15:10:38 2009
@@ -116,7 +116,7 @@
public DataInputBuffer next(String key, String cf, SSTable ssTable) throws
IOException
{
- return ssTable.next(key, cf, names_);
+ return ssTable.next(key, cf, names_, null);
}
}
Modified: incubator/cassandra/trunk/src/org/apache/cassandra/db/TimeFilter.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/db/TimeFilter.java?rev=762383&r1=762382&r2=762383&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/db/TimeFilter.java
(original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/db/TimeFilter.java Mon
Apr 6 15:10:38 2009
@@ -146,6 +146,6 @@
public DataInputBuffer next(String key, String cfName, SSTable ssTable)
throws IOException
{
- return ssTable.next( key, cfName, new IndexHelper.TimeRange(
timeLimit_, Long.MAX_VALUE ) );
+ return ssTable.next( key, cfName, null, new IndexHelper.TimeRange(
timeLimit_, Long.MAX_VALUE ) );
}
}
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=762383&r1=762382&r2=762383&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:38 2009
@@ -20,11 +20,7 @@
import java.io.*;
import java.math.BigInteger;
-import java.nio.channels.FileChannel;
import java.util.*;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.service.PartitionerType;
@@ -35,7 +31,7 @@
import org.apache.cassandra.utils.FileUtils;
import org.apache.cassandra.utils.LogUtil;
import org.apache.log4j.Logger;
-import org.apache.cassandra.utils.*;
+
import org.apache.cassandra.db.RowMutation;
/**
@@ -853,53 +849,37 @@
}
return internalKey;
}
-
- public DataInputBuffer next(String key, String cf, List<String> cNames)
throws IOException
+
+ public DataInputBuffer next(String key, String cf, List<String> cNames,
IndexHelper.TimeRange timeRange) throws IOException
{
- DataInputBuffer bufIn = null;
+ DataInputBuffer bufIn = new DataInputBuffer();
IFileReader dataReader = null;
try
{
dataReader = SequenceFile.reader(dataFile_);
- /* Morph key into actual key based on the partition type. */
+ /* Morph key into actual key based on the partition type. */
key = morphKey(key);
- Coordinate fileCoordinate = getCoordinates(key, dataReader);
+ Coordinate fileCoordinate = getCoordinates(key, dataReader);
/*
* 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, null, fileCoordinate);
- }
- finally
- {
- if ( dataReader != null )
+ */
+ DataOutputBuffer bufOut = new DataOutputBuffer();
+ long bytesRead = dataReader.next(key, bufOut, cf, cNames,
timeRange, fileCoordinate);
+ if (bytesRead != -1L)
{
- dataReader.close();
+ 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;
- }
-
- public DataInputBuffer next(String key, String columnName) throws
IOException
- {
- DataInputBuffer bufIn = null;
- IFileReader dataReader = null;
- try
- {
- dataReader = SequenceFile.reader(dataFile_);
- // dataReader = SequenceFile.chksumReader(dataFile_, 4*1024*1024);
- /* Morph key into actual key based on the partition type. */
- key = morphKey(key);
- Coordinate fileCoordinate = getCoordinates(key, dataReader);
- /*
- * 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, columnName, fileCoordinate);
- }
finally
{
- if ( dataReader != null )
+ if (dataReader != null)
{
dataReader.close();
}
@@ -907,30 +887,12 @@
return bufIn;
}
- public DataInputBuffer next(String key, String cfName,
IndexHelper.TimeRange timeRange) throws IOException
+ public DataInputBuffer next(String key, String columnFamilyColumn) throws
IOException
{
- DataInputBuffer bufIn = null;
- IFileReader dataReader = null;
- try
- {
- dataReader = SequenceFile.reader(dataFile_);
- /* Morph key into actual key based on the partition type. */
- key = morphKey(key);
- Coordinate fileCoordinate = getCoordinates(key, dataReader);
- /*
- * 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, null, timeRange,
fileCoordinate);
- }
- finally
- {
- if ( dataReader != null )
- {
- dataReader.close();
- }
- }
- return bufIn;
+ String[] values =
RowMutation.getColumnAndColumnFamily(columnFamilyColumn);
+ String columnFamilyName = values[0];
+ List<String> columnNames = (values.length == 1) ? null :
Arrays.asList(values[1]);
+ return next(key, columnFamilyName, columnNames, null);
}
long getSeekPosition(String key, long start)
@@ -942,37 +904,7 @@
}
return start;
}
-
- /*
- * Get the data for the key from the position passed in.
- */
- private DataInputBuffer getData(IFileReader dataReader, String key, String
columnFamilyColumn, Coordinate section) throws IOException
- {
- 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, IndexHelper.TimeRange timeRange, Coordinate section)
throws IOException
- {
- DataOutputBuffer bufOut = new DataOutputBuffer();
- DataInputBuffer bufIn = new DataInputBuffer();
-
- long bytesRead = dataReader.next(key, bufOut, cf, columns, timeRange,
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;
- }
-
+
/*
* Given a key we are interested in this method gets the
* closest index before the key on disk.