Interface EntryCache

  • All Superinterfaces:
    java.lang.Comparable<EntryCache>
    All Known Implementing Classes:
    EntryCacheImpl, EntryCacheManager.EntryCacheDisabled

    public interface EntryCache
    extends java.lang.Comparable<EntryCache>
    Cache of entries used by a single ManagedLedger. An EntryCache is compared to other EntryCache instances using their size (the memory that is occupied by each of them).
    • Method Summary

      All Methods Instance Methods Abstract 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.
      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 interface java.lang.Comparable

        compareTo
    • Method Detail

      • getName

        java.lang.String getName()
        Returns:
        the name of the cache
      • insert

        boolean insert​(EntryImpl entry)
        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

        Parameters:
        entry - the entry to be cached
        Returns:
        whether the entry was inserted in cache
      • invalidateEntries

        void invalidateEntries​(PositionImpl lastPosition)
        Remove from cache all the entries related to a ledger up to lastPosition included.
        Parameters:
        lastPosition - the position of the last entry to be invalidated (non-inclusive)
      • invalidateEntriesBeforeTimestamp

        void invalidateEntriesBeforeTimestamp​(long timestamp)
      • invalidateAllEntries

        void invalidateAllEntries​(long ledgerId)
        Remove from the cache all the entries belonging to a specific ledger.
        Parameters:
        ledgerId - the ledger id
      • clear

        void clear()
        Remove all the entries from the cache.
      • evictEntries

        org.apache.commons.lang3.tuple.Pair<java.lang.Integer,​java.lang.Long> evictEntries​(long sizeToFree)
        Force the cache to drop entries to free space.
        Parameters:
        sizeToFree - the total memory size to free
        Returns:
        a pair containing the number of entries evicted and their total size
      • asyncReadEntry

        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.

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

        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
      • asyncReadEntry

        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.

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

        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
      • getSize

        long getSize()
        Get the total size in bytes of all the entries stored in this cache.
        Returns:
        the size of the entry cache