Package org.apache.bookkeeper.bookie
Class InterleavedLedgerStorage
java.lang.Object
org.apache.bookkeeper.bookie.InterleavedLedgerStorage
- All Implemented Interfaces:
CompactableLedgerStorage,DefaultEntryLogger.EntryLogListener,LedgerStorage
@StatsDoc(name="bookie",
category="server",
help="Bookie related stats")
public class InterleavedLedgerStorage
extends Object
implements CompactableLedgerStorage, DefaultEntryLogger.EntryLogListener
Interleave ledger storage.
This ledger storage implementation stores all entries in a single file and maintains an index file for each ledger.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.LedgerStorage
LedgerStorage.DetectedInconsistency, LedgerStorage.LedgerDeletionListener, LedgerStorage.StorageState -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final SnapshotMap<Long,Boolean> protected Checkpointerprotected CheckpointSource(package private) DefaultEntryLogger(package private) GarbageCollectorThread(package private) LedgerCache -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongaddEntry(io.netty.buffer.ByteBuf entry) Add an entry to the storage.voidcancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) Cancel a previous wait for last add confirmed update.voidcheckpoint(CheckpointSource.Checkpoint checkpoint) Ask the ledger storage to sync data until the given checkpoint.voidclearLimboState(long ledgerId) Clear the limbo state of a ledger.voidClear a storage state flag for the storage instance.voiddeleteLedger(long ledgerId) booleanentryExists(long ledgerId, long entryId) Whether an entry exists.voidflush()Flushes all data in the storage.voidFlush the entries locations index for the compacted entries.voidforceGC()Force trigger Garbage Collection.voidforceGC(boolean forceMajor, boolean forceMinor) Force trigger Garbage Collection with forceMajor or forceMinor parameter.getActiveLedgersInRange(long firstLedgerId, long lastLedgerId) Get an iterator over a range of ledger ids stored in the bookie.io.netty.buffer.ByteBufgetEntry(long ledgerId, long entryId) Read an entry from storage.io.netty.buffer.ByteBufgetExplicitLac(long ledgerId) Get Garbage Collection status.getIndexEntries(long ledgerId) Return iterable for index entries for ledgerId.longgetLastAddConfirmed(long ledgerId) Get last add confirmed.getListOfEntriesOfLedger(long ledgerId) Returns the primitive long iterator for entries of the ledger, stored in this LedgerStorage.Get the storage state flags currently set for the storage instance.booleanhasLimboState(long ledgerId) Check whether a ledger is in limbo state.voidinitialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) Initialize the LedgerStorage implementation.voidinitializeWithEntryLogger(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, EntryLogger entryLogger, StatsLogger statsLogger) (package private) voidinitializeWithEntryLogListener(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, DefaultEntryLogger.EntryLogListener entryLogListener, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) booleanisFenced(long ledgerId) Check whether the ledger is fenced in ledger storage or not.booleanWhether force triggered Garbage Collection is running or not.booleanbooleanbooleanledgerExists(long ledgerId) Whether a ledger exists.localConsistencyCheck(Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter) Performs internal check of local storage logging any inconsistencies.voidRotate a new entry log to write.protected voidprocessEntry(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry) protected voidprocessEntry(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry, boolean rollLog) readLedgerIndexMetadata(long ledgerId) Read implementation metadata for index file.byte[]readMasterKey(long ledgerId) Get the master key for a ledger.voidRegister a listener for ledgers deletion notifications.voidvoidvoidsetCheckpointer(Checkpointer checkpointer) voidsetCheckpointSource(CheckpointSource checkpointSource) voidsetExplicitLac(long ledgerId, io.netty.buffer.ByteBuf lac) booleansetFenced(long ledgerId) Fenced the ledger id in ledger storage.voidsetLimboState(long ledgerId) Set a ledger to limbo state.voidsetMasterKey(long ledgerId, byte[] masterKey) Set the master key for a ledger.voidsetStateManager(StateManager stateManager) voidSet a storage state flag for the storage instance.voidshutdown()Cleanup and free any resources being used by the storage system.voidstart()Start any background threads belonging to the storage system.voidvoidvoidupdateEntriesLocations(Iterable<EntryLocation> locations) Update the location of several entries.booleanwaitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) Wait for last add confirmed update.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.bookkeeper.bookie.LedgerStorage
entryLocationCompact, entryLocationCompact, getEntryLocationDBPath, getUnderlyingLedgerStorage, isEntryLocationCompacting, isEntryLocationCompacting
-
Field Details
-
entryLogger
DefaultEntryLogger entryLogger -
ledgerCache
LedgerCache ledgerCache -
checkpointSource
-
checkpointer
-
activeLedgers
-
gcThread
GarbageCollectorThread gcThread
-
-
Constructor Details
-
InterleavedLedgerStorage
public InterleavedLedgerStorage()
-
-
Method Details
-
initialize
public void initialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) throws IOException Description copied from interface:LedgerStorageInitialize the LedgerStorage implementation.- Specified by:
initializein interfaceLedgerStorage- Throws:
IOException
-
initializeWithEntryLogListener
void initializeWithEntryLogListener(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, DefaultEntryLogger.EntryLogListener entryLogListener, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) throws IOException - Throws:
IOException
-
setStateManager
- Specified by:
setStateManagerin interfaceLedgerStorage
-
setCheckpointSource
- Specified by:
setCheckpointSourcein interfaceLedgerStorage
-
setCheckpointer
- Specified by:
setCheckpointerin interfaceLedgerStorage
-
initializeWithEntryLogger
public void initializeWithEntryLogger(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, EntryLogger entryLogger, StatsLogger statsLogger) throws IOException - Throws:
IOException
-
forceGC
public void forceGC()Description copied from interface:LedgerStorageForce trigger Garbage Collection.- Specified by:
forceGCin interfaceLedgerStorage
-
forceGC
public void forceGC(boolean forceMajor, boolean forceMinor) Description copied from interface:LedgerStorageForce trigger Garbage Collection with forceMajor or forceMinor parameter.- Specified by:
forceGCin interfaceLedgerStorage
-
isInForceGC
public boolean isInForceGC()Description copied from interface:LedgerStorageWhether force triggered Garbage Collection is running or not.- Specified by:
isInForceGCin interfaceLedgerStorage- Returns:
- true -- force triggered Garbage Collection is running, false -- force triggered Garbage Collection is not running
-
suspendMinorGC
public void suspendMinorGC()- Specified by:
suspendMinorGCin interfaceLedgerStorage
-
suspendMajorGC
public void suspendMajorGC()- Specified by:
suspendMajorGCin interfaceLedgerStorage
-
resumeMinorGC
public void resumeMinorGC()- Specified by:
resumeMinorGCin interfaceLedgerStorage
-
resumeMajorGC
public void resumeMajorGC()- Specified by:
resumeMajorGCin interfaceLedgerStorage
-
isMajorGcSuspended
public boolean isMajorGcSuspended()- Specified by:
isMajorGcSuspendedin interfaceLedgerStorage
-
isMinorGcSuspended
public boolean isMinorGcSuspended()- Specified by:
isMinorGcSuspendedin interfaceLedgerStorage
-
start
public void start()Description copied from interface:LedgerStorageStart any background threads belonging to the storage system. For example, garbage collection.- Specified by:
startin interfaceLedgerStorage
-
shutdown
Description copied from interface:LedgerStorageCleanup and free any resources being used by the storage system.- Specified by:
shutdownin interfaceLedgerStorage- Throws:
InterruptedException
-
setFenced
Description copied from interface:LedgerStorageFenced the ledger id in ledger storage.- Specified by:
setFencedin interfaceLedgerStorage- Parameters:
ledgerId- Ledger Id.- Throws:
IOException- when failed to fence the ledger.
-
isFenced
Description copied from interface:LedgerStorageCheck whether the ledger is fenced in ledger storage or not.- Specified by:
isFencedin interfaceLedgerStorage- Parameters:
ledgerId- Ledger ID.- Throws:
IOException
-
setExplicitLac
- Specified by:
setExplicitLacin interfaceLedgerStorage- Throws:
IOException
-
getExplicitLac
public io.netty.buffer.ByteBuf getExplicitLac(long ledgerId) - Specified by:
getExplicitLacin interfaceLedgerStorage
-
setMasterKey
Description copied from interface:LedgerStorageSet the master key for a ledger.- Specified by:
setMasterKeyin interfaceLedgerStorage- Throws:
IOException
-
readMasterKey
Description copied from interface:LedgerStorageGet the master key for a ledger.- Specified by:
readMasterKeyin interfaceLedgerStorage- Throws:
IOException- if there is an error reading the from the ledgerBookieException- if no such ledger exists
-
ledgerExists
Description copied from interface:LedgerStorageWhether a ledger exists.- Specified by:
ledgerExistsin interfaceLedgerStorage- Throws:
IOException
-
entryExists
Description copied from interface:LedgerStorageWhether an entry exists.- Specified by:
entryExistsin interfaceLedgerStorage- Throws:
IOException
-
getLastAddConfirmed
Description copied from interface:LedgerStorageGet last add confirmed.- Specified by:
getLastAddConfirmedin interfaceLedgerStorage- Parameters:
ledgerId- ledger id.- Returns:
- last add confirmed.
- Throws:
IOException
-
waitForLastAddConfirmedUpdate
public boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException Description copied from interface:LedgerStorageWait for last add confirmed update.- Specified by:
waitForLastAddConfirmedUpdatein interfaceLedgerStoragepreviousLAC- - The threshold beyond which we would wait for the updatewatcher- - Watcher to notify on update- Returns:
- Throws:
IOException
-
cancelWaitForLastAddConfirmedUpdate
public void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException Description copied from interface:LedgerStorageCancel a previous wait for last add confirmed update.- Specified by:
cancelWaitForLastAddConfirmedUpdatein interfaceLedgerStorage- Parameters:
ledgerId- The ledger being watched.watcher- The watcher to cancel.- Throws:
IOException
-
addEntry
Description copied from interface:LedgerStorageAdd an entry to the storage.- Specified by:
addEntryin interfaceLedgerStorage- Returns:
- the entry id of the entry added
- Throws:
IOException
-
getEntry
Description copied from interface:LedgerStorageRead an entry from storage.- Specified by:
getEntryin interfaceLedgerStorage- Throws:
IOException
-
checkpoint
Description copied from interface:LedgerStorageAsk the ledger storage to sync data until the given checkpoint. The ledger storage implementation do checkpoint and return the real checkpoint that it finished. The returned the checkpoint indicates that all entries added before that point already persist.- Specified by:
checkpointin interfaceLedgerStorage- Parameters:
checkpoint- Check Point thatCheckpointSource.Checkpointproposed.- Throws:
IOException
-
flush
Description copied from interface:LedgerStorageFlushes all data in the storage. Once this is called, add data written to the LedgerStorage up until this point has been persisted to perminant storage- Specified by:
flushin interfaceLedgerStorage- Throws:
IOException
-
deleteLedger
- Specified by:
deleteLedgerin interfaceLedgerStorage- Throws:
IOException
-
getActiveLedgersInRange
Description copied from interface:CompactableLedgerStorageGet an iterator over a range of ledger ids stored in the bookie.- Specified by:
getActiveLedgersInRangein interfaceCompactableLedgerStorage- Parameters:
firstLedgerId- first ledger id in the sequence (included)lastLedgerId- last ledger id in the sequence (not included)- Returns:
-
updateEntriesLocations
Description copied from interface:CompactableLedgerStorageUpdate the location of several entries.- Specified by:
updateEntriesLocationsin interfaceCompactableLedgerStorage- Parameters:
locations- the list of locations to update- Throws:
IOException
-
flushEntriesLocationsIndex
Description copied from interface:CompactableLedgerStorageFlush the entries locations index for the compacted entries.- Specified by:
flushEntriesLocationsIndexin interfaceCompactableLedgerStorage- Throws:
IOException
-
getEntryLogger
-
registerLedgerDeletionListener
Description copied from interface:LedgerStorageRegister a listener for ledgers deletion notifications.- Specified by:
registerLedgerDeletionListenerin interfaceLedgerStorage- Parameters:
listener- object that will be notified every time a ledger is deleted
-
processEntry
protected void processEntry(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry) throws IOException - Throws:
IOException
-
processEntry
protected void processEntry(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry, boolean rollLog) throws IOException - Throws:
IOException
-
onRotateEntryLog
public void onRotateEntryLog()Description copied from interface:DefaultEntryLogger.EntryLogListenerRotate a new entry log to write.- Specified by:
onRotateEntryLogin interfaceDefaultEntryLogger.EntryLogListener
-
getIndexEntries
Return iterable for index entries for ledgerId.- Parameters:
ledgerId- ledger to scan- Returns:
- Iterator
- Throws:
IOException
-
readLedgerIndexMetadata
Read implementation metadata for index file.- Parameters:
ledgerId-- Returns:
- Implementation metadata
- Throws:
IOException
-
localConsistencyCheck
public List<LedgerStorage.DetectedInconsistency> localConsistencyCheck(Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter) throws IOException Description copied from interface:LedgerStoragePerforms internal check of local storage logging any inconsistencies.- Specified by:
localConsistencyCheckin interfaceLedgerStorage- Parameters:
rateLimiter- Provide to rate of entry checking. null for unlimited.- Returns:
- List of inconsistencies detected
- Throws:
IOException
-
getGarbageCollectionStatus
Description copied from interface:LedgerStorageGet Garbage Collection status. Since DbLedgerStorage is a list of storage instances, we should return a list.- Specified by:
getGarbageCollectionStatusin interfaceLedgerStorage
-
getListOfEntriesOfLedger
Description copied from interface:LedgerStorageReturns the primitive long iterator for entries of the ledger, stored in this LedgerStorage. The returned iterator provide weakly consistent state of the ledger. It is guaranteed that entries of the ledger added to this LedgerStorage by the time this method is called will be available but modifications made after method invocation may not be available.- Specified by:
getListOfEntriesOfLedgerin interfaceLedgerStorage- Parameters:
ledgerId- - id of the ledger- Returns:
- the list of entries of the ledger available in this ledgerstorage.
- Throws:
IOException
-
setLimboState
Description copied from interface:LedgerStorageSet a ledger to limbo state. When a ledger is in limbo state, we cannot answer any requests about it. For example, if a client asks for an entry, we cannot say we don't have it because it may have been written to us in the past, but we are waiting for data integrity checks to copy it over.- Specified by:
setLimboStatein interfaceLedgerStorage- Throws:
IOException
-
hasLimboState
Description copied from interface:LedgerStorageCheck whether a ledger is in limbo state.- Specified by:
hasLimboStatein interfaceLedgerStorage- Throws:
IOException- See Also:
-
clearLimboState
Description copied from interface:LedgerStorageClear the limbo state of a ledger.- Specified by:
clearLimboStatein interfaceLedgerStorage- Throws:
IOException- See Also:
-
getStorageStateFlags
Description copied from interface:LedgerStorageGet the storage state flags currently set for the storage instance.- Specified by:
getStorageStateFlagsin interfaceLedgerStorage- Throws:
IOException
-
setStorageStateFlag
Description copied from interface:LedgerStorageSet a storage state flag for the storage instance. Implementations must ensure this method is atomic, and the flag is persisted to storage when the method returns.- Specified by:
setStorageStateFlagin interfaceLedgerStorage- Throws:
IOException
-
clearStorageStateFlag
Description copied from interface:LedgerStorageClear a storage state flag for the storage instance. Implementations must ensure this method is atomic, and the flag is persisted to storage when the method returns.- Specified by:
clearStorageStateFlagin interfaceLedgerStorage- Throws:
IOException
-
getLedgerCache
-