combine next / getData overloads. patch by jbellis; reviewed by Jun Rau. see #52

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@762382 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2009-04-06 15:10:34 +00:00
parent 1068ee7b0c
commit e6b830c3be
3 changed files with 13 additions and 93 deletions

View File

@ -102,19 +102,6 @@ public interface IFileReader
*/
public long next(String key, DataOutputBuffer bufOut, 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 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
@ -125,26 +112,14 @@ public interface IFileReader
* @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.

View File

@ -36,6 +36,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;
/**
* This class is built on top of the SequenceFile. It stores
@ -867,7 +868,7 @@ public class SSTable
* 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 @@ public class SSTable
* 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 @@ public class SSTable
/*
* 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 )
@ -984,32 +973,6 @@ public class SSTable
return bufIn;
}
/*
* 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.

View File

@ -848,19 +848,6 @@ public class SequenceFile
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 @@ public class SequenceFile
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
{