Class AbstractAllocatorMemtable

All Implemented Interfaces:
Comparable<Memtable>, CellSourceIdentifier, 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.
  • Field Details

  • Constructor Details

  • Method Details

    • 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 if Memtable.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 if Memtable.shouldSwitch(org.apache.cassandra.db.ColumnFamilyStore.FlushReason) (OWNED_RANGES_CHANGE) returns true, as the memtable will be swapped out instead.
    • performSnapshot

      public void performSnapshot(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, 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 a Memtable.getFlushSet(org.apache.cassandra.db.PartitionPosition, org.apache.cassandra.db.PartitionPosition) call (if the table is not truncated or dropped), and a Memtable.discard().
      Specified by:
      switchOut in interface Memtable
      Overrides:
      switchOut in class AbstractMemtableWithCommitlog
      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; see Memtable.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 interface Memtable
      Overrides:
      discard in class AbstractMemtableWithCommitlog
    • toString

      public String toString()
      Overrides:
      toString in class 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 bytes
      opGroup - 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 bytes
      opGroup - 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<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.