Class EntryCacheImpl

  • All Implemented Interfaces:
    java.lang.Comparable<EntryCache>, EntryCache

    public class EntryCacheImpl
    extends java.lang.Object
    implements EntryCache
    Cache data payload for entries of all ledgers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static io.netty.buffer.PooledByteBufAllocator ALLOCATOR  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void asyncReadEntry​(org.apache.bookkeeper.client.api.ReadHandle lh, long firstEntry, long lastEntry, boolean isSlowestReader, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx)
      Read entries from the cache or from bookkeeper.
      void asyncReadEntry​(org.apache.bookkeeper.client.api.ReadHandle lh, PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, java.lang.Object ctx)
      Read entry at given position from the cache or from bookkeeper.
      void clear()
      Remove all the entries from the cache.
      int compareTo​(EntryCache other)  
      org.apache.commons.lang3.tuple.Pair<java.lang.Integer,​java.lang.Long> evictEntries​(long sizeToFree)
      Force the cache to drop entries to free space.
      java.lang.String getName()  
      long getSize()
      Get the total size in bytes of all the entries stored in this cache.
      boolean insert​(EntryImpl entry)
      Insert an entry in the cache.
      void invalidateAllEntries​(long ledgerId)
      Remove from the cache all the entries belonging to a specific ledger.
      void invalidateEntries​(PositionImpl lastPosition)
      Remove from cache all the entries related to a ledger up to lastPosition included.
      void invalidateEntriesBeforeTimestamp​(long timestamp)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ALLOCATOR

        public static final io.netty.buffer.PooledByteBufAllocator ALLOCATOR
    • Method Detail

      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface EntryCache
        Returns:
        the name of the cache
      • insert

        public boolean insert​(EntryImpl entry)
        Description copied from interface: EntryCache
        Insert an entry in the cache.

        If the overall limit have been reached, this will triggered the eviction of other entries, possibly from other EntryCache instances

        Specified by:
        insert in interface EntryCache
        Parameters:
        entry - the entry to be cached
        Returns:
        whether the entry was inserted in cache
      • invalidateEntries

        public void invalidateEntries​(PositionImpl lastPosition)
        Description copied from interface: EntryCache
        Remove from cache all the entries related to a ledger up to lastPosition included.
        Specified by:
        invalidateEntries in interface EntryCache
        Parameters:
        lastPosition - the position of the last entry to be invalidated (non-inclusive)
      • invalidateAllEntries

        public void invalidateAllEntries​(long ledgerId)
        Description copied from interface: EntryCache
        Remove from the cache all the entries belonging to a specific ledger.
        Specified by:
        invalidateAllEntries in interface EntryCache
        Parameters:
        ledgerId - the ledger id
      • asyncReadEntry

        public void asyncReadEntry​(org.apache.bookkeeper.client.api.ReadHandle lh,
                                   PositionImpl position,
                                   AsyncCallbacks.ReadEntryCallback callback,
                                   java.lang.Object ctx)
        Description copied from interface: EntryCache
        Read entry at given position from the cache or from bookkeeper.

        Get the entry data either from cache or bookkeeper and mixes up the results in a single list.

        Specified by:
        asyncReadEntry in interface EntryCache
        Parameters:
        lh - the ledger handle
        position - position to read the entry from
        callback - the callback object that will be notified when read is done
        ctx - the context object
      • asyncReadEntry

        public void asyncReadEntry​(org.apache.bookkeeper.client.api.ReadHandle lh,
                                   long firstEntry,
                                   long lastEntry,
                                   boolean isSlowestReader,
                                   AsyncCallbacks.ReadEntriesCallback callback,
                                   java.lang.Object ctx)
        Description copied from interface: EntryCache
        Read entries from the cache or from bookkeeper.

        Get the entry data either from cache or bookkeeper and mixes up the results in a single list.

        Specified by:
        asyncReadEntry in interface EntryCache
        Parameters:
        lh - the ledger handle
        firstEntry - the first entry to read (inclusive)
        lastEntry - the last entry to read (inclusive)
        isSlowestReader - whether the reader cursor is the most far behind in the stream
        callback - the callback object that will be notified when read is done
        ctx - the context object
      • clear

        public void clear()
        Description copied from interface: EntryCache
        Remove all the entries from the cache.
        Specified by:
        clear in interface EntryCache
      • getSize

        public long getSize()
        Description copied from interface: EntryCache
        Get the total size in bytes of all the entries stored in this cache.
        Specified by:
        getSize in interface EntryCache
        Returns:
        the size of the entry cache
      • compareTo

        public int compareTo​(EntryCache other)
        Specified by:
        compareTo in interface java.lang.Comparable<EntryCache>
      • evictEntries

        public org.apache.commons.lang3.tuple.Pair<java.lang.Integer,​java.lang.Long> evictEntries​(long sizeToFree)
        Description copied from interface: EntryCache
        Force the cache to drop entries to free space.
        Specified by:
        evictEntries in interface EntryCache
        Parameters:
        sizeToFree - the total memory size to free
        Returns:
        a pair containing the number of entries evicted and their total size