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:
java.lang.Comparable<Memtable>,Memtable,UnfilteredSource
- Direct Known Subclasses:
ShardedSkipListMemtable,SkipListMemtable
public abstract class AbstractAllocatorMemtable extends AbstractMemtableWithCommitlog
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.StatsCollector
-
Nested 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
Fields Modifier and Type Field Description protected MemtableAllocatorallocatorprotected ClusteringComparatorinitialComparatorstatic MemtablePoolMEMORY_POOLprotected Memtable.Ownerowner-
Fields inherited from class org.apache.cassandra.db.memtable.AbstractMemtable
columnsCollector, currentOperations, metadata, minLocalDeletionTime, minTimestamp, statsCollector
-
Fields inherited from interface org.apache.cassandra.db.memtable.Memtable
NO_MIN_TIMESTAMP
-
-
Constructor Summary
Constructors Constructor Description AbstractAllocatorMemtable(java.util.concurrent.atomic.AtomicReference<CommitLogPosition> commitLogLowerBound, TableMetadataRef metadataRef, Memtable.Owner owner)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddMemoryUsageTo(Memtable.MemoryUsage stats)Add 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.protected abstract Memtable.Factoryfactory()static Future<java.lang.Boolean>flushLargestMemtable()Finds the largest memtable, as a percentage of *either* on- or off-heap memory limits, and immediately queues it for flushing.MemtableAllocatorgetAllocator()voidlocalRangesUpdated()Called 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.voidmetadataUpdated()Called when the table's metadata is updated.voidperformSnapshot(java.lang.String snapshotName)If the memtable needs to do some special action for snapshots (e.g.booleanshouldSwitch(ColumnFamilyStore.FlushReason reason)Decides whether the memtable should be switched/flushed for the passed reason.voidswitchOut(OpOrder.Barrier writeBarrier, java.util.concurrent.atomic.AtomicReference<CommitLogPosition> commitLogUpperBound)Called to tell the memtable that it is being switched out and will be flushed (or dropped) and discarded.java.lang.StringtoString()-
Methods inherited from class org.apache.cassandra.db.memtable.AbstractMemtableWithCommitlog
accepts, getApproximateCommitLogLowerBound, getCommitLogLowerBound, getFinalCommitLogUpperBound, mayContainDataBefore
-
Methods inherited from class org.apache.cassandra.db.memtable.AbstractMemtable
getMinLocalDeletionTime, getMinTimestamp, metadata, operationCount, updateMin, updateMin
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.db.memtable.Memtable
compareTo, getFlushSet, getLiveDataSize, isClean, partitionCount, put
-
Methods inherited from interface org.apache.cassandra.db.rows.UnfilteredSource
partitionIterator, rowIterator, rowIterator
-
-
-
-
Field Detail
-
MEMORY_POOL
public static final MemtablePool MEMORY_POOL
-
owner
protected final Memtable.Owner owner
-
allocator
protected final MemtableAllocator allocator
-
initialComparator
protected final ClusteringComparator initialComparator
-
-
Constructor Detail
-
AbstractAllocatorMemtable
public AbstractAllocatorMemtable(java.util.concurrent.atomic.AtomicReference<CommitLogPosition> commitLogLowerBound, TableMetadataRef metadataRef, Memtable.Owner owner)
-
-
Method Detail
-
createMemtableAllocatorPoolInternal
public static MemtablePool createMemtableAllocatorPoolInternal(Config.MemtableAllocationType allocationType, long heapLimit, long offHeapLimit, float memtableCleanupThreshold, MemtableCleaner cleaner)
-
getAllocator
public MemtableAllocator getAllocator()
-
shouldSwitch
public boolean shouldSwitch(ColumnFamilyStore.FlushReason reason)
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 if {@link #shouldSwitch)(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 if {@link #shouldSwitch)(OWNED_RANGES_CHANGE) returns true, as the memtable will be swapped out instead.
-
performSnapshot
public void performSnapshot(java.lang.String snapshotName)
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.
-
factory
protected abstract Memtable.Factory factory()
-
switchOut
public void switchOut(OpOrder.Barrier writeBarrier, java.util.concurrent.atomic.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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
addMemoryUsageTo
public void addMemoryUsageTo(Memtable.MemoryUsage stats)
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
public void markExtraOnHeapUsed(long additionalSpace, OpOrder.Group opGroup)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
public void markExtraOffHeapUsed(long additionalSpace, OpOrder.Group opGroup)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
public static Future<java.lang.Boolean> 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.
-
-