Package org.apache.bookkeeper.bookie
Interface LedgerStorage
- All Known Subinterfaces:
CompactableLedgerStorage
- All Known Implementing Classes:
DbLedgerStorage,InterleavedLedgerStorage,SingleDirectoryDbLedgerStorage,SortedLedgerStorage
public interface LedgerStorage
Interface for storing ledger data on persistent storage.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classClass for describing location of a generic inconsistency.static interfaceSignals that a ledger is deleted by the garbage collection thread.static enumStorageState flags. -
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.default voiddefault voidentryLocationCompact(List<String> locations) voidflush()Flushes all data in the storage.default voidforceGC()Force trigger Garbage Collection.default voidforceGC(boolean forceMajor, boolean forceMinor) Force trigger Garbage Collection with forceMajor or forceMinor parameter.io.netty.buffer.ByteBufgetEntry(long ledgerId, long entryId) Read an entry from storage.io.netty.buffer.ByteBufgetExplicitLac(long ledgerId) default List<GarbageCollectionStatus>Get Garbage Collection status.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.default LedgerStoragebooleanhasLimboState(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.default booleanisEntryLocationCompacting(List<String> locations) booleanisFenced(long ledgerId) Check whether the ledger is fenced in ledger storage or not.default booleanWhether force triggered Garbage Collection is running or not.default booleandefault booleanbooleanledgerExists(long ledgerId) Whether a ledger exists.default List<LedgerStorage.DetectedInconsistency>localConsistencyCheck(Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter) Performs internal check of local storage logging any inconsistencies.byte[]readMasterKey(long ledgerId) Get the master key for a ledger.voidRegister a listener for ledgers deletion notifications.default voiddefault voidvoidsetCheckpointer(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.default voiddefault voidbooleanwaitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) Wait for last add confirmed update.
-
Method Details
-
initialize
void initialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) throws IOException Initialize the LedgerStorage implementation.- Parameters:
conf-ledgerManager-ledgerDirsManager-- Throws:
IOException
-
setStateManager
-
setCheckpointSource
-
setCheckpointer
-
start
void start()Start any background threads belonging to the storage system. For example, garbage collection. -
shutdown
Cleanup and free any resources being used by the storage system.- Throws:
InterruptedException
-
ledgerExists
Whether a ledger exists.- Throws:
IOException
-
entryExists
Whether an entry exists.- Throws:
IOExceptionBookieException
-
setFenced
Fenced the ledger id in ledger storage.- Parameters:
ledgerId- Ledger Id.- Throws:
IOException- when failed to fence the ledger.
-
isFenced
Check whether the ledger is fenced in ledger storage or not.- Parameters:
ledgerId- Ledger ID.- Throws:
IOExceptionBookieException
-
setLimboState
Set 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.- Throws:
IOException
-
hasLimboState
Check whether a ledger is in limbo state.- Throws:
IOException- See Also:
-
clearLimboState
Clear the limbo state of a ledger.- Throws:
IOException- See Also:
-
setMasterKey
Set the master key for a ledger.- Throws:
IOException
-
readMasterKey
Get the master key for a ledger.- Throws:
IOException- if there is an error reading the from the ledgerBookieException- if no such ledger exists
-
addEntry
Add an entry to the storage.- Returns:
- the entry id of the entry added
- Throws:
IOExceptionBookieException
-
getEntry
Read an entry from storage.- Throws:
IOExceptionBookieException
-
getLastAddConfirmed
Get last add confirmed.- Parameters:
ledgerId- ledger id.- Returns:
- last add confirmed.
- Throws:
IOExceptionBookieException
-
waitForLastAddConfirmedUpdate
boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException Wait for last add confirmed update.- Parameters:
previousLAC- - The threshold beyond which we would wait for the updatewatcher- - Watcher to notify on update- Returns:
- Throws:
IOException
-
cancelWaitForLastAddConfirmedUpdate
void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException Cancel a previous wait for last add confirmed update.- Parameters:
ledgerId- The ledger being watched.watcher- The watcher to cancel.- Throws:
IOException
-
flush
Flushes 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- Throws:
IOException
-
checkpoint
Ask 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.- Parameters:
checkpoint- Check Point thatCheckpointSource.Checkpointproposed.- Throws:
IOException
-
deleteLedger
- Parameters:
ledgerId-- Throws:
IOException
-
registerLedgerDeletionListener
Register a listener for ledgers deletion notifications.- Parameters:
listener- object that will be notified every time a ledger is deleted
-
setExplicitLac
- Throws:
IOException
-
getExplicitLac
- Throws:
IOExceptionBookieException
-
getUnderlyingLedgerStorage
-
forceGC
default void forceGC()Force trigger Garbage Collection. -
forceGC
default void forceGC(boolean forceMajor, boolean forceMinor) Force trigger Garbage Collection with forceMajor or forceMinor parameter. -
suspendMinorGC
default void suspendMinorGC() -
suspendMajorGC
default void suspendMajorGC() -
resumeMinorGC
default void resumeMinorGC() -
resumeMajorGC
default void resumeMajorGC() -
isMajorGcSuspended
default boolean isMajorGcSuspended() -
isMinorGcSuspended
default boolean isMinorGcSuspended() -
entryLocationCompact
default void entryLocationCompact() -
entryLocationCompact
-
isEntryLocationCompacting
default boolean isEntryLocationCompacting() -
isEntryLocationCompacting
-
getEntryLocationDBPath
-
localConsistencyCheck
default List<LedgerStorage.DetectedInconsistency> localConsistencyCheck(Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter) throws IOException Performs internal check of local storage logging any inconsistencies.- Parameters:
rateLimiter- Provide to rate of entry checking. null for unlimited.- Returns:
- List of inconsistencies detected
- Throws:
IOException
-
isInForceGC
default boolean isInForceGC()Whether force triggered Garbage Collection is running or not.- Returns:
- true -- force triggered Garbage Collection is running, false -- force triggered Garbage Collection is not running
-
getGarbageCollectionStatus
Get Garbage Collection status. Since DbLedgerStorage is a list of storage instances, we should return a list. -
getListOfEntriesOfLedger
Returns 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.- Parameters:
ledgerId- - id of the ledger- Returns:
- the list of entries of the ledger available in this ledgerstorage.
- Throws:
ExceptionIOException
-
getStorageStateFlags
Get the storage state flags currently set for the storage instance.- Throws:
IOException
-
setStorageStateFlag
Set 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.- Throws:
IOException
-
clearStorageStateFlag
Clear 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.- Throws:
IOException
-