SSTable (apache-cassandra API)
Date: 2014-10-21

org.apache.cassandra.io.sstable

## Class SSTable

- java.lang.Object
- - org.apache.cassandra.io.sstable.SSTable

- Direct Known Subclasses:
    SSTableReader, SSTableWriter

      public abstract 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. A separate index file is maintained as well, containing the SSTable keys and the offset into the SSTable at which they are found. Every 1/indexInterval key is read into memory when the SSTable is opened. Finally, a bloom filter file is also kept for the keys in each SSTable.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Set<Component>` | `components`
    `boolean` | `compression`
    `Descriptor` | `descriptor`
    `DecoratedKey` | `first`
    `DecoratedKey` | `last`
    `CFMetaData` | `metadata`
    `IPartitioner` | `partitioner`
    `static int` | `TOMBSTONE_HISTOGRAM_BIN_SIZE`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `SSTable(Descriptor descriptor, CFMetaData metadata, IPartitioner partitioner)`
    `protected` | `SSTable(Descriptor descriptor, java.util.Set<Component> components, CFMetaData metadata, IPartitioner partitioner)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addComponents(java.util.Collection<Component> newComponents)` Registers new custom components.
    `protected static void` | `appendTOC(Descriptor descriptor, java.util.Collection<Component> components)` Appends new component names to the TOC component.
    `long` | `bytesOnDisk()`
    `static java.util.Set<Component>` | `componentsFor(Descriptor desc)` Discovers existing components for the descriptor.
    `static boolean` | `delete(Descriptor desc, java.util.Set<Component> components)` We use a ReferenceQueue to manage deleting files that have been compacted and for which no more SSTable references exist.
    `java.lang.String` | `getColumnFamilyName()`
    `java.lang.String` | `getFilename()`
    `java.lang.String` | `getIndexFilename()`
    `java.lang.String` | `getKeyspaceName()`
    `static DecoratedKey` | `getMinimalKey(DecoratedKey key)` If the given @param key occupies only part of a larger buffer, allocate a new buffer that is only as large as necessary.
    `protected static java.util.Set<Component>` | `readTOC(Descriptor descriptor)` Reads the list of components from the TOC component.
    `java.lang.String` | `toString()`
    `static Pair<Descriptor,Component>` | `tryComponentFromFilename(java.io.File dir, java.lang.String name)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### TOMBSTONE_HISTOGRAM_BIN_SIZE

          public static final int TOMBSTONE_HISTOGRAM_BIN_SIZE

      See Also:
        Constant Field Values

    - #### descriptor

          public final Descriptor descriptor

    - #### components

          protected final java.util.Set<Component> components

    - #### metadata

          public final CFMetaData metadata

    - #### partitioner

          public final IPartitioner partitioner

    - #### compression

          public final boolean compression

    - #### first

          public DecoratedKey first

    - #### last

          public DecoratedKey last

  - ### Constructor Detail

    - #### SSTable

          protected SSTable(Descriptor descriptor,
                 CFMetaData metadata,
                 IPartitioner partitioner)

    - #### SSTable

          protected SSTable(Descriptor descriptor,
                 java.util.Set<Component> components,
                 CFMetaData metadata,
                 IPartitioner partitioner)

  - ### Method Detail

    - #### delete

          public static boolean delete(Descriptor desc,
                       java.util.Set<Component> components)

      We use a ReferenceQueue to manage deleting files that have been compacted and for which no more SSTable references exist. But this is not guaranteed to run for each such file because of the semantics of the JVM gc. So, we write a marker to `compactedFilename` when a file is compacted; if such a marker exists on startup, the file should be removed. This method will also remove SSTables that are marked as temporary.
      Returns:
        true if the file was deleted

    - #### getMinimalKey

          public static DecoratedKey getMinimalKey(DecoratedKey key)

      If the given @param key occupies only part of a larger buffer, allocate a new buffer that is only as large as necessary.

    - #### getFilename

          public java.lang.String getFilename()

    - #### getIndexFilename

          public java.lang.String getIndexFilename()

    - #### getColumnFamilyName

          public java.lang.String getColumnFamilyName()

    - #### getKeyspaceName

          public java.lang.String getKeyspaceName()

    - #### tryComponentFromFilename

          public static Pair<Descriptor,Component> tryComponentFromFilename(java.io.File dir,
                                                            java.lang.String name)

      Returns:
        A Descriptor,Component pair. If component is of unknown type, returns CUSTOM component.

    - #### componentsFor

          public static java.util.Set<Component> componentsFor(Descriptor desc)

      Discovers existing components for the descriptor. Slow: only intended for use outside the critical path.

    - #### bytesOnDisk

          public long bytesOnDisk()

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### readTOC

          protected static java.util.Set<Component> readTOC(Descriptor descriptor)
                                                     throws java.io.IOException

      Reads the list of components from the TOC component.
      Returns:
        set of components found in the TOC
      Throws:
        `java.io.IOException`

    - #### appendTOC

          protected static void appendTOC(Descriptor descriptor,
                       java.util.Collection<Component> components)

      Appends new component names to the TOC component.

    - #### addComponents

          public void addComponents(java.util.Collection<Component> newComponents)

      Registers new custom components. Used by custom compaction strategies. Adding a component for the second time is a no-op. Don't remove this - this method is a part of the public API, intended for use by custom compaction strategies.
      Parameters:
        `newComponents` - collection of components to be added

Copyright © 2014 The Apache Software Foundation