Class PaxosUncommittedIndex
- java.lang.Object
-
- org.apache.cassandra.service.paxos.uncommitted.PaxosUncommittedIndex
-
- All Implemented Interfaces:
Index,PaxosUncommittedTracker.UpdateSupplier
public class PaxosUncommittedIndex extends java.lang.Object implements Index, PaxosUncommittedTracker.UpdateSupplier
A 2i implementation made specifically for system.paxos that listens for changes to paxos state by interpreting mutations against system.paxos and updates the uncommitted tracker accordingly. No read expressions are supported by the index. This is implemented as a 2i so it can piggy back off the commit log and paxos table flushes, and avoid worrying about implementing a parallel log/flush system for the tracker and potential bugs there. It also means we don't have to worry about cases where the tracker can become out of sync with the paxos table due to failure/edge cases outside of the PaxosTableState class itself.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.cassandra.index.Index
Index.CollatedViewIndexBuildingSupport, Index.IndexBuildingSupport, Index.Indexer, Index.LoadType, Index.Searcher
-
-
Field Summary
Fields Modifier and Type Field Description ColumnFamilyStorebaseCfsprotected IndexMetadatametadata-
Fields inherited from interface org.apache.cassandra.index.Index
INDEX_BUILDER_SUPPORT
-
-
Constructor Summary
Constructors Constructor Description PaxosUncommittedIndex(ColumnFamilyStore baseTable, IndexMetadata metadata)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractType<?>customExpressionValueType()If the index supports custom search expressions using the SELECT * FROM table WHERE expr(index_name, expression) syntax, this method should return the expected type of the expression argument.booleandependsOn(ColumnMetadata column)Called to determine whether this index targets a specific column.CloseableIterator<PaxosKeyState>flushIterator(Memtable flushing)java.util.Optional<ColumnFamilyStore>getBackingTable()If the index implementation uses a local table to store its index data this method should return a handle to it.java.util.concurrent.Callable<?>getBlockingFlushTask()Return a task which performs a blocking flush of any in-memory index data to persistent storage, independent of any flush of the base table.java.util.concurrent.Callable<?>getBlockingFlushTask(Memtable paxos)Return a task which performs a blocking flush of the index's data corresponding to the provided base table's Memtable.longgetEstimatedResultRows()Return an estimate of the number of results this index is expected to return for any given query that it can be used to answer.IndexMetadatagetIndexMetadata()Returns the IndexMetadata which configures and defines the index instance.java.util.concurrent.Callable<?>getInitializationTask()Return a task to perform any initialization work when a new index instance is created.java.util.concurrent.Callable<?>getInvalidateTask()Return a task which invalidates the index, indicating it should no longer be considered usable.java.util.concurrent.Callable<?>getMetadataReloadTask(IndexMetadata indexMetadata)Return a task to reload the internal metadata of an index.RowFiltergetPostIndexQueryFilter(RowFilter filter)Transform an initial RowFilter into the filter that will still need to applied to a set of Rows after the index has performed it's initial scan.java.util.concurrent.Callable<?>getTruncateTask(long truncatedAt)Return a task to truncate the index with the specified truncation timestamp.Index.IndexerindexerFor(DecoratedKey key, RegularAndStaticColumns columns, int nowInSec, WriteContext ctx, IndexTransaction.Type transactionType)Creates an newIndexerobject for updates to a given partition.static Indexesindexes()static IndexMetadataindexMetadata()java.util.function.BiFunction<PartitionIterator,ReadCommand,PartitionIterator>postProcessorFor(ReadCommand command)Return a function which performs post processing on the results of a partition range read command.voidregister(IndexRegistry registry)An index must be registered in order to be able to either subscribe to update events on the base table and/or to provide Searcher functionality for reads.CloseableIterator<PaxosKeyState>repairIterator(TableId tableId, java.util.Collection<Range<Token>> ranges)Index.SearchersearcherFor(ReadCommand command)Factory method for query time search helper.booleanshouldBuildBlocking()Return true if this index can be built or rebuilt when the index manager determines it is necessary.booleansupportsExpression(ColumnMetadata column, Operator operator)Called to determine whether this index can provide a searcher to execute a query on the supplied column using the specified operator.voidvalidate(PartitionUpdate update)Called at write time to ensure that values present in the update are valid according to the rules of all registered indexes which will process it.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.index.Index
getBuildTaskSupport, getFlushObserver, getPreJoinTask, getRecoveryTaskSupport, getSupportedLoadTypeOnFailure, notifyIndexerAboutRowsInFullyExpiredSSTables, supportsReplicaFilteringProtection, validate
-
-
-
-
Field Detail
-
baseCfs
public final ColumnFamilyStore baseCfs
-
metadata
protected IndexMetadata metadata
-
-
Constructor Detail
-
PaxosUncommittedIndex
public PaxosUncommittedIndex(ColumnFamilyStore baseTable, IndexMetadata metadata)
-
-
Method Detail
-
indexMetadata
public static IndexMetadata indexMetadata()
-
indexes
public static Indexes indexes()
-
getInitializationTask
public java.util.concurrent.Callable<?> getInitializationTask()
Description copied from interface:IndexReturn a task to perform any initialization work when a new index instance is created. This may involve costly operations such as (re)building the index, and is performed asynchronously by SecondaryIndexManager- Specified by:
getInitializationTaskin interfaceIndex- Returns:
- a task to perform any necessary initialization work
-
getIndexMetadata
public IndexMetadata getIndexMetadata()
Description copied from interface:IndexReturns the IndexMetadata which configures and defines the index instance. This should be the same object passed as the argument to setIndexMetadata.- Specified by:
getIndexMetadatain interfaceIndex- Returns:
- the index's metadata
-
getMetadataReloadTask
public java.util.concurrent.Callable<?> getMetadataReloadTask(IndexMetadata indexMetadata)
Description copied from interface:IndexReturn a task to reload the internal metadata of an index. Called when the base table metadata is modified or when the configuration of the Index is updated Implementations should return a task which performs any necessary work to be done due to updating the configuration(s) such as (re)building etc. This task is performed asynchronously by SecondaryIndexManager- Specified by:
getMetadataReloadTaskin interfaceIndex- Returns:
- task to be executed by the index manager during a reload
-
register
public void register(IndexRegistry registry)
Description copied from interface:IndexAn index must be registered in order to be able to either subscribe to update events on the base table and/or to provide Searcher functionality for reads. The double dispatch involved here, where the Index actually performs its own registration by calling back to the supplied IndexRegistry's own registerIndex method, is to make the decision as to whether or not to register an index belong to the implementation, not the manager.
-
getBackingTable
public java.util.Optional<ColumnFamilyStore> getBackingTable()
Description copied from interface:IndexIf the index implementation uses a local table to store its index data this method should return a handle to it. If not, an empty Optional should be returned. Typically, this is useful for the built-in Index implementations.- Specified by:
getBackingTablein interfaceIndex- Returns:
- an Optional referencing the Index's backing storage table if it has one, or Optional.empty() if not.
-
repairIterator
public CloseableIterator<PaxosKeyState> repairIterator(TableId tableId, java.util.Collection<Range<Token>> ranges)
- Specified by:
repairIteratorin interfacePaxosUncommittedTracker.UpdateSupplier
-
flushIterator
public CloseableIterator<PaxosKeyState> flushIterator(Memtable flushing)
- Specified by:
flushIteratorin interfacePaxosUncommittedTracker.UpdateSupplier
-
getBlockingFlushTask
public java.util.concurrent.Callable<?> getBlockingFlushTask()
Description copied from interface:IndexReturn a task which performs a blocking flush of any in-memory index data to persistent storage, independent of any flush of the base table. Note that this method is only invoked outside of normal flushes: if there is no in-memory storage for this index, and it only extracts data on flush from the base table's Memtable, then it is safe to perform no work.- Specified by:
getBlockingFlushTaskin interfaceIndex- Returns:
- task to be executed by the index manager to perform the flush.
-
getBlockingFlushTask
public java.util.concurrent.Callable<?> getBlockingFlushTask(Memtable paxos)
Description copied from interface:IndexReturn a task which performs a blocking flush of the index's data corresponding to the provided base table's Memtable. This may extract any necessary data from the base table's Memtable as part of the flush. This version of the method is invoked whenever we flush the base table. If the index stores no in-memory data of its own, it is safe to only implement this method.- Specified by:
getBlockingFlushTaskin interfaceIndex- Returns:
- task to be executed by the index manager to perform the flush.
-
getInvalidateTask
public java.util.concurrent.Callable<?> getInvalidateTask()
Description copied from interface:IndexReturn a task which invalidates the index, indicating it should no longer be considered usable. This should include an clean up and releasing of resources required when dropping an index.- Specified by:
getInvalidateTaskin interfaceIndex- Returns:
- task to be executed by the index manager to invalidate the index.
-
getTruncateTask
public java.util.concurrent.Callable<?> getTruncateTask(long truncatedAt)
Description copied from interface:IndexReturn a task to truncate the index with the specified truncation timestamp. Called when the base table is truncated.- Specified by:
getTruncateTaskin interfaceIndex- Parameters:
truncatedAt- timestamp of the truncation operation. This will be the same timestamp used in the truncation of the base table.- Returns:
- task to be executed by the index manager when the base table is truncated.
-
shouldBuildBlocking
public boolean shouldBuildBlocking()
Description copied from interface:IndexReturn true if this index can be built or rebuilt when the index manager determines it is necessary. Returning false enables the index implementation (or some other component) to control if and when SSTable data is incorporated into the index. This is called by SecondaryIndexManager in buildIndexBlocking, buildAllIndexesBlocking and rebuildIndexesBlocking where a return value of false causes the index to be exluded from the set of those which will process the SSTable data.- Specified by:
shouldBuildBlockingin interfaceIndex- Returns:
- if the index should be included in the set which processes SSTable data, false otherwise.
-
dependsOn
public boolean dependsOn(ColumnMetadata column)
Description copied from interface:IndexCalled to determine whether this index targets a specific column. Used during schema operations such as when dropping or renaming a column, to check if the index will be affected by the change. Typically, if an index answers that it does depend upon a column, then schema operations on that column are not permitted until the index is dropped or altered.
-
supportsExpression
public boolean supportsExpression(ColumnMetadata column, Operator operator)
Description copied from interface:IndexCalled to determine whether this index can provide a searcher to execute a query on the supplied column using the specified operator. This forms part of the query validation done before a CQL select statement is executed.- Specified by:
supportsExpressionin interfaceIndex- Parameters:
column- the target column of a search query predicateoperator- the operator of a search query predicate- Returns:
- true if this index is capable of supporting such expressions, false otherwise
-
customExpressionValueType
public AbstractType<?> customExpressionValueType()
Description copied from interface:IndexIf the index supports custom search expressions using the SELECT * FROM table WHERE expr(index_name, expression) syntax, this method should return the expected type of the expression argument. For example, if the index supports custom expressions as Strings, calls to this method should return UTF8Type.instance. If the index implementation does not support custom expressions, then it should return null.- Specified by:
customExpressionValueTypein interfaceIndex- Returns:
- an the type of custom index expressions supported by this index, or an null if custom expressions are not supported.
-
getPostIndexQueryFilter
public RowFilter getPostIndexQueryFilter(RowFilter filter)
Description copied from interface:IndexTransform an initial RowFilter into the filter that will still need to applied to a set of Rows after the index has performed it's initial scan. Used in ReadCommand#executeLocal to reduce the amount of filtering performed on the results of the index query.- Specified by:
getPostIndexQueryFilterin interfaceIndex- Parameters:
filter- the intial filter belonging to a ReadCommand- Returns:
- the (hopefully) reduced filter that would still need to be applied after the index was used to narrow the initial result set
-
getEstimatedResultRows
public long getEstimatedResultRows()
Description copied from interface:IndexReturn an estimate of the number of results this index is expected to return for any given query that it can be used to answer. Used in conjunction with indexes() and supportsExpression() to determine the most selective index for a given ReadCommand. Additionally, this is also used by StorageProxy.estimateResultsPerRange to calculate the initial concurrency factor for range requests- Specified by:
getEstimatedResultRowsin interfaceIndex- Returns:
- the estimated average number of results a Searcher may return for any given query
-
validate
public void validate(PartitionUpdate update) throws InvalidRequestException
Description copied from interface:IndexCalled at write time to ensure that values present in the update are valid according to the rules of all registered indexes which will process it. The partition key as well as the clustering and cell values for each row in the update may be checked by index implementations- Specified by:
validatein interfaceIndex- Parameters:
update- PartitionUpdate containing the values to be validated by registered Index implementations- Throws:
InvalidRequestException
-
indexerFor
public Index.Indexer indexerFor(DecoratedKey key, RegularAndStaticColumns columns, int nowInSec, WriteContext ctx, IndexTransaction.Type transactionType)
Description copied from interface:IndexCreates an newIndexerobject for updates to a given partition.- Specified by:
indexerForin interfaceIndex- Parameters:
key- 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 compaction- Returns:
- the newly created indexer or
nullif 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, ...).
-
postProcessorFor
public java.util.function.BiFunction<PartitionIterator,ReadCommand,PartitionIterator> postProcessorFor(ReadCommand command)
Description copied from interface:IndexReturn a function which performs post processing on the results of a partition range read command. In future, this may be used as a generalized mechanism for transforming results on the coordinator prior to returning them to the caller. This is used on the coordinator during execution of a range command to perform post processing of merged results obtained from the necessary replicas. This is the only way in which results are transformed in this way but this may change over time as usage is generalized. See CASSANDRA-8717 for further discussion. The function takes a PartitionIterator of the results from the replicas which has already been collated and reconciled, along with the command being executed. It returns another PartitionIterator containing the results of the transformation (which may be the same as the input if the transformation is a no-op).- Specified by:
postProcessorForin interfaceIndex
-
searcherFor
public Index.Searcher searcherFor(ReadCommand command)
Description copied from interface:IndexFactory method for query time search helper.- Specified by:
searcherForin interfaceIndex- Parameters:
command- the read command being executed- Returns:
- an Searcher with which to perform the supplied command
-
-