cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r799950 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/io/ test/unit/org/apache/cassandra/io/
Date Sat, 01 Aug 2009 22:31:24 GMT
Author: jbellis
Date: Sat Aug  1 22:31:24 2009
New Revision: 799950

URL: http://svn.apache.org/viewvc?rev=799950&view=rev
Log:
remove AbstractWriter. all it was providing was append methods, which are inlined into SSTableWriter
now; the rest was all wrappers. also, rename some variables in SST/SSTW.
patch by jbellis; reviewed by Stu Hood for CASSANDRA-330

Removed:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/AbstractWriter.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableWriter.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/io/SSTableTest.java

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=799950&r1=799949&r2=799950&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 Sat Aug  1 22:31:24
2009
@@ -22,7 +22,7 @@
  */
 public abstract class SSTable
 {
-    protected String dataFile;
+    protected String path;
     protected IPartitioner partitioner;
     protected BloomFilter bf;
     protected List<KeyPosition> indexPositions;
@@ -34,7 +34,7 @@
     public SSTable(String filename, IPartitioner partitioner)
     {
         assert filename.endsWith("-Data.db");
-        this.dataFile = filename;
+        this.path = filename;
         this.partitioner = partitioner;
     }
 
@@ -47,7 +47,7 @@
 
     protected String indexFilename()
     {
-        return indexFilename(dataFile);
+        return indexFilename(path);
     }
 
     protected static String filterFilename(String dataFile)
@@ -59,12 +59,12 @@
 
     protected String filterFilename()
     {
-        return filterFilename(dataFile);
+        return filterFilename(path);
     }
 
     public String getFilename()
     {
-        return dataFile;
+        return path;
     }
 
     public static String parseTableName(String filename)

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java?rev=799950&r1=799949&r2=799950&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java Sat Aug
 1 22:31:24 2009
@@ -215,7 +215,7 @@
         }
 
         // TODO mmap the index file?
-        BufferedRandomAccessFile input = new BufferedRandomAccessFile(indexFilename(dataFile),
"r");
+        BufferedRandomAccessFile input = new BufferedRandomAccessFile(indexFilename(path),
"r");
         input.seek(start);
         int i = 0;
         try
@@ -258,7 +258,7 @@
         {
             return 0;
         }
-        BufferedRandomAccessFile input = new BufferedRandomAccessFile(indexFilename(dataFile),
"r");
+        BufferedRandomAccessFile input = new BufferedRandomAccessFile(indexFilename(path),
"r");
         input.seek(start);
         try
         {
@@ -287,10 +287,10 @@
 
     public void delete() throws IOException
     {
-        FileUtils.deleteWithConfirm(new File(dataFile));
-        FileUtils.deleteWithConfirm(new File(indexFilename(dataFile)));
-        FileUtils.deleteWithConfirm(new File(filterFilename(dataFile)));
-        openedFiles.remove(dataFile);
+        FileUtils.deleteWithConfirm(new File(path));
+        FileUtils.deleteWithConfirm(new File(indexFilename(path)));
+        FileUtils.deleteWithConfirm(new File(filterFilename(path)));
+        openedFiles.remove(path);
     }
 
     /** obviously only for testing */
@@ -305,7 +305,7 @@
         openedFiles.clear();
         for (SSTableReader sstable : sstables)
         {
-            SSTableReader.open(sstable.dataFile, sstable.partitioner, 0.01);
+            SSTableReader.open(sstable.path, sstable.partitioner, 0.01);
         }
     }
 
@@ -321,7 +321,7 @@
 
     public String getTableName()
     {
-        return parseTableName(dataFile);
+        return parseTableName(path);
     }
 
     public static void deleteAll() throws IOException

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableWriter.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableWriter.java?rev=799950&r1=799949&r2=799950&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableWriter.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableWriter.java Sat Aug
 1 22:31:24 2009
@@ -18,16 +18,16 @@
     private static Logger logger = Logger.getLogger(SSTableWriter.class);
 
     private long keysWritten;
-    private AbstractWriter dataWriter;
-    private BufferedRandomAccessFile indexRAF;
+    private BufferedRandomAccessFile dataFile;
+    private BufferedRandomAccessFile indexFile;
     private String lastWrittenKey;
     private BloomFilter bf;
 
     public SSTableWriter(String filename, int keyCount, IPartitioner partitioner) throws
IOException
     {
         super(filename, partitioner);
-        dataWriter = new AbstractWriter.BufferWriter(dataFile, 4 * 1024 * 1024);
-        indexRAF = new BufferedRandomAccessFile(indexFilename(), "rw", 1024 * 1024);
+        dataFile = new BufferedRandomAccessFile(path, "rw", 4 * 1024 * 1024);
+        indexFile = new BufferedRandomAccessFile(indexFilename(), "rw", 1024 * 1024);
         bf = new BloomFilter(keyCount, 15);
     }
 
@@ -42,19 +42,19 @@
         {
             logger.info("Last written key : " + lastWrittenKey);
             logger.info("Current key : " + decoratedKey);
-            logger.info("Writing into file " + dataFile);
+            logger.info("Writing into file " + path);
             throw new IOException("Keys must be written in ascending order.");
         }
-        return (lastWrittenKey == null) ? 0 : dataWriter.getCurrentPosition();
+        return (lastWrittenKey == null) ? 0 : dataFile.getFilePointer();
     }
 
     private void afterAppend(String decoratedKey, long position) throws IOException
     {
         bf.add(decoratedKey);
         lastWrittenKey = decoratedKey;
-        long indexPosition = indexRAF.getFilePointer();
-        indexRAF.writeUTF(decoratedKey);
-        indexRAF.writeLong(position);
+        long indexPosition = indexFile.getFilePointer();
+        indexFile.writeUTF(decoratedKey);
+        indexFile.writeLong(position);
         if (logger.isTraceEnabled())
             logger.trace("wrote " + decoratedKey + " at " + position);
 
@@ -73,14 +73,19 @@
     public void append(String decoratedKey, DataOutputBuffer buffer) throws IOException
     {
         long currentPosition = beforeAppend(decoratedKey);
-        dataWriter.append(decoratedKey, buffer);
+        dataFile.writeUTF(decoratedKey);
+        int length = buffer.getLength();
+        dataFile.writeInt(length);
+        dataFile.write(buffer.getData(), 0, length);
         afterAppend(decoratedKey, currentPosition);
     }
 
     public void append(String decoratedKey, byte[] value) throws IOException
     {
         long currentPosition = beforeAppend(decoratedKey);
-        dataWriter.append(decoratedKey, value);
+        dataFile.writeUTF(decoratedKey);
+        dataFile.writeInt(value.length);
+        dataFile.write(value);
         afterAppend(decoratedKey, currentPosition);
     }
 
@@ -105,20 +110,20 @@
         stream.close();
 
         // index
-        indexRAF.getChannel().force(true);
-        indexRAF.close();
+        indexFile.getChannel().force(true);
+        indexFile.close();
 
         // main data
-        dataWriter.close(); // calls force
+        dataFile.close(); // calls force
 
         rename(indexFilename());
         rename(filterFilename());
-        dataFile = rename(dataFile); // important to do this last since index & filter
file names are derived from it
+        path = rename(path); // important to do this last since index & filter file names
are derived from it
 
         ConcurrentLinkedHashMap<String,Long> keyCache = cacheFraction > 0
                                                         ? SSTableReader.createKeyCache((int)
(cacheFraction * keysWritten))
                                                         : null;
-        return new SSTableReader(dataFile, partitioner, indexPositions, bf, keyCache);
+        return new SSTableReader(path, partitioner, indexPositions, bf, keyCache);
     }
 
 }

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=799950&r1=799949&r2=799950&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 Sat Aug 
1 22:31:24 2009
@@ -25,7 +25,6 @@
 import org.junit.Test;
 
 import org.apache.cassandra.CleanupHelper;
-import org.apache.cassandra.io.FileStruct;
 import org.apache.cassandra.dht.OrderPreservingPartitioner;
 
 public class SSTableTest extends CleanupHelper
@@ -57,7 +56,7 @@
 
     private void verifySingle(SSTableReader sstable, byte[] bytes, String key) throws IOException
     {
-        BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.dataFile, "r");
+        BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.path, "r");
         file.seek(sstable.getPosition(key));
         assert key.equals(file.readUTF());
         int size = file.readInt();
@@ -94,7 +93,7 @@
     {
         List<String> keys = new ArrayList<String>(map.keySet());
         Collections.shuffle(keys);
-        BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.dataFile, "r");
+        BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.path, "r");
         for (String key : keys)
         {
             file.seek(sstable.getPosition(key));



Mime
View raw message