Interface LedgerStorage

    • 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 ledger
        BookieException - 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 update
        watcher - - 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 that CheckpointSource.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​(java.lang.Boolean forceMajor,
                             java.lang.Boolean forceMinor)
        Force trigger Garbage Collection with forceMajor or forceMinor parameter.
      • 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