org.apache.cassandra.io
Class SSTable

java.lang.Object
  extended by org.apache.cassandra.io.SSTable

public class SSTable
extends java.lang.Object

This class is built on top of the SequenceFile. It stores data on disk in sorted fashion. However the sorting is upto the application. This class expects keys to be handed to it in sorted order. SSTable is broken up into blocks where each block contains 128 keys. At the end of the file the block index is written which contains the offsets to the keys in the block. SSTable also maintains an index file to which every 128th key is written with a pointer to the block index which is the block that actually contains the key. This index file is then read and maintained in memory. SSTable is append only and immutable. SSTable on disk looks as follows:

------------------------- |------------------------|<-------| | | | BLOCK-INDEX PTR | | | |------------------------|-------- |------------------------|<-------| | | | | | | BLOCK-INDEX PTR | | | |------------------------|--------- |------------------------|<--------| | | | | | | | | | BLOCK-INDEX PTR | | | |------------------------| | |------------------------|---------- |------------------------|-----------------> BLOOM-FILTER version-info <--|----------|-------------|-------> relative offset to last block index.

Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com )


Nested Class Summary
protected static class SSTable.BlockMetadata
          This class holds the position of a key in a block and the size of the data associated with this key.
static class SSTable.KeyPositionInfo
          This is a simple container for the index Key and its corresponding position in the data file.
 
Field Summary
static java.lang.String blockIndexKey_
           
static java.lang.String temporaryFile_
           
 
Constructor Summary
SSTable(java.lang.String dataFileName, IPartitioner partitioner)
          This ctor basically gets passed in the full path name of the data file associated with this SSTable.
SSTable(java.lang.String directory, java.lang.String filename, IPartitioner partitioner)
          This ctor is used for writing data into the SSTable.
 
Method Summary
 void append(java.lang.String decoratedKey, byte[] value)
           
 void append(java.lang.String decoratedKey, DataOutputBuffer buffer)
           
 void close()
           
 void close(BloomFilter bf)
           
 void closeRename(BloomFilter bf)
          Renames a temporary SSTable file to a valid data and index file
static void delete(java.lang.String dataFile)
          This method deletes both the specified data file and the associated index file
static int getApproximateKeyCount(java.util.List<java.lang.String> dataFiles)
           
static Coordinate getCoordinates(java.lang.String decoratedKey, IFileReader dataReader, IPartitioner partitioner)
           
 java.lang.String getDataFileLocation()
           
static java.util.List<java.lang.String> getIndexedKeys()
          Get all indexed keys in the SSTable.
static int indexInterval()
           
static boolean isKeyInFile(java.lang.String clientKey, java.lang.String filename)
           
 DataInputBuffer next(java.lang.String clientKey, java.lang.String columnFamilyColumn)
           
 DataInputBuffer next(java.lang.String clientKey, java.lang.String cfName, java.util.List<java.lang.String> columnNames)
           
 DataInputBuffer next(java.lang.String clientKey, java.lang.String cfName, java.util.List<java.lang.String> columnNames, IndexHelper.TimeRange timeRange)
           
static void onStart(java.util.List<java.lang.String> filenames)
           
static void removeAssociatedBloomFilter(java.lang.String filename)
           
static void storeBloomFilter(java.lang.String filename, BloomFilter bf)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blockIndexKey_

public static final java.lang.String blockIndexKey_
See Also:
Constant Field Values

temporaryFile_

public static final java.lang.String temporaryFile_
See Also:
Constant Field Values
Constructor Detail

SSTable

public SSTable(java.lang.String dataFileName,
               IPartitioner partitioner)
        throws java.io.IOException
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.

Throws:
java.io.IOException

SSTable

public SSTable(java.lang.String directory,
               java.lang.String filename,
               IPartitioner partitioner)
        throws java.io.IOException
This ctor is used for writing data into the SSTable. Use this version for non DB writes to the SSTable.

Throws:
java.io.IOException
Method Detail

indexInterval

public static int indexInterval()

delete

public static void delete(java.lang.String dataFile)
This method deletes both the specified data file and the associated index file

Parameters:
dataFile - - data file associated with the SSTable

getApproximateKeyCount

public static int getApproximateKeyCount(java.util.List<java.lang.String> dataFiles)

getIndexedKeys

public static java.util.List<java.lang.String> getIndexedKeys()
Get all indexed keys in the SSTable.


onStart

public static void onStart(java.util.List<java.lang.String> filenames)
                    throws java.io.IOException
Throws:
java.io.IOException

storeBloomFilter

public static void storeBloomFilter(java.lang.String filename,
                                    BloomFilter bf)

removeAssociatedBloomFilter

public static void removeAssociatedBloomFilter(java.lang.String filename)

isKeyInFile

public static boolean isKeyInFile(java.lang.String clientKey,
                                  java.lang.String filename)

getDataFileLocation

public java.lang.String getDataFileLocation()
                                     throws java.io.IOException
Throws:
java.io.IOException

append

public void append(java.lang.String decoratedKey,
                   DataOutputBuffer buffer)
            throws java.io.IOException
Throws:
java.io.IOException

append

public void append(java.lang.String decoratedKey,
                   byte[] value)
            throws java.io.IOException
Throws:
java.io.IOException

getCoordinates

public static Coordinate getCoordinates(java.lang.String decoratedKey,
                                        IFileReader dataReader,
                                        IPartitioner partitioner)
                                 throws java.io.IOException
Throws:
java.io.IOException

next

public DataInputBuffer next(java.lang.String clientKey,
                            java.lang.String cfName,
                            java.util.List<java.lang.String> columnNames)
                     throws java.io.IOException
Throws:
java.io.IOException

next

public DataInputBuffer next(java.lang.String clientKey,
                            java.lang.String cfName,
                            java.util.List<java.lang.String> columnNames,
                            IndexHelper.TimeRange timeRange)
                     throws java.io.IOException
Throws:
java.io.IOException

next

public DataInputBuffer next(java.lang.String clientKey,
                            java.lang.String columnFamilyColumn)
                     throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

close

public void close(BloomFilter bf)
           throws java.io.IOException
Throws:
java.io.IOException

closeRename

public void closeRename(BloomFilter bf)
                 throws java.io.IOException
Renames a temporary SSTable file to a valid data and index file

Throws:
java.io.IOException


Copyright © 2009 The Apache Software Foundation