SecondaryIndex (apache-cassandra API)
Date: 2018-02-12

org.apache.cassandra.db.index

## Class SecondaryIndex

- java.lang.Object
- - org.apache.cassandra.db.index.SecondaryIndex

- Direct Known Subclasses:
    PerColumnSecondaryIndex, PerRowSecondaryIndex

      public abstract class SecondaryIndex
      extends java.lang.Object

  Abstract base class for different types of secondary indexes. Do not extend this directly, please pick from PerColumnSecondaryIndex or PerRowSecondaryIndex

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ColumnFamilyStore` | `baseCfs` Base CF that has many indexes
    `protected java.util.Set<ColumnDefinition>` | `columnDefs` The column definitions which this index is responsible for
    `static java.lang.String` | `CUSTOM_INDEX_OPTION_NAME`
    `static java.lang.String` | `INDEX_ENTRIES_OPTION_NAME` The name of the option used to specify that the index is on the collection (map) entries.
    `static java.lang.String` | `INDEX_KEYS_OPTION_NAME` The name of the option used to specify that the index is on the collection keys.
    `static java.lang.String` | `INDEX_VALUES_OPTION_NAME` The name of the option used to specify that the index is on the collection values.
    `static AbstractType<?>` | `keyComparator`
    `protected static org.slf4j.Logger` | `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SecondaryIndex()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.util.concurrent.Future<?>` | `buildIndexAsync()` Builds the index using the data in the underlying CF, non blocking
    `protected void` | `buildIndexBlocking()` Builds the index using the data in the underlying CFS Blocks till it's complete
    `static SecondaryIndex` | `createInstance(ColumnFamilyStore baseCfs, ColumnDefinition cdef)` This is the primary way to create a secondary index instance for a CF column.
    `protected abstract SecondaryIndexSearcher` | `createSecondaryIndexSearcher(java.util.Set<java.nio.ByteBuffer> columns)` Called at query time Creates a implementation specific searcher instance for this index type
    `abstract long` | `estimateResultRows()`
    `abstract void` | `forceBlockingFlush()` Forces this indexes' in memory data to disk
    `ColumnFamilyStore` | `getBaseCfs()`
    `java.util.Set<ColumnDefinition>` | `getColumnDefs()`
    `abstract ColumnFamilyStore` | `getIndexCfs()` Allow access to the underlying column family store if there is one
    `static CellNameType` | `getIndexComparator(CFMetaData baseMetadata, ColumnDefinition cdef)` Returns the index comparator for index backed by CFS, or null.
    `DecoratedKey` | `getIndexKeyFor(java.nio.ByteBuffer value)` Returns the decoratedKey for a column value.
    `abstract java.lang.String` | `getIndexName()`
    `abstract java.lang.String` | `getNameForSystemKeyspace(java.nio.ByteBuffer columnName)` Return the unique name for this index and column to be stored in the SystemKeyspace that tracks if each column is built
    `abstract boolean` | `indexes(CellName name)` Returns true if the provided cell name is indexed by this secondary index.
    `boolean` | `indexes(ColumnDefinition cdef)` Returns true if the provided column definition is indexed by this secondary index.
    `abstract void` | `init()` Perform any initialization work
    `abstract void` | `invalidate()` Remove the index and unregisters this index's mbean if one exists
    `boolean` | `isIndexBuilt(java.nio.ByteBuffer columnName)` Checks if the index for specified column is fully built
    `boolean` | `isQueryable()` Checks if the index is ready.
    `abstract void` | `reload()` Reload an existing index following a change to its configuration, or that of the indexed column(s).
    `abstract void` | `removeIndex(java.nio.ByteBuffer columnName)` Delete all files and references to this index
    `void` | `setIndexBuilt()`
    `void` | `setIndexRemoved()`
    `boolean` | `supportsOperator(Operator operator)` Returns true if the index supports lookups for the given operator, false otherwise.
    `java.lang.String` | `toString()`
    `abstract void` | `truncateBlocking(long truncatedAt)` Truncate all the data from the current index
    `abstract boolean` | `validate(java.nio.ByteBuffer rowKey, Cell cell)`
    `abstract void` | `validateOptions()` Validates the index_options passed in the ColumnDef

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

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

- - ### Field Detail

    - #### logger

          protected static final org.slf4j.Logger logger

    - #### CUSTOM_INDEX_OPTION_NAME

          public static final java.lang.String CUSTOM_INDEX_OPTION_NAME

      See Also:
        Constant Field Values

    - #### INDEX_KEYS_OPTION_NAME

          public static final java.lang.String INDEX_KEYS_OPTION_NAME

      The name of the option used to specify that the index is on the collection keys.
      See Also:
        Constant Field Values

    - #### INDEX_VALUES_OPTION_NAME

          public static final java.lang.String INDEX_VALUES_OPTION_NAME

      The name of the option used to specify that the index is on the collection values.
      See Also:
        Constant Field Values

    - #### INDEX_ENTRIES_OPTION_NAME

          public static final java.lang.String INDEX_ENTRIES_OPTION_NAME

      The name of the option used to specify that the index is on the collection (map) entries.
      See Also:
        Constant Field Values

    - #### keyComparator

          public static final AbstractType<?> keyComparator

    - #### baseCfs

          protected ColumnFamilyStore baseCfs

      Base CF that has many indexes

    - #### columnDefs

          protected final java.util.Set<ColumnDefinition> columnDefs

      The column definitions which this index is responsible for

  - ### Constructor Detail

    - #### SecondaryIndex

          public SecondaryIndex()

  - ### Method Detail

    - #### init

          public abstract void init()

      Perform any initialization work

    - #### reload

          public abstract void reload()

      Reload an existing index following a change to its configuration, or that of the indexed column(s). Differs from init() in that we expect expect new resources (such as CFS for a KEYS index) to be created by init() but not here

    - #### validateOptions

          public abstract void validateOptions()
                                        throws ConfigurationException

      Validates the index_options passed in the ColumnDef
      Throws:
        `ConfigurationException`

    - #### getIndexName

          public abstract java.lang.String getIndexName()

      Returns:
        The name of the index

    - #### getNameForSystemKeyspace

          public abstract java.lang.String getNameForSystemKeyspace(java.nio.ByteBuffer columnName)

      Return the unique name for this index and column to be stored in the SystemKeyspace that tracks if each column is built
      Parameters:
        `columnName` - the name of the column
      Returns:
        the unique name

    - #### isIndexBuilt

          public boolean isIndexBuilt(java.nio.ByteBuffer columnName)

      Checks if the index for specified column is fully built
      Parameters:
        `columnName` - the column
      Returns:
        true if the index is fully built

    - #### isQueryable

          public boolean isQueryable()

      Checks if the index is ready.
      Returns:
        `true` if the index is ready, `false` otherwise

    - #### setIndexBuilt

          public void setIndexBuilt()

    - #### setIndexRemoved

          public void setIndexRemoved()

    - #### createSecondaryIndexSearcher

          protected abstract SecondaryIndexSearcher createSecondaryIndexSearcher(java.util.Set<java.nio.ByteBuffer> columns)

      Called at query time Creates a implementation specific searcher instance for this index type
      Parameters:
        `columns` - the list of columns which belong to this index type
      Returns:
        the secondary index search impl

    - #### forceBlockingFlush

          public abstract void forceBlockingFlush()

      Forces this indexes' in memory data to disk

    - #### getIndexCfs

          public abstract ColumnFamilyStore getIndexCfs()

      Allow access to the underlying column family store if there is one
      Returns:
        the underlying column family store or null

    - #### removeIndex

          public abstract void removeIndex(java.nio.ByteBuffer columnName)

      Delete all files and references to this index
      Parameters:
        `columnName` - the indexed column to remove

    - #### invalidate

          public abstract void invalidate()

      Remove the index and unregisters this index's mbean if one exists

    - #### truncateBlocking

          public abstract void truncateBlocking(long truncatedAt)

      Truncate all the data from the current index
      Parameters:
        `truncatedAt` - The truncation timestamp, all data before that timestamp should be rejected.

    - #### buildIndexBlocking

          protected void buildIndexBlocking()

      Builds the index using the data in the underlying CFS Blocks till it's complete

    - #### buildIndexAsync

          public final java.util.concurrent.Future<?> buildIndexAsync()

      Builds the index using the data in the underlying CF, non blocking
      Returns:
        A future object which the caller can block on (optional)

    - #### getBaseCfs

          public ColumnFamilyStore getBaseCfs()

    - #### getColumnDefs

          public java.util.Set<ColumnDefinition> getColumnDefs()

    - #### supportsOperator

          public boolean supportsOperator(Operator operator)

      Returns true if the index supports lookups for the given operator, false otherwise.

    - #### getIndexKeyFor

          public DecoratedKey getIndexKeyFor(java.nio.ByteBuffer value)

      Returns the decoratedKey for a column value. Assumes an index CFS is present.
      Parameters:
        `value` - column value
      Returns:
        decorated key

    - #### indexes

          public abstract boolean indexes(CellName name)

      Returns true if the provided cell name is indexed by this secondary index. The default implementation checks whether the name is one the columnDef name, but this should be overriden but subclass if needed.

    - #### indexes

          public boolean indexes(ColumnDefinition cdef)

      Returns true if the provided column definition is indexed by this secondary index. The default implementation checks whether it is contained in this index column definitions set.

    - #### createInstance

          public static SecondaryIndex createInstance(ColumnFamilyStore baseCfs,
                                                      ColumnDefinition cdef)
                                               throws ConfigurationException

      This is the primary way to create a secondary index instance for a CF column. It will validate the index_options before initializing.
      Parameters:
        `baseCfs` - the source of data for the Index
        `cdef` - the meta information about this column (index_type, index_options, name, etc...)
      Returns:
        The secondary index instance for this column
      Throws:
        `ConfigurationException`

    - #### validate

          public abstract boolean validate(java.nio.ByteBuffer rowKey,
                                           Cell cell)

    - #### estimateResultRows

          public abstract long estimateResultRows()

    - #### getIndexComparator

          public static CellNameType getIndexComparator(CFMetaData baseMetadata,
                                                        ColumnDefinition cdef)

      Returns the index comparator for index backed by CFS, or null. Note: it would be cleaner to have this be a member method. However we need this when opening indexes sstables, but by then the CFS won't be fully initiated, so the SecondaryIndex object won't be accessible.

    - #### toString

          public java.lang.String toString()

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

Copyright © 2018 The Apache Software Foundation