Package org.apache.cassandra.db.memtable
Class AbstractAllocatorMemtable
java.lang.Object
org.apache.cassandra.db.memtable.AbstractMemtable
org.apache.cassandra.db.memtable.AbstractMemtableWithCommitlog
org.apache.cassandra.db.memtable.AbstractAllocatorMemtable
- All Implemented Interfaces:
Comparable<Memtable>,CellSourceIdentifier,Memtable,UnfilteredSource
- Direct Known Subclasses:
AbstractShardedMemtable,SkipListMemtable
A memtable that uses memory tracked and maybe allocated via a MemtableAllocator from a MemtablePool.
Provides methods of memory tracking and triggering flushes when the relevant limits are reached.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.cassandra.db.memtable.AbstractMemtable
AbstractMemtable.AbstractFlushablePartitionSet<P extends Partition>, AbstractMemtable.ColumnsCollector, AbstractMemtable.StatsCollectorNested classes/interfaces inherited from interface org.apache.cassandra.db.memtable.Memtable
Memtable.Factory, Memtable.FlushablePartitionSet<P extends Partition>, Memtable.LastCommitLogPosition, Memtable.MemoryUsage, Memtable.Owner -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final MemtableAllocatorprotected final ClusteringComparatorfinal Memtable.Factorystatic final MemtablePoolprotected final Memtable.OwnerFields inherited from class org.apache.cassandra.db.memtable.AbstractMemtable
columnsCollector, currentOperations, metadata, minLocalDeletionTime, minTimestamp, statsCollectorFields inherited from interface org.apache.cassandra.db.memtable.Memtable
NO_MIN_TIMESTAMP -
Constructor Summary
ConstructorsConstructorDescriptionAbstractAllocatorMemtable(AtomicReference<CommitLogPosition> commitLogLowerBound, TableMetadataRef metadataRef, Memtable.Owner owner) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd this memtable's used memory to the given usage object.static MemtablePoolcreateMemtableAllocatorPoolInternal(Config.MemtableAllocationType allocationType, long heapLimit, long offHeapLimit, float memtableCleanupThreshold, MemtableCleaner cleaner) voiddiscard()This memtable is no longer in use or required for outstanding flushes or operations.Finds the largest memtable, as a percentage of *either* on- or off-heap memory limits, and immediately queues it for flushing.voidCalled when the known ranges have been updated and owner.localRangeSplits() may return different values.voidmarkExtraOffHeapUsed(long additionalSpace, OpOrder.Group opGroup) Adjust the used off-heap space by the given size (e.g.voidmarkExtraOnHeapUsed(long additionalSpace, OpOrder.Group opGroup) Adjust the used on-heap space by the given size (e.g.voidCalled when the table's metadata is updated.voidperformSnapshot(String snapshotName) If the memtable needs to do some special action for snapshots (e.g.booleanDecides whether the memtable should be switched/flushed for the passed reason.voidswitchOut(OpOrder.Barrier writeBarrier, AtomicReference<CommitLogPosition> commitLogUpperBound) Called to tell the memtable that it is being switched out and will be flushed (or dropped) and discarded.toString()Methods inherited from class org.apache.cassandra.db.memtable.AbstractMemtableWithCommitlog
accepts, getApproximateCommitLogLowerBound, getCommitLogLowerBound, getFinalCommitLogUpperBound, mayContainDataBeforeMethods inherited from class org.apache.cassandra.db.memtable.AbstractMemtable
getFlushTransaction, getMinLocalDeletionTime, getMinTimestamp, metadata, operationCount, setFlushTransaction, updateMin, updateMinMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.cassandra.db.CellSourceIdentifier
isEqualSourceMethods inherited from interface org.apache.cassandra.db.memtable.Memtable
compareTo, getFlushSet, getLiveDataSize, isClean, partitionCount, putMethods inherited from interface org.apache.cassandra.db.rows.UnfilteredSource
partitionIterator, rowIterator, rowIterator
-
Field Details
-
MEMORY_POOL
-
owner
-
allocator
-
initialComparator
-
initialFactory
-
-
Constructor Details
-
AbstractAllocatorMemtable
public AbstractAllocatorMemtable(AtomicReference<CommitLogPosition> commitLogLowerBound, TableMetadataRef metadataRef, Memtable.Owner owner)
-
-
Method Details
-
createMemtableAllocatorPoolInternal
public static MemtablePool createMemtableAllocatorPoolInternal(Config.MemtableAllocationType allocationType, long heapLimit, long offHeapLimit, float memtableCleanupThreshold, MemtableCleaner cleaner) -
getAllocator
-
shouldSwitch
Description copied from interface:MemtableDecides whether the memtable should be switched/flushed for the passed reason. Normally this will return true, but e.g. persistent memtables may choose not to flush. Returning false will trigger further action for some reasons: - SCHEMA_CHANGE will be followed by metadataUpdated(). - OWNED_RANGES_CHANGE will be followed by localRangesUpdated(). - SNAPSHOT will be followed by performSnapshot(). - STREAMING/REPAIR will be followed by creating a FlushSet for the streamed/repaired ranges. This data will be used to create sstables, which will be streamed and then deleted. This will not be called to perform truncation or drop (in that case the memtable is unconditionally dropped), but a flush may nevertheless be requested in that case to prepare a snapshot. -
metadataUpdated
public void metadataUpdated()Description copied from interface:MemtableCalled when the table's metadata is updated. The memtable's metadata reference now points to the new version. This will not be called ifMemtable.shouldSwitch(org.apache.cassandra.db.ColumnFamilyStore.FlushReason)(SCHEMA_CHANGE) returns true, as the memtable will be swapped out instead. -
localRangesUpdated
public void localRangesUpdated()Description copied from interface:MemtableCalled when the known ranges have been updated and owner.localRangeSplits() may return different values. This will not be called ifMemtable.shouldSwitch(org.apache.cassandra.db.ColumnFamilyStore.FlushReason)(OWNED_RANGES_CHANGE) returns true, as the memtable will be swapped out instead. -
performSnapshot
Description copied from interface:MemtableIf the memtable needs to do some special action for snapshots (e.g. because it is persistent and does not want to flush), it should return false on the above with reason SNAPSHOT and implement this method. -
switchOut
public void switchOut(OpOrder.Barrier writeBarrier, AtomicReference<CommitLogPosition> commitLogUpperBound) Description copied from interface:MemtableCalled to tell the memtable that it is being switched out and will be flushed (or dropped) and discarded. Will be followed by aMemtable.getFlushSet(org.apache.cassandra.db.PartitionPosition, org.apache.cassandra.db.PartitionPosition)call (if the table is not truncated or dropped), and aMemtable.discard().- Specified by:
switchOutin interfaceMemtable- Overrides:
switchOutin classAbstractMemtableWithCommitlog- Parameters:
writeBarrier- The barrier that will signal that all writes to this memtable have completed. That is, the point after which writes cannot be accepted by this memtable (it is permitted for writes before this barrier to go into the next; seeMemtable.accepts(org.apache.cassandra.utils.concurrent.OpOrder.Group, org.apache.cassandra.db.commitlog.CommitLogPosition)).commitLogUpperBound- The upper commit log position for this memtable. The value may be modified after this call and will match the next memtable's lower commit log bound.
-
discard
public void discard()Description copied from interface:MemtableThis memtable is no longer in use or required for outstanding flushes or operations. All held memory must be released.- Specified by:
discardin interfaceMemtable- Overrides:
discardin classAbstractMemtableWithCommitlog
-
toString
-
addMemoryUsageTo
Description copied from interface:MemtableAdd this memtable's used memory to the given usage object. This can be used to retrieve a single memtable's usage as well as to combine the ones of related sstables (e.g. a table and its table-based secondary indexes). -
markExtraOnHeapUsed
Description copied from interface:MemtableAdjust the used on-heap space by the given size (e.g. to reflect memory used by a non-table-based index). This operation may block until enough memory is available in the memory pool.- Parameters:
additionalSpace- the number of allocated bytesopGroup- write operation group, used to permit the operation to complete if it is needed to complete a flush to free space.
-
markExtraOffHeapUsed
Description copied from interface:MemtableAdjust the used off-heap space by the given size (e.g. to reflect memory used by a non-table-based index). This operation may block until enough memory is available in the memory pool.- Parameters:
additionalSpace- the number of allocated bytesopGroup- write operation group, used to permit the operation to complete if it is needed to complete a flush to free space.
-
flushLargestMemtable
Finds the largest memtable, as a percentage of *either* on- or off-heap memory limits, and immediately queues it for flushing. If the memtable selected is flushed before this completes, no work is done.
-