mirror of https://github.com/apache/cassandra
refactor read-only constructor to SSTable.open
patch by jbellis; reviewed by Eric Evans for CASSANDRA-224 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@787759 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d48d8fcbf7
commit
a2f9b40183
|
|
@ -577,7 +577,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
|
||||
private ColumnFamily fetchColumnFamily(String key, String cf, IFilter filter, String ssTableFile) throws IOException
|
||||
{
|
||||
SSTable ssTable = new SSTable(ssTableFile, StorageService.getPartitioner());
|
||||
SSTable ssTable = SSTable.open(ssTableFile, StorageService.getPartitioner());
|
||||
DataInputBuffer bufIn;
|
||||
bufIn = filter.next(key, cf, ssTable);
|
||||
if (bufIn.getLength() == 0)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class SSTableColumnIterator extends AbstractIterator<IColumn> implements ColumnI
|
|||
throws IOException
|
||||
{
|
||||
this.isAscending = isAscending;
|
||||
SSTable ssTable = new SSTable(filename, StorageService.getPartitioner());
|
||||
SSTable ssTable = SSTable.open(filename, StorageService.getPartitioner());
|
||||
reader = ssTable.getColumnGroupReader(key, cfName, startColumn, isAscending);
|
||||
this.startColumn = startColumn;
|
||||
curColumnIndex = isAscending ? 0 : -1;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ public class SSTable
|
|||
{
|
||||
try
|
||||
{
|
||||
new SSTable(filename, StorageService.getPartitioner());
|
||||
SSTable.open(filename, StorageService.getPartitioner());
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
|
|
@ -205,30 +205,26 @@ public class SSTable
|
|||
private String lastWrittenKey_;
|
||||
private IPartitioner partitioner_;
|
||||
|
||||
/**
|
||||
* This ctor basically gets passed in the full path name
|
||||
* of the data file associated with this SSTable. Use this
|
||||
* ctor to read the data in this file.
|
||||
*/
|
||||
public SSTable(String dataFileName, IPartitioner partitioner) throws IOException
|
||||
public static synchronized SSTable open(String dataFileName, IPartitioner partitioner) throws IOException
|
||||
{
|
||||
dataFile_ = dataFileName;
|
||||
partitioner_ = partitioner;
|
||||
/*
|
||||
* this is to prevent multiple threads from
|
||||
* loading the same index files multiple times
|
||||
* into memory.
|
||||
*/
|
||||
synchronized (indexLoadLock_)
|
||||
SSTable sstable = new SSTable(dataFileName, partitioner);
|
||||
sstable.dataWriter_.close(); // todo this is dumb
|
||||
if (indexMetadataMap_.get(dataFileName) == null)
|
||||
{
|
||||
if (indexMetadataMap_.get(dataFile_) == null)
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
loadIndexFile();
|
||||
loadBloomFilter();
|
||||
logger_.debug("INDEX LOAD TIME: " + (System.currentTimeMillis() - start) + " ms.");
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
sstable.loadIndexFile();
|
||||
sstable.loadBloomFilter();
|
||||
logger_.debug("INDEX LOAD TIME for " + dataFileName + ": " + (System.currentTimeMillis() - start) + " ms.");
|
||||
}
|
||||
return sstable;
|
||||
}
|
||||
|
||||
public SSTable(String filename, IPartitioner partitioner) throws IOException
|
||||
{
|
||||
dataFile_ = filename;
|
||||
partitioner_ = partitioner;
|
||||
dataWriter_ = SequenceFile.bufferedWriter(dataFile_, 4 * 1024 * 1024);
|
||||
indexRAF_ = new BufferedRandomAccessFile(indexFilename(), "rw", 1024 * 1024);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -237,10 +233,7 @@ public class SSTable
|
|||
*/
|
||||
public SSTable(String directory, String filename, IPartitioner partitioner) throws IOException
|
||||
{
|
||||
dataFile_ = directory + System.getProperty("file.separator") + filename + "-Data.db";
|
||||
partitioner_ = partitioner;
|
||||
dataWriter_ = SequenceFile.bufferedWriter(dataFile_, 4 * 1024 * 1024);
|
||||
indexRAF_ = new BufferedRandomAccessFile(indexFilename(), "rw", 1024 * 1024);
|
||||
this(directory + System.getProperty("file.separator") + filename + "-Data.db", partitioner);
|
||||
}
|
||||
|
||||
static String parseTableName(String filename)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class SSTableTest extends CleanupHelper
|
|||
|
||||
private void verifySingle(File f, byte[] bytes, String key) throws IOException
|
||||
{
|
||||
SSTable ssTable = new SSTable(f.getPath() + "-Data.db", new OrderPreservingPartitioner());
|
||||
SSTable ssTable = SSTable.open(f.getPath() + "-Data.db", new OrderPreservingPartitioner());
|
||||
FileStruct fs = new FileStruct(SequenceFile.bufferedReader(ssTable.dataFile_, 128 * 1024), new OrderPreservingPartitioner());
|
||||
fs.seekTo(key);
|
||||
int size = fs.getBufIn().readInt();
|
||||
|
|
@ -95,7 +95,7 @@ public class SSTableTest extends CleanupHelper
|
|||
{
|
||||
List<String> keys = new ArrayList(map.keySet());
|
||||
Collections.shuffle(keys);
|
||||
SSTable ssTable = new SSTable(f.getPath() + "-Data.db", new OrderPreservingPartitioner());
|
||||
SSTable ssTable = SSTable.open(f.getPath() + "-Data.db", new OrderPreservingPartitioner());
|
||||
FileStruct fs = new FileStruct(SequenceFile.bufferedReader(ssTable.dataFile_, 128 * 1024), new OrderPreservingPartitioner());
|
||||
for (String key : keys)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue