Package org.apache.bookkeeper.bookie
Class EntryMemTable
- java.lang.Object
-
- org.apache.bookkeeper.bookie.EntryMemTable
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
EntryMemTableWithParallelFlusher
public class EntryMemTable extends java.lang.Object implements java.lang.AutoCloseableThe 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 Classes Modifier and Type Class Description (package private) static classEntryMemTable.EntrySkipListEntry skip list.
-
Field Summary
Fields Modifier and Type Field Description (package private) SkipListArenaallocator(package private) CheckpointSourcecheckpointSource(package private) ServerConfigurationconf(package private) EntryMemTable.EntrySkipListkvmap(package private) java.util.concurrent.locks.ReentrantReadWriteLocklockprotected EntryMemTableStatsmemTableStats(package private) java.util.concurrent.atomic.AtomicLongsize(package private) java.util.concurrent.SemaphoreskipListSemaphore(package private) longskipListSizeLimit(package private) EntryMemTable.EntrySkipListsnapshot
-
Constructor Summary
Constructors Constructor Description EntryMemTable(ServerConfiguration conf, CheckpointSource source, StatsLogger statsLogger)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddEntry(long ledgerId, long entryId, java.nio.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.EntryKeyValuegetEntry(long ledgerId, long entryId)Find the entry with given key.EntryKeyValuegetLastEntry(long ledgerId)Find the last entry with the given ledger key.(package private) java.util.PrimitiveIterator.OfLonggetListOfEntriesOfLedger(long ledgerId)(package private) booleanisEmpty()Check if there is data in the mem-table.(package private) booleanisSizeLimitReached()Check if the entire heap usage for this EntryMemTable exceeds limit.(package private) CheckpointSource.Checkpointsnapshot()(package private) CheckpointSource.Checkpointsnapshot(CheckpointSource.Checkpoint oldCp)Snapshot current EntryMemTable.
-
-
-
Field Detail
-
kvmap
volatile EntryMemTable.EntrySkipList kvmap
-
snapshot
volatile EntryMemTable.EntrySkipList snapshot
-
conf
final ServerConfiguration conf
-
checkpointSource
final CheckpointSource checkpointSource
-
lock
final java.util.concurrent.locks.ReentrantReadWriteLock lock
-
size
final java.util.concurrent.atomic.AtomicLong size
-
skipListSizeLimit
final long skipListSizeLimit
-
skipListSemaphore
final java.util.concurrent.Semaphore skipListSemaphore
-
allocator
SkipListArena allocator
-
memTableStats
protected final EntryMemTableStats memTableStats
-
-
Constructor Detail
-
EntryMemTable
public EntryMemTable(ServerConfiguration conf, CheckpointSource source, StatsLogger statsLogger)
Constructor.- Parameters:
conf- Server configuration
-
-
Method Detail
-
dump
void dump()
-
snapshot
CheckpointSource.Checkpoint snapshot() throws java.io.IOException
- Throws:
java.io.IOException
-
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.IOExceptionWrite 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:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.Exception
-
getListOfEntriesOfLedger
java.util.PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId)
-
-