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.
  • 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

      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 InterruptedException
      Cleanup and free any resources being used by the storage system.
      Throws:
      InterruptedException
    • ledgerExists

      boolean ledgerExists(long ledgerId) throws IOException
      Whether a ledger exists.
      Throws:
      IOException
    • entryExists

      boolean entryExists(long ledgerId, long entryId) throws IOException, BookieException
      Whether an entry exists.
      Throws:
      IOException
      BookieException
    • setFenced

      boolean setFenced(long ledgerId) throws IOException
      Fenced the ledger id in ledger storage.
      Parameters:
      ledgerId - Ledger Id.
      Throws:
      IOException - when failed to fence the ledger.
    • isFenced

      boolean isFenced(long ledgerId) throws IOException, BookieException
      Check whether the ledger is fenced in ledger storage or not.
      Parameters:
      ledgerId - Ledger ID.
      Throws:
      IOException
      BookieException
    • setLimboState

      void setLimboState(long ledgerId) throws 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:
      IOException
    • hasLimboState

      boolean hasLimboState(long ledgerId) throws IOException
      Check whether a ledger is in limbo state.
      Throws:
      IOException
      See Also:
    • clearLimboState

      void clearLimboState(long ledgerId) throws IOException
      Clear the limbo state of a ledger.
      Throws:
      IOException
      See Also:
    • setMasterKey

      void setMasterKey(long ledgerId, byte[] masterKey) throws IOException
      Set the master key for a ledger.
      Throws:
      IOException
    • readMasterKey

      byte[] readMasterKey(long ledgerId) throws IOException, BookieException
      Get the master key for a ledger.
      Throws:
      IOException - if there is an error reading the from the ledger
      BookieException - if no such ledger exists
    • addEntry

      long addEntry(io.netty.buffer.ByteBuf entry) throws IOException, BookieException
      Add an entry to the storage.
      Returns:
      the entry id of the entry added
      Throws:
      IOException
      BookieException
    • getEntry

      io.netty.buffer.ByteBuf getEntry(long ledgerId, long entryId) throws IOException, BookieException
      Read an entry from storage.
      Throws:
      IOException
      BookieException
    • getLastAddConfirmed

      long getLastAddConfirmed(long ledgerId) throws IOException, BookieException
      Get last add confirmed.
      Parameters:
      ledgerId - ledger id.
      Returns:
      last add confirmed.
      Throws:
      IOException
      BookieException
    • 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 update
      watcher - - 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

      void flush() throws 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:
      IOException
    • checkpoint

      void checkpoint(CheckpointSource.Checkpoint checkpoint) throws 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 that CheckpointSource.Checkpoint proposed.
      Throws:
      IOException
    • deleteLedger

      void deleteLedger(long ledgerId) throws IOException
      Parameters:
      ledgerId -
      Throws:
      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 IOException
      Throws:
      IOException
    • getExplicitLac

      io.netty.buffer.ByteBuf getExplicitLac(long ledgerId) throws IOException, BookieException
      Throws:
      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(List<String> locations)
    • isEntryLocationCompacting

      default boolean isEntryLocationCompacting()
    • isEntryLocationCompacting

      default Map<String,Boolean> isEntryLocationCompacting(List<String> locations)
    • getEntryLocationDBPath

      default List<String> 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

      default List<GarbageCollectionStatus> getGarbageCollectionStatus()
      Get Garbage Collection status. Since DbLedgerStorage is a list of storage instances, we should return a list.
    • getListOfEntriesOfLedger

      PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId) throws 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:
      Exception
      IOException
    • getStorageStateFlags

      EnumSet<LedgerStorage.StorageState> getStorageStateFlags() throws IOException
      Get the storage state flags currently set for the storage instance.
      Throws:
      IOException
    • setStorageStateFlag

      void setStorageStateFlag(LedgerStorage.StorageState flags) throws 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:
      IOException
    • clearStorageStateFlag

      void clearStorageStateFlag(LedgerStorage.StorageState flags) throws 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:
      IOException