org.apache.cassandra.db.index
Class SecondaryIndexManager

java.lang.Object
  extended by org.apache.cassandra.db.index.SecondaryIndexManager

public class SecondaryIndexManager
extends java.lang.Object

Manages all the indexes associated with a given CFS Different types of indexes can be created across the same CF


Field Summary
 ColumnFamilyStore baseCfs
          The underlying column family containing the source data for these indexes
 
Constructor Summary
SecondaryIndexManager(ColumnFamilyStore baseCfs)
           
 
Method Summary
 java.util.concurrent.Future<?> addIndexedColumn(ColumnDefinition cdef)
          Adds and builds a index for a column
 void applyIndexUpdates(java.nio.ByteBuffer rowKey, ColumnFamily cf, java.util.SortedSet<java.nio.ByteBuffer> mutatedIndexedColumns, ColumnFamily oldIndexedColumns)
          Removes obsolete index entries and creates new ones for the given row key and mutated columns.
 void deleteFromIndexes(DecoratedKey<?> key, java.util.List<IColumn> indexedColumnsInRow)
          Delete all columns from all indexes for this row
 void flushIndexesBlocking()
          Flush all indexes to disk
 java.util.List<java.lang.String> getBuiltIndexes()
           
 java.util.SortedSet<java.nio.ByteBuffer> getIndexedColumns()
           
 java.util.Collection<ColumnFamilyStore> getIndexesBackedByCfs()
           
 SecondaryIndex getIndexForColumn(java.nio.ByteBuffer column)
           
 DecoratedKey<LocalToken> getIndexKeyFor(java.nio.ByteBuffer name, java.nio.ByteBuffer value)
          Returns the decoratedKey for a column value
 void maybeBuildSecondaryIndexes(java.util.Collection<SSTableReader> sstables, java.util.SortedSet<java.nio.ByteBuffer> columns)
          Does a full, blocking rebuild of the indexes specified by columns from the sstables.
 void reload()
          Drops and adds new indexes associated with the underlying CF
 void removeAllIndexes()
          Remove all underlying index data
 void removeIndexedColumn(java.nio.ByteBuffer column)
          Removes a existing index
 void renameIndexes(java.lang.String newCfName)
          Rename all underlying index files
 java.util.List<Row> search(org.apache.cassandra.thrift.IndexClause clause, AbstractBounds range, IFilter dataFilter)
          Performs a search across a number of column indexes TODO: add support for querying across index types
 void unregisterMBeans()
          Remove all index MBeans
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseCfs

public final ColumnFamilyStore baseCfs
The underlying column family containing the source data for these indexes

Constructor Detail

SecondaryIndexManager

public SecondaryIndexManager(ColumnFamilyStore baseCfs)
Method Detail

reload

public void reload()
            throws java.io.IOException
Drops and adds new indexes associated with the underlying CF

Throws:
java.io.IOException

maybeBuildSecondaryIndexes

public void maybeBuildSecondaryIndexes(java.util.Collection<SSTableReader> sstables,
                                       java.util.SortedSet<java.nio.ByteBuffer> columns)
                                throws java.io.IOException
Does a full, blocking rebuild of the indexes specified by columns from the sstables. Does nothing if columns is empty. Caller must acquire and release references to the sstables used here.

Parameters:
sstables - the data to build from
columns - the list of columns to index
Throws:
java.io.IOException

getIndexedColumns

public java.util.SortedSet<java.nio.ByteBuffer> getIndexedColumns()
Returns:
the list of indexed columns

removeIndexedColumn

public void removeIndexedColumn(java.nio.ByteBuffer column)
                         throws java.io.IOException
Removes a existing index

Parameters:
column - the indexed column to remove
Throws:
java.io.IOException

addIndexedColumn

public java.util.concurrent.Future<?> addIndexedColumn(ColumnDefinition cdef)
Adds and builds a index for a column

Parameters:
cdef - the column definition holding the index data
Returns:
a future which the caller can optionally block on signaling the index is built

getIndexForColumn

public SecondaryIndex getIndexForColumn(java.nio.ByteBuffer column)
Parameters:
column - the name of indexes column
Returns:
the index

unregisterMBeans

public void unregisterMBeans()
Remove all index MBeans


removeAllIndexes

public void removeAllIndexes()
                      throws java.io.IOException
Remove all underlying index data

Throws:
java.io.IOException

renameIndexes

public void renameIndexes(java.lang.String newCfName)
                   throws java.io.IOException
Rename all underlying index files

Parameters:
newCfName - the new index Name
Throws:
java.io.IOException

flushIndexesBlocking

public void flushIndexesBlocking()
                          throws java.io.IOException
Flush all indexes to disk

Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException
java.io.IOException

getIndexKeyFor

public DecoratedKey<LocalToken> getIndexKeyFor(java.nio.ByteBuffer name,
                                               java.nio.ByteBuffer value)
Returns the decoratedKey for a column value

Parameters:
name - column name
value - column value
Returns:
decorated key

getBuiltIndexes

public java.util.List<java.lang.String> getBuiltIndexes()
Returns:
all built indexes (ready to use)

getIndexesBackedByCfs

public java.util.Collection<ColumnFamilyStore> getIndexesBackedByCfs()
Returns:
all CFS from indexes which use a backing CFS internally (KEYS)

applyIndexUpdates

public void applyIndexUpdates(java.nio.ByteBuffer rowKey,
                              ColumnFamily cf,
                              java.util.SortedSet<java.nio.ByteBuffer> mutatedIndexedColumns,
                              ColumnFamily oldIndexedColumns)
                       throws java.io.IOException
Removes obsolete index entries and creates new ones for the given row key and mutated columns. For columns whos underlying index type has the isRowLevelIndex() flag set to true this function will call the

Parameters:
rowKey - the row key
cf - the current rows data
mutatedIndexedColumns - the set of columns that were changed or added
oldIndexedColumns - the columns what were deleted
Throws:
java.io.IOException

deleteFromIndexes

public void deleteFromIndexes(DecoratedKey<?> key,
                              java.util.List<IColumn> indexedColumnsInRow)
                       throws java.io.IOException
Delete all columns from all indexes for this row

Parameters:
key - the row key
indexedColumnsInRow - all column names in row
Throws:
java.io.IOException

search

public java.util.List<Row> search(org.apache.cassandra.thrift.IndexClause clause,
                                  AbstractBounds range,
                                  IFilter dataFilter)
Performs a search across a number of column indexes TODO: add support for querying across index types

Parameters:
clause - the index query clause
range - the row range to restrict to
dataFilter - the column range to restrict to
Returns:
found indexed rows


Copyright © 2011 The Apache Software Foundation