Class EntryCacheImpl
- java.lang.Object
-
- org.apache.bookkeeper.mledger.impl.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.PooledByteBufAllocatorALLOCATOR
-
Constructor Summary
Constructors Constructor Description EntryCacheImpl(EntryCacheManager manager, ManagedLedgerImpl ml, boolean copyEntries)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidasyncReadEntry(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.voidasyncReadEntry(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.voidclear()Remove all the entries from the cache.intcompareTo(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.StringgetName()longgetSize()Get the total size in bytes of all the entries stored in this cache.booleaninsert(EntryImpl entry)Insert an entry in the cache.voidinvalidateAllEntries(long ledgerId)Remove from the cache all the entries belonging to a specific ledger.voidinvalidateEntries(PositionImpl lastPosition)Remove from cache all the entries related to a ledger up to lastPosition included.voidinvalidateEntriesBeforeTimestamp(long timestamp)
-
-
-
Constructor Detail
-
EntryCacheImpl
public EntryCacheImpl(EntryCacheManager manager, ManagedLedgerImpl ml, boolean copyEntries)
-
-
Method Detail
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceEntryCache- Returns:
- the name of the cache
-
insert
public boolean insert(EntryImpl entry)
Description copied from interface:EntryCacheInsert 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:
insertin interfaceEntryCache- 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:EntryCacheRemove from cache all the entries related to a ledger up to lastPosition included.- Specified by:
invalidateEntriesin interfaceEntryCache- Parameters:
lastPosition- the position of the last entry to be invalidated (non-inclusive)
-
invalidateAllEntries
public void invalidateAllEntries(long ledgerId)
Description copied from interface:EntryCacheRemove from the cache all the entries belonging to a specific ledger.- Specified by:
invalidateAllEntriesin interfaceEntryCache- 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:EntryCacheRead 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:
asyncReadEntryin interfaceEntryCache- Parameters:
lh- the ledger handleposition- position to read the entry fromcallback- the callback object that will be notified when read is donectx- 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:EntryCacheRead 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:
asyncReadEntryin interfaceEntryCache- Parameters:
lh- the ledger handlefirstEntry- 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 streamcallback- the callback object that will be notified when read is donectx- the context object
-
clear
public void clear()
Description copied from interface:EntryCacheRemove all the entries from the cache.- Specified by:
clearin interfaceEntryCache
-
getSize
public long getSize()
Description copied from interface:EntryCacheGet the total size in bytes of all the entries stored in this cache.- Specified by:
getSizein interfaceEntryCache- Returns:
- the size of the entry cache
-
compareTo
public int compareTo(EntryCache other)
- Specified by:
compareToin interfacejava.lang.Comparable<EntryCache>
-
evictEntries
public org.apache.commons.lang3.tuple.Pair<java.lang.Integer,java.lang.Long> evictEntries(long sizeToFree)
Description copied from interface:EntryCacheForce the cache to drop entries to free space.- Specified by:
evictEntriesin interfaceEntryCache- Parameters:
sizeToFree- the total memory size to free- Returns:
- a pair containing the number of entries evicted and their total size
-
invalidateEntriesBeforeTimestamp
public void invalidateEntriesBeforeTimestamp(long timestamp)
- Specified by:
invalidateEntriesBeforeTimestampin interfaceEntryCache
-
-