Package org.apache.bookkeeper.bookie
Class EntryMemTable
java.lang.Object
org.apache.bookkeeper.bookie.EntryMemTable
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
EntryMemTableWithParallelFlusher
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classEntry skip list. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) SkipListArena(package private) final CheckpointSource(package private) final ServerConfiguration(package private) EntryMemTable.EntrySkipList(package private) final ReentrantReadWriteLockprotected final EntryMemTableStats(package private) final AtomicLong(package private) final Semaphore(package private) final long(package private) EntryMemTable.EntrySkipList -
Constructor Summary
ConstructorsConstructorDescriptionEntryMemTable(ServerConfiguration conf, CheckpointSource source, StatsLogger statsLogger) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionlongaddEntry(long ledgerId, long entryId, ByteBuffer entry, CacheCallback cb) Write an update.(package private) voidclearSnapshot(EntryMemTable.EntrySkipList keyValues) The passed snapshot was successfully persisted; it can be let go.voidclose()(package private) voiddump()(package private) longflush(SkipListFlusher flusher) Flush snapshot and clear it.longflush(SkipListFlusher flusher, CheckpointSource.Checkpoint checkpoint) Flush memtable until checkpoint.(package private) longflushSnapshot(SkipListFlusher flusher, CheckpointSource.Checkpoint checkpoint) Flush snapshot and clear it iff its data is before checkpoint.getEntry(long ledgerId, long entryId) Find the entry with given key.getLastEntry(long ledgerId) Find the last entry with the given ledger key.(package private) PrimitiveIterator.OfLonggetListOfEntriesOfLedger(long ledgerId) (package private) booleanisEmpty()Check if there is data in the mem-table.(package private) booleanCheck if the entire heap usage for this EntryMemTable exceeds limit.(package private) CheckpointSource.Checkpointsnapshot()(package private) CheckpointSource.CheckpointSnapshot current EntryMemTable.
-
Field Details
-
kvmap
-
snapshot
-
conf
-
checkpointSource
-
lock
-
size
-
skipListSizeLimit
final long skipListSizeLimit -
skipListSemaphore
-
allocator
SkipListArena allocator -
memTableStats
-
-
Constructor Details
-
EntryMemTable
Constructor.- Parameters:
conf- Server configuration
-
-
Method Details
-
dump
void dump() -
snapshot
- Throws:
IOException
-
snapshot
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:
IOException
-
flush
Flush snapshot and clear it.- Throws:
IOException
-
flush
public long flush(SkipListFlusher flusher, CheckpointSource.Checkpoint checkpoint) throws IOException Flush memtable until checkpoint.- Parameters:
checkpoint- all data before this checkpoint need to be flushed.- Throws:
IOException
-
flushSnapshot
long flushSnapshot(SkipListFlusher flusher, CheckpointSource.Checkpoint checkpoint) throws 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:
IOException
-
clearSnapshot
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, ByteBuffer entry, CacheCallback cb) throws IOException Write an update.- Parameters:
entry-- Returns:
- approximate size of the passed key and value.
- Throws:
IOException
-
getEntry
Find the entry with given key.- Parameters:
ledgerId-entryId-- Returns:
- the entry kv or null if none found.
- Throws:
IOException
-
getLastEntry
Find the last entry with the given ledger key.- Parameters:
ledgerId-- Returns:
- the entry kv or null if none found.
- Throws:
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
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
getListOfEntriesOfLedger
-