Class EntryMemTable

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Direct Known Subclasses:
    EntryMemTableWithParallelFlusher

    public class EntryMemTable
    extends java.lang.Object
    implements java.lang.AutoCloseable
    The EntryMemTable holds in-memory representation to the entries not-yet flushed. When asked to flush, current EntrySkipList is moved to snapshot and is cleared. We continue to serve edits out of new EntrySkipList and backing snapshot until flusher reports in that the flush succeeded. At that point we let the snapshot go.
    • Method Detail

      • dump

        void dump()
      • snapshot

        CheckpointSource.Checkpoint snapshot​(CheckpointSource.Checkpoint oldCp)
                                      throws java.io.IOException
        Snapshot current EntryMemTable. if given oldCp is older than current checkpoint, we don't do any snapshot. If snapshot happened, we return the checkpoint of the snapshot.
        Parameters:
        oldCp - checkpoint
        Returns:
        checkpoint of the snapshot, null means no snapshot
        Throws:
        java.io.IOException
      • flush

        long flush​(SkipListFlusher flusher)
            throws java.io.IOException
        Flush snapshot and clear it.
        Throws:
        java.io.IOException
      • flush

        public long flush​(SkipListFlusher flusher,
                          CheckpointSource.Checkpoint checkpoint)
                   throws java.io.IOException
        Flush memtable until checkpoint.
        Parameters:
        checkpoint - all data before this checkpoint need to be flushed.
        Throws:
        java.io.IOException
      • flushSnapshot

        long flushSnapshot​(SkipListFlusher flusher,
                           CheckpointSource.Checkpoint checkpoint)
                    throws java.io.IOException
        Flush snapshot and clear it iff its data is before checkpoint. Only this function change non-empty this.snapshot.

        EntryMemTableWithParallelFlusher overrides this flushSnapshot method. So any change in functionality/behavior/characteristic of this method should also reflect in EntryMemTableWithParallelFlusher's flushSnapshot method.

        Throws:
        java.io.IOException
      • clearSnapshot

        void clearSnapshot​(EntryMemTable.EntrySkipList keyValues)
        The passed snapshot was successfully persisted; it can be let go.
        Parameters:
        keyValues - The snapshot to clean out.
      • addEntry

        public long addEntry​(long ledgerId,
                             long entryId,
                             java.nio.ByteBuffer entry,
                             CacheCallback cb)
                      throws java.io.IOException
        Write an update.
        Parameters:
        entry -
        Returns:
        approximate size of the passed key and value.
        Throws:
        java.io.IOException
      • getEntry

        public EntryKeyValue getEntry​(long ledgerId,
                                      long entryId)
                               throws java.io.IOException
        Find the entry with given key.
        Parameters:
        ledgerId -
        entryId -
        Returns:
        the entry kv or null if none found.
        Throws:
        java.io.IOException
      • getLastEntry

        public EntryKeyValue getLastEntry​(long ledgerId)
                                   throws java.io.IOException
        Find the last entry with the given ledger key.
        Parameters:
        ledgerId -
        Returns:
        the entry kv or null if none found.
        Throws:
        java.io.IOException
      • isSizeLimitReached

        boolean isSizeLimitReached()
        Check if the entire heap usage for this EntryMemTable exceeds limit.
      • isEmpty

        boolean isEmpty()
        Check if there is data in the mem-table.
        Returns:
      • close

        public void close()
                   throws java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • getListOfEntriesOfLedger

        java.util.PrimitiveIterator.OfLong getListOfEntriesOfLedger​(long ledgerId)