Package org.apache.bookkeeper.bookie
Interface LedgerStorage
-
- All Known Subinterfaces:
CompactableLedgerStorage
- All Known Implementing Classes:
DbLedgerStorage,InterleavedLedgerStorage,SingleDirectoryDbLedgerStorage,SortedLedgerStorage
public interface LedgerStorageInterface for storing ledger data on persistent storage.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classLedgerStorage.DetectedInconsistencyClass for describing location of a generic inconsistency.static interfaceLedgerStorage.LedgerDeletionListenerSignals that a ledger is deleted by the garbage collection thread.static classLedgerStorage.StorageStateStorageState flags.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description longaddEntry(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.voidclearStorageStateFlag(LedgerStorage.StorageState flags)Clear a storage state flag for the storage instance.voiddeleteLedger(long ledgerId)booleanentryExists(long ledgerId, long entryId)Whether an entry exists.default voidentryLocationCompact()default voidentryLocationCompact(java.util.List<java.lang.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.default java.util.List<java.lang.String>getEntryLocationDBPath()io.netty.buffer.ByteBufgetExplicitLac(long ledgerId)default java.util.List<GarbageCollectionStatus>getGarbageCollectionStatus()Get Garbage Collection status.longgetLastAddConfirmed(long ledgerId)Get last add confirmed.java.util.PrimitiveIterator.OfLonggetListOfEntriesOfLedger(long ledgerId)Returns the primitive long iterator for entries of the ledger, stored in this LedgerStorage.java.util.EnumSet<LedgerStorage.StorageState>getStorageStateFlags()Get the storage state flags currently set for the storage instance.default LedgerStoragegetUnderlyingLedgerStorage()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.default booleanisEntryLocationCompacting()default java.util.Map<java.lang.String,java.lang.Boolean>isEntryLocationCompacting(java.util.List<java.lang.String> locations)booleanisFenced(long ledgerId)Check whether the ledger is fenced in ledger storage or not.default booleanisInForceGC()Whether force triggered Garbage Collection is running or not.default booleanisMajorGcSuspended()default booleanisMinorGcSuspended()booleanledgerExists(long ledgerId)Whether a ledger exists.default java.util.List<LedgerStorage.DetectedInconsistency>localConsistencyCheck(java.util.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.voidregisterLedgerDeletionListener(LedgerStorage.LedgerDeletionListener listener)Register a listener for ledgers deletion notifications.default voidresumeMajorGC()default voidresumeMinorGC()voidsetCheckpointer(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)voidsetStorageStateFlag(LedgerStorage.StorageState flags)Set 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 voidsuspendMajorGC()default voidsuspendMinorGC()booleanwaitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher)Wait for last add confirmed update.
-
-
-
Method Detail
-
initialize
void initialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) throws java.io.IOException
Initialize the LedgerStorage implementation.- Parameters:
conf-ledgerManager-ledgerDirsManager-- Throws:
java.io.IOException
-
setStateManager
void setStateManager(StateManager stateManager)
-
setCheckpointSource
void setCheckpointSource(CheckpointSource checkpointSource)
-
setCheckpointer
void setCheckpointer(Checkpointer checkpointer)
-
start
void start()
Start any background threads belonging to the storage system. For example, garbage collection.
-
shutdown
void shutdown() throws java.lang.InterruptedExceptionCleanup and free any resources being used by the storage system.- Throws:
java.lang.InterruptedException
-
ledgerExists
boolean ledgerExists(long ledgerId) throws java.io.IOExceptionWhether a ledger exists.- Throws:
java.io.IOException
-
entryExists
boolean entryExists(long ledgerId, long entryId) throws java.io.IOException, BookieExceptionWhether an entry exists.- Throws:
java.io.IOExceptionBookieException
-
setFenced
boolean setFenced(long ledgerId) throws java.io.IOExceptionFenced the ledger id in ledger storage.- Parameters:
ledgerId- Ledger Id.- Throws:
java.io.IOException- when failed to fence the ledger.
-
isFenced
boolean isFenced(long ledgerId) throws java.io.IOException, BookieExceptionCheck whether the ledger is fenced in ledger storage or not.- Parameters:
ledgerId- Ledger ID.- Throws:
java.io.IOExceptionBookieException
-
setLimboState
void setLimboState(long ledgerId) throws java.io.IOExceptionSet 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:
java.io.IOException
-
hasLimboState
boolean hasLimboState(long ledgerId) throws java.io.IOExceptionCheck whether a ledger is in limbo state.- Throws:
java.io.IOException- See Also:
setLimboState(long)
-
clearLimboState
void clearLimboState(long ledgerId) throws java.io.IOExceptionClear the limbo state of a ledger.- Throws:
java.io.IOException- See Also:
setLimboState(long)
-
setMasterKey
void setMasterKey(long ledgerId, byte[] masterKey) throws java.io.IOExceptionSet the master key for a ledger.- Throws:
java.io.IOException
-
readMasterKey
byte[] readMasterKey(long ledgerId) throws java.io.IOException, BookieExceptionGet the master key for a ledger.- Throws:
java.io.IOException- if there is an error reading the from the ledgerBookieException- if no such ledger exists
-
addEntry
long addEntry(io.netty.buffer.ByteBuf entry) throws java.io.IOException, BookieExceptionAdd an entry to the storage.- Returns:
- the entry id of the entry added
- Throws:
java.io.IOExceptionBookieException
-
getEntry
io.netty.buffer.ByteBuf getEntry(long ledgerId, long entryId) throws java.io.IOException, BookieExceptionRead an entry from storage.- Throws:
java.io.IOExceptionBookieException
-
getLastAddConfirmed
long getLastAddConfirmed(long ledgerId) throws java.io.IOException, BookieExceptionGet last add confirmed.- Parameters:
ledgerId- ledger id.- Returns:
- last add confirmed.
- Throws:
java.io.IOExceptionBookieException
-
waitForLastAddConfirmedUpdate
boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.IOExceptionWait for last add confirmed update.- Parameters:
previousLAC- - The threshold beyond which we would wait for the updatewatcher- - Watcher to notify on update- Returns:
- Throws:
java.io.IOException
-
cancelWaitForLastAddConfirmedUpdate
void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.IOExceptionCancel a previous wait for last add confirmed update.- Parameters:
ledgerId- The ledger being watched.watcher- The watcher to cancel.- Throws:
java.io.IOException
-
flush
void flush() throws java.io.IOExceptionFlushes 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:
java.io.IOException
-
checkpoint
void checkpoint(CheckpointSource.Checkpoint checkpoint) throws java.io.IOException
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:
java.io.IOException
-
deleteLedger
void deleteLedger(long ledgerId) throws java.io.IOException- Parameters:
ledgerId-- Throws:
java.io.IOException
-
registerLedgerDeletionListener
void registerLedgerDeletionListener(LedgerStorage.LedgerDeletionListener listener)
Register a listener for ledgers deletion notifications.- Parameters:
listener- object that will be notified every time a ledger is deleted
-
setExplicitLac
void setExplicitLac(long ledgerId, io.netty.buffer.ByteBuf lac) throws java.io.IOException- Throws:
java.io.IOException
-
getExplicitLac
io.netty.buffer.ByteBuf getExplicitLac(long ledgerId) throws java.io.IOException, BookieException- Throws:
java.io.IOExceptionBookieException
-
getUnderlyingLedgerStorage
default LedgerStorage 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
default void entryLocationCompact(java.util.List<java.lang.String> locations)
-
isEntryLocationCompacting
default boolean isEntryLocationCompacting()
-
isEntryLocationCompacting
default java.util.Map<java.lang.String,java.lang.Boolean> isEntryLocationCompacting(java.util.List<java.lang.String> locations)
-
getEntryLocationDBPath
default java.util.List<java.lang.String> getEntryLocationDBPath()
-
localConsistencyCheck
default java.util.List<LedgerStorage.DetectedInconsistency> localConsistencyCheck(java.util.Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter) throws java.io.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:
java.io.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
default java.util.List<GarbageCollectionStatus> getGarbageCollectionStatus()
Get Garbage Collection status. Since DbLedgerStorage is a list of storage instances, we should return a list.
-
getListOfEntriesOfLedger
java.util.PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId) throws java.io.IOExceptionReturns 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:
java.lang.Exceptionjava.io.IOException
-
getStorageStateFlags
java.util.EnumSet<LedgerStorage.StorageState> getStorageStateFlags() throws java.io.IOException
Get the storage state flags currently set for the storage instance.- Throws:
java.io.IOException
-
setStorageStateFlag
void setStorageStateFlag(LedgerStorage.StorageState flags) throws java.io.IOException
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:
java.io.IOException
-
clearStorageStateFlag
void clearStorageStateFlag(LedgerStorage.StorageState flags) throws java.io.IOException
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:
java.io.IOException
-
-