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 Classes Modifier and Type Interface Description static class
LedgerStorage.DetectedInconsistency
Class for describing location of a generic inconsistency.static interface
LedgerStorage.LedgerDeletionListener
Signals that a ledger is deleted by the garbage collection thread.static class
LedgerStorage.StorageState
StorageState flags.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description long
addEntry(io.netty.buffer.ByteBuf entry)
Add an entry to the storage.void
cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher)
Cancel a previous wait for last add confirmed update.void
checkpoint(CheckpointSource.Checkpoint checkpoint)
Ask the ledger storage to sync data until the given checkpoint.void
clearLimboState(long ledgerId)
Clear the limbo state of a ledger.void
clearStorageStateFlag(LedgerStorage.StorageState flags)
Clear a storage state flag for the storage instance.void
deleteLedger(long ledgerId)
boolean
entryExists(long ledgerId, long entryId)
Whether an entry exists.default void
entryLocationCompact()
default void
entryLocationCompact(java.util.List<java.lang.String> locations)
void
flush()
Flushes all data in the storage.default void
forceGC()
Force trigger Garbage Collection.default void
forceGC(boolean forceMajor, boolean forceMinor)
Force trigger Garbage Collection with forceMajor or forceMinor parameter.io.netty.buffer.ByteBuf
getEntry(long ledgerId, long entryId)
Read an entry from storage.default java.util.List<java.lang.String>
getEntryLocationDBPath()
io.netty.buffer.ByteBuf
getExplicitLac(long ledgerId)
default java.util.List<GarbageCollectionStatus>
getGarbageCollectionStatus()
Get Garbage Collection status.long
getLastAddConfirmed(long ledgerId)
Get last add confirmed.java.util.PrimitiveIterator.OfLong
getListOfEntriesOfLedger(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 LedgerStorage
getUnderlyingLedgerStorage()
boolean
hasLimboState(long ledgerId)
Check whether a ledger is in limbo state.void
initialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator)
Initialize the LedgerStorage implementation.default boolean
isEntryLocationCompacting()
default java.util.Map<java.lang.String,java.lang.Boolean>
isEntryLocationCompacting(java.util.List<java.lang.String> locations)
boolean
isFenced(long ledgerId)
Check whether the ledger is fenced in ledger storage or not.default boolean
isInForceGC()
Whether force triggered Garbage Collection is running or not.default boolean
isMajorGcSuspended()
default boolean
isMinorGcSuspended()
boolean
ledgerExists(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.void
registerLedgerDeletionListener(LedgerStorage.LedgerDeletionListener listener)
Register a listener for ledgers deletion notifications.default void
resumeMajorGC()
default void
resumeMinorGC()
void
setCheckpointer(Checkpointer checkpointer)
void
setCheckpointSource(CheckpointSource checkpointSource)
void
setExplicitLac(long ledgerId, io.netty.buffer.ByteBuf lac)
boolean
setFenced(long ledgerId)
Fenced the ledger id in ledger storage.void
setLimboState(long ledgerId)
Set a ledger to limbo state.void
setMasterKey(long ledgerId, byte[] masterKey)
Set the master key for a ledger.void
setStateManager(StateManager stateManager)
void
setStorageStateFlag(LedgerStorage.StorageState flags)
Set a storage state flag for the storage instance.void
shutdown()
Cleanup and free any resources being used by the storage system.void
start()
Start any background threads belonging to the storage system.default void
suspendMajorGC()
default void
suspendMinorGC()
boolean
waitForLastAddConfirmedUpdate(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.InterruptedException
Cleanup and free any resources being used by the storage system.- Throws:
java.lang.InterruptedException
-
ledgerExists
boolean ledgerExists(long ledgerId) throws java.io.IOException
Whether a ledger exists.- Throws:
java.io.IOException
-
entryExists
boolean entryExists(long ledgerId, long entryId) throws java.io.IOException, BookieException
Whether an entry exists.- Throws:
java.io.IOException
BookieException
-
setFenced
boolean setFenced(long ledgerId) throws java.io.IOException
Fenced 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, BookieException
Check whether the ledger is fenced in ledger storage or not.- Parameters:
ledgerId
- Ledger ID.- Throws:
java.io.IOException
BookieException
-
setLimboState
void setLimboState(long ledgerId) throws java.io.IOException
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:
java.io.IOException
-
hasLimboState
boolean hasLimboState(long ledgerId) throws java.io.IOException
Check whether a ledger is in limbo state.- Throws:
java.io.IOException
- See Also:
setLimboState(long)
-
clearLimboState
void clearLimboState(long ledgerId) throws java.io.IOException
Clear the limbo state of a ledger.- Throws:
java.io.IOException
- See Also:
setLimboState(long)
-
setMasterKey
void setMasterKey(long ledgerId, byte[] masterKey) throws java.io.IOException
Set the master key for a ledger.- Throws:
java.io.IOException
-
readMasterKey
byte[] readMasterKey(long ledgerId) throws java.io.IOException, BookieException
Get 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, BookieException
Add an entry to the storage.- Returns:
- the entry id of the entry added
- Throws:
java.io.IOException
BookieException
-
getEntry
io.netty.buffer.ByteBuf getEntry(long ledgerId, long entryId) throws java.io.IOException, BookieException
Read an entry from storage.- Throws:
java.io.IOException
BookieException
-
getLastAddConfirmed
long getLastAddConfirmed(long ledgerId) throws java.io.IOException, BookieException
Get last add confirmed.- Parameters:
ledgerId
- ledger id.- Returns:
- last add confirmed.
- Throws:
java.io.IOException
BookieException
-
waitForLastAddConfirmedUpdate
boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.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:
java.io.IOException
-
cancelWaitForLastAddConfirmedUpdate
void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.IOException
Cancel 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.IOException
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:
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.Checkpoint
proposed.- 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.IOException
BookieException
-
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.IOException
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:
java.lang.Exception
java.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
-
-