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:
AbstractShardedMemtable
,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 MemtableAllocator
allocator
protected ClusteringComparator
initialComparator
Memtable.Factory
initialFactory
static MemtablePool
MEMORY_POOL
protected Memtable.Owner
owner
-
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 Concrete Methods Modifier and Type Method Description void
addMemoryUsageTo(Memtable.MemoryUsage stats)
Add this memtable's used memory to the given usage object.static MemtablePool
createMemtableAllocatorPoolInternal(Config.MemtableAllocationType allocationType, long heapLimit, long offHeapLimit, float memtableCleanupThreshold, MemtableCleaner cleaner)
void
discard()
This memtable is no longer in use or required for outstanding flushes or operations.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.MemtableAllocator
getAllocator()
void
localRangesUpdated()
Called when the known ranges have been updated and owner.localRangeSplits() may return different values.void
markExtraOffHeapUsed(long additionalSpace, OpOrder.Group opGroup)
Adjust the used off-heap space by the given size (e.g.void
markExtraOnHeapUsed(long additionalSpace, OpOrder.Group opGroup)
Adjust the used on-heap space by the given size (e.g.void
metadataUpdated()
Called when the table's metadata is updated.void
performSnapshot(java.lang.String snapshotName)
If the memtable needs to do some special action for snapshots (e.g.boolean
shouldSwitch(ColumnFamilyStore.FlushReason reason)
Decides whether the memtable should be switched/flushed for the passed reason.void
switchOut(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.String
toString()
-
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
getFlushTransaction, getMinLocalDeletionTime, getMinTimestamp, metadata, operationCount, setFlushTransaction, 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
-
initialFactory
public final Memtable.Factory initialFactory
-
-
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:Memtable
Decides 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:Memtable
Called 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:Memtable
Called 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
public void performSnapshot(java.lang.String snapshotName)
Description copied from interface:Memtable
If 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, java.util.concurrent.atomic.AtomicReference<CommitLogPosition> commitLogUpperBound)
Description copied from interface:Memtable
Called 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:
switchOut
in interfaceMemtable
- Overrides:
switchOut
in 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:Memtable
This memtable is no longer in use or required for outstanding flushes or operations. All held memory must be released.- Specified by:
discard
in interfaceMemtable
- Overrides:
discard
in classAbstractMemtableWithCommitlog
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
addMemoryUsageTo
public void addMemoryUsageTo(Memtable.MemoryUsage stats)
Description copied from interface:Memtable
Add 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:Memtable
Adjust 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:Memtable
Adjust 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.
-
-