Package org.apache.cassandra.index.sai
Class StorageAttachedIndexGroup
- java.lang.Object
-
- org.apache.cassandra.index.sai.StorageAttachedIndexGroup
-
- All Implemented Interfaces:
Index.Group
,INotificationConsumer
@ThreadSafe public class StorageAttachedIndexGroup extends java.lang.Object implements Index.Group, INotificationConsumer
Orchestrates building of storage-attached indices, and manages lifecycle of resources shared between them.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.cassandra.index.Index.Group
Index.Group.Key
-
-
Field Summary
Fields Modifier and Type Field Description static Index.Group.Key
GROUP_KEY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIndex(Index index)
Adds the specifiedIndex
as a member of this group.boolean
containsIndex(Index index)
Returns if this group contains the specifiedIndex
.long
diskUsage()
java.util.Set<Component>
getComponents()
Returns the SSTable-attachedComponent
s created by this index group.SSTableFlushObserver
getFlushObserver(Descriptor descriptor, LifecycleNewTracker tracker, TableMetadata tableMetadata)
Get flush observer to observe partition/cell events generated by flushing SSTable (memtable flush or compaction).java.util.Set<Index>
getIndexes()
Returns the indexes that are members of this group.static StorageAttachedIndexGroup
getIndexGroup(ColumnFamilyStore cfs)
static java.util.Set<Component>
getLiveComponents(SSTableReader sstable, java.util.Collection<StorageAttachedIndex> indices)
void
handleNotification(INotification notification, java.lang.Object sender)
boolean
handles(IndexTransaction.Type type)
Index.Indexer
indexerFor(java.util.function.Predicate<Index> indexSelector, DecoratedKey key, RegularAndStaticColumns columns, long nowInSec, WriteContext ctx, IndexTransaction.Type transactionType, Memtable memtable)
Creates an newIndexer
object for updates to a given partition.void
invalidate()
Called when the table associated with this group has been invalidated or all indexes in the group are removed.boolean
isSingleton()
Returns whether this group can only ever contain a single index.TableMetadata
metadata()
int
openIndexFiles()
open index files by checking number ofSSTableContext
andSSTableIndex
, so transient open files during validation and files that are still open for in-flight requests will not be tracked.StorageAttachedIndexQueryPlan
queryPlanFor(RowFilter rowFilter)
Returns a newIndex.QueryPlan
for the specifiedRowFilter
, ornull
if none of the indexes in this group supports the expression in the row filter.void
removeIndex(Index index)
Removes the specifiedIndex
from the members of this group.void
reset()
Simulate the index going through a restart of nodeSSTableContextManager
sstableContextManager()
ColumnFamilyStore
table()
long
totalDiskUsage()
int
totalIndexBuildsInProgress()
int
totalIndexCount()
int
totalQueryableIndexCount()
void
unsafeReload()
simulate index loading on restart with index file validationboolean
validateSSTableAttachedIndexes(java.util.Collection<SSTableReader> sstables, boolean throwOnIncomplete, boolean validateChecksum)
Validates all indexes in the group against the specified SSTables.
-
-
-
Field Detail
-
GROUP_KEY
public static final Index.Group.Key GROUP_KEY
-
-
Method Detail
-
getIndexGroup
@Nullable public static StorageAttachedIndexGroup getIndexGroup(ColumnFamilyStore cfs)
-
getIndexes
public java.util.Set<Index> getIndexes()
Description copied from interface:Index.Group
Returns the indexes that are members of this group.- Specified by:
getIndexes
in interfaceIndex.Group
- Returns:
- the indexes that are members of this group
-
addIndex
public void addIndex(Index index)
Description copied from interface:Index.Group
Adds the specifiedIndex
as a member of this group.- Specified by:
addIndex
in interfaceIndex.Group
- Parameters:
index
- the index to be added
-
removeIndex
public void removeIndex(Index index)
Description copied from interface:Index.Group
Removes the specifiedIndex
from the members of this group.- Specified by:
removeIndex
in interfaceIndex.Group
- Parameters:
index
- the index to be removed
-
invalidate
public void invalidate()
Description copied from interface:Index.Group
Called when the table associated with this group has been invalidated or all indexes in the group are removed. Implementations should dispose of any resources tied to the lifecycle of theIndex.Group
.- Specified by:
invalidate
in interfaceIndex.Group
-
containsIndex
public boolean containsIndex(Index index)
Description copied from interface:Index.Group
Returns if this group contains the specifiedIndex
.- Specified by:
containsIndex
in interfaceIndex.Group
- Parameters:
index
- the index to be removed- Returns:
true
if this group containsindex
,false
otherwise
-
isSingleton
public boolean isSingleton()
Description copied from interface:Index.Group
Returns whether this group can only ever contain a single index.- Specified by:
isSingleton
in interfaceIndex.Group
- Returns:
true
if this group only contains a single index,false
otherwise
-
indexerFor
public Index.Indexer indexerFor(java.util.function.Predicate<Index> indexSelector, DecoratedKey key, RegularAndStaticColumns columns, long nowInSec, WriteContext ctx, IndexTransaction.Type transactionType, Memtable memtable)
Description copied from interface:Index.Group
Creates an newIndexer
object for updates to a given partition.- Specified by:
indexerFor
in interfaceIndex.Group
- Parameters:
indexSelector
- a predicate selecting the targeted memberskey
- key of the partition being modifiedcolumns
- the regular and static columns the created indexer will have to deal with. This can be empty as an update might only contain partition, range and row deletions, but the indexer is guaranteed to not get any cells for a column that is not part ofcolumns
.nowInSec
- current time of the update operationctx
- WriteContext spanning the update operationtransactionType
- indicates what kind of update is being performed on the base data i.e. a write time insert/update/delete or the result of compactionmemtable
- theMemtable
to which the updates are being applied ornull
if the source of the updates is an existingSSTable
- Returns:
- the newly created indexer or
null
if the index is not interested by the update (this could be because the index doesn't care about that particular partition, doesn't care about that type of transaction, ...).
-
queryPlanFor
public StorageAttachedIndexQueryPlan queryPlanFor(RowFilter rowFilter)
Description copied from interface:Index.Group
Returns a newIndex.QueryPlan
for the specifiedRowFilter
, ornull
if none of the indexes in this group supports the expression in the row filter.- Specified by:
queryPlanFor
in interfaceIndex.Group
- Parameters:
rowFilter
- a row filter- Returns:
- a new query plan for the specified
RowFilter
if it's supported,null
otherwise
-
getFlushObserver
public SSTableFlushObserver getFlushObserver(Descriptor descriptor, LifecycleNewTracker tracker, TableMetadata tableMetadata)
Description copied from interface:Index.Group
Get flush observer to observe partition/cell events generated by flushing SSTable (memtable flush or compaction).- Specified by:
getFlushObserver
in interfaceIndex.Group
- Parameters:
descriptor
- The descriptor of the sstable observer is requested for.tracker
- TheLifecycleNewTracker
associated with the SSTable being writtentableMetadata
- The immutable metadata of the table at the moment the SSTable is flushed- Returns:
- SSTable flush observer.
-
handles
public boolean handles(IndexTransaction.Type type)
- Specified by:
handles
in interfaceIndex.Group
- Parameters:
type
- index transaction type- Returns:
- true if index will be able to handle given index transaction type
-
getComponents
public java.util.Set<Component> getComponents()
Description copied from interface:Index.Group
Returns the SSTable-attachedComponent
s created by this index group.- Specified by:
getComponents
in interfaceIndex.Group
- Returns:
- the SSTable components created by this group
-
getLiveComponents
public static java.util.Set<Component> getLiveComponents(SSTableReader sstable, java.util.Collection<StorageAttachedIndex> indices)
-
handleNotification
public void handleNotification(INotification notification, java.lang.Object sender)
- Specified by:
handleNotification
in interfaceINotificationConsumer
-
validateSSTableAttachedIndexes
public boolean validateSSTableAttachedIndexes(java.util.Collection<SSTableReader> sstables, boolean throwOnIncomplete, boolean validateChecksum)
Description copied from interface:Index.Group
Validates all indexes in the group against the specified SSTables.- Specified by:
validateSSTableAttachedIndexes
in interfaceIndex.Group
- Parameters:
sstables
- SSTables for which indexes in the group should be builtthrowOnIncomplete
- whether to throw an error if any index in the group is incompletevalidateChecksum
- whether checksum will be tested as part of the validation- Returns:
- true if all indexes in the group are complete and valid
false if any index is incomplete and
throwOnIncomplete
is false
-
openIndexFiles
public int openIndexFiles()
open index files by checking number ofSSTableContext
andSSTableIndex
, so transient open files during validation and files that are still open for in-flight requests will not be tracked.- Returns:
- total number of open files for all
StorageAttachedIndex
es.
-
diskUsage
public long diskUsage()
- Returns:
- total disk usage (in bytes) of all per-sstable index files
-
totalIndexBuildsInProgress
public int totalIndexBuildsInProgress()
- Returns:
- count of indexes building
-
totalQueryableIndexCount
public int totalQueryableIndexCount()
- Returns:
- count of queryable indexes
-
totalIndexCount
public int totalIndexCount()
- Returns:
- count of indexes
-
totalDiskUsage
public long totalDiskUsage()
- Returns:
- total disk usage of all per-sstable index files and per-column index files
-
metadata
public TableMetadata metadata()
-
table
public ColumnFamilyStore table()
-
sstableContextManager
public SSTableContextManager sstableContextManager()
-
unsafeReload
public void unsafeReload()
simulate index loading on restart with index file validation
-
reset
public void reset()
Simulate the index going through a restart of node
-
-