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/06/23 19:47:53 UTC
svn commit: r787759 - in /incubator/cassandra/trunk:
src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/io/
test/unit/org/apache/cassandra/io/
Author: jbellis
Date: Tue Jun 23 17:47:53 2009
New Revision: 787759
URL: http://svn.apache.org/viewvc?rev=787759&view=rev
Log:
refactor read-only constructor to SSTable.open
patch by jbellis; reviewed by Eric Evans for CASSANDRA-224
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIterator.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java
incubator/cassandra/trunk/test/unit/org/apache/cassandra/io/SSTableTest.java
Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=787759&r1=787758&r2=787759&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Tue Jun 23 17:47:53 2009
@@ -577,7 +577,7 @@
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)
Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIterator.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIterator.java?rev=787759&r1=787758&r2=787759&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIterator.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIterator.java Tue Jun 23 17:47:53 2009
@@ -58,7 +58,7 @@
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;
Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java?rev=787759&r1=787758&r2=787759&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java Tue Jun 23 17:47:53 2009
@@ -156,7 +156,7 @@
{
try
{
- new SSTable(filename, StorageService.getPartitioner());
+ SSTable.open(filename, StorageService.getPartitioner());
}
catch (IOException ex)
{
@@ -205,30 +205,26 @@
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 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)
Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/io/SSTableTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/io/SSTableTest.java?rev=787759&r1=787758&r2=787759&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/io/SSTableTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/io/SSTableTest.java Tue Jun 23 17:47:53 2009
@@ -56,7 +56,7 @@
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 @@
{
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)
{