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.AutoCloseable
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 Classes Modifier and Type Class Description (package private) static class
EntryMemTable.EntrySkipList
Entry skip list.
-
Field Summary
Fields Modifier and Type Field Description (package private) SkipListArena
allocator
(package private) CheckpointSource
checkpointSource
(package private) ServerConfiguration
conf
(package private) EntryMemTable.EntrySkipList
kvmap
(package private) java.util.concurrent.locks.ReentrantReadWriteLock
lock
protected EntryMemTableStats
memTableStats
(package private) java.util.concurrent.atomic.AtomicLong
size
(package private) java.util.concurrent.Semaphore
skipListSemaphore
(package private) long
skipListSizeLimit
(package private) EntryMemTable.EntrySkipList
snapshot
-
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 long
addEntry(long ledgerId, long entryId, java.nio.ByteBuffer entry, CacheCallback cb)
Write an update.(package private) void
clearSnapshot(EntryMemTable.EntrySkipList keyValues)
The passed snapshot was successfully persisted; it can be let go.void
close()
(package private) void
dump()
(package private) long
flush(SkipListFlusher flusher)
Flush snapshot and clear it.long
flush(SkipListFlusher flusher, CheckpointSource.Checkpoint checkpoint)
Flush memtable until checkpoint.(package private) long
flushSnapshot(SkipListFlusher flusher, CheckpointSource.Checkpoint checkpoint)
Flush snapshot and clear it iff its data is before checkpoint.EntryKeyValue
getEntry(long ledgerId, long entryId)
Find the entry with given key.EntryKeyValue
getLastEntry(long ledgerId)
Find the last entry with the given ledger key.(package private) java.util.PrimitiveIterator.OfLong
getListOfEntriesOfLedger(long ledgerId)
(package private) boolean
isEmpty()
Check if there is data in the mem-table.(package private) boolean
isSizeLimitReached()
Check if the entire heap usage for this EntryMemTable exceeds limit.(package private) CheckpointSource.Checkpoint
snapshot()
(package private) CheckpointSource.Checkpoint
snapshot(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.IOException
Write 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:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
getListOfEntriesOfLedger
java.util.PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId)
-
-