Class InterleavedLedgerStorage

    • Constructor Detail

      • InterleavedLedgerStorage

        public InterleavedLedgerStorage()
    • Method Detail

      • forceGC

        public void forceGC()
        Description copied from interface: LedgerStorage
        Force trigger Garbage Collection.
        Specified by:
        forceGC in interface LedgerStorage
      • forceGC

        public void forceGC​(boolean forceMajor,
                            boolean forceMinor)
        Description copied from interface: LedgerStorage
        Force trigger Garbage Collection with forceMajor or forceMinor parameter.
        Specified by:
        forceGC in interface LedgerStorage
      • isInForceGC

        public boolean isInForceGC()
        Description copied from interface: LedgerStorage
        Whether force triggered Garbage Collection is running or not.
        Specified by:
        isInForceGC in interface LedgerStorage
        Returns:
        true -- force triggered Garbage Collection is running, false -- force triggered Garbage Collection is not running
      • start

        public void start()
        Description copied from interface: LedgerStorage
        Start any background threads belonging to the storage system. For example, garbage collection.
        Specified by:
        start in interface LedgerStorage
      • shutdown

        public void shutdown()
                      throws java.lang.InterruptedException
        Description copied from interface: LedgerStorage
        Cleanup and free any resources being used by the storage system.
        Specified by:
        shutdown in interface LedgerStorage
        Throws:
        java.lang.InterruptedException
      • setFenced

        public boolean setFenced​(long ledgerId)
                          throws java.io.IOException
        Description copied from interface: LedgerStorage
        Fenced the ledger id in ledger storage.
        Specified by:
        setFenced in interface LedgerStorage
        Parameters:
        ledgerId - Ledger Id.
        Throws:
        java.io.IOException - when failed to fence the ledger.
      • isFenced

        public boolean isFenced​(long ledgerId)
                         throws java.io.IOException
        Description copied from interface: LedgerStorage
        Check whether the ledger is fenced in ledger storage or not.
        Specified by:
        isFenced in interface LedgerStorage
        Parameters:
        ledgerId - Ledger ID.
        Throws:
        java.io.IOException
      • setExplicitLac

        public void setExplicitLac​(long ledgerId,
                                   io.netty.buffer.ByteBuf lac)
                            throws java.io.IOException
        Specified by:
        setExplicitLac in interface LedgerStorage
        Throws:
        java.io.IOException
      • getExplicitLac

        public io.netty.buffer.ByteBuf getExplicitLac​(long ledgerId)
        Specified by:
        getExplicitLac in interface LedgerStorage
      • setMasterKey

        public void setMasterKey​(long ledgerId,
                                 byte[] masterKey)
                          throws java.io.IOException
        Description copied from interface: LedgerStorage
        Set the master key for a ledger.
        Specified by:
        setMasterKey in interface LedgerStorage
        Throws:
        java.io.IOException
      • readMasterKey

        public byte[] readMasterKey​(long ledgerId)
                             throws java.io.IOException,
                                    BookieException
        Description copied from interface: LedgerStorage
        Get the master key for a ledger.
        Specified by:
        readMasterKey in interface LedgerStorage
        Throws:
        java.io.IOException - if there is an error reading the from the ledger
        BookieException - if no such ledger exists
      • ledgerExists

        public boolean ledgerExists​(long ledgerId)
                             throws java.io.IOException
        Description copied from interface: LedgerStorage
        Whether a ledger exists.
        Specified by:
        ledgerExists in interface LedgerStorage
        Throws:
        java.io.IOException
      • entryExists

        public boolean entryExists​(long ledgerId,
                                   long entryId)
                            throws java.io.IOException
        Description copied from interface: LedgerStorage
        Whether an entry exists.
        Specified by:
        entryExists in interface LedgerStorage
        Throws:
        java.io.IOException
      • getLastAddConfirmed

        public long getLastAddConfirmed​(long ledgerId)
                                 throws java.io.IOException
        Description copied from interface: LedgerStorage
        Get last add confirmed.
        Specified by:
        getLastAddConfirmed in interface LedgerStorage
        Parameters:
        ledgerId - ledger id.
        Returns:
        last add confirmed.
        Throws:
        java.io.IOException
      • waitForLastAddConfirmedUpdate

        public boolean waitForLastAddConfirmedUpdate​(long ledgerId,
                                                     long previousLAC,
                                                     Watcher<LastAddConfirmedUpdateNotification> watcher)
                                              throws java.io.IOException
        Description copied from interface: LedgerStorage
        Wait for last add confirmed update.
        Specified by:
        waitForLastAddConfirmedUpdate in interface LedgerStorage
        previousLAC - - The threshold beyond which we would wait for the update
        watcher - - Watcher to notify on update
        Returns:
        Throws:
        java.io.IOException
      • addEntry

        public long addEntry​(io.netty.buffer.ByteBuf entry)
                      throws java.io.IOException
        Description copied from interface: LedgerStorage
        Add an entry to the storage.
        Specified by:
        addEntry in interface LedgerStorage
        Returns:
        the entry id of the entry added
        Throws:
        java.io.IOException
      • getEntry

        public io.netty.buffer.ByteBuf getEntry​(long ledgerId,
                                                long entryId)
                                         throws java.io.IOException
        Description copied from interface: LedgerStorage
        Read an entry from storage.
        Specified by:
        getEntry in interface LedgerStorage
        Throws:
        java.io.IOException
      • checkpoint

        public void checkpoint​(CheckpointSource.Checkpoint checkpoint)
                        throws java.io.IOException
        Description copied from interface: LedgerStorage
        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.
        Specified by:
        checkpoint in interface LedgerStorage
        Parameters:
        checkpoint - Check Point that CheckpointSource.Checkpoint proposed.
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from interface: LedgerStorage
        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
        Specified by:
        flush in interface LedgerStorage
        Throws:
        java.io.IOException
      • deleteLedger

        public void deleteLedger​(long ledgerId)
                          throws java.io.IOException
        Specified by:
        deleteLedger in interface LedgerStorage
        Throws:
        java.io.IOException
      • getActiveLedgersInRange

        public java.lang.Iterable<java.lang.Long> getActiveLedgersInRange​(long firstLedgerId,
                                                                          long lastLedgerId)
        Description copied from interface: CompactableLedgerStorage
        Get an iterator over a range of ledger ids stored in the bookie.
        Specified by:
        getActiveLedgersInRange in interface CompactableLedgerStorage
        Parameters:
        firstLedgerId - first ledger id in the sequence (included)
        lastLedgerId - last ledger id in the sequence (not included)
        Returns:
      • processEntry

        protected void processEntry​(long ledgerId,
                                    long entryId,
                                    io.netty.buffer.ByteBuf entry)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • processEntry

        protected void processEntry​(long ledgerId,
                                    long entryId,
                                    io.netty.buffer.ByteBuf entry,
                                    boolean rollLog)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • getIndexEntries

        public LedgerCache.PageEntriesIterable getIndexEntries​(long ledgerId)
                                                        throws java.io.IOException
        Return iterable for index entries for ledgerId.
        Parameters:
        ledgerId - ledger to scan
        Returns:
        Iterator
        Throws:
        java.io.IOException
      • readLedgerIndexMetadata

        public LedgerCache.LedgerIndexMetadata readLedgerIndexMetadata​(long ledgerId)
                                                                throws java.io.IOException
        Read implementation metadata for index file.
        Parameters:
        ledgerId -
        Returns:
        Implementation metadata
        Throws:
        java.io.IOException
      • localConsistencyCheck

        public java.util.List<LedgerStorage.DetectedInconsistency> localConsistencyCheck​(java.util.Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter)
                                                                                  throws java.io.IOException
        Description copied from interface: LedgerStorage
        Performs internal check of local storage logging any inconsistencies.
        Specified by:
        localConsistencyCheck in interface LedgerStorage
        Parameters:
        rateLimiter - Provide to rate of entry checking. null for unlimited.
        Returns:
        List of inconsistencies detected
        Throws:
        java.io.IOException
      • getListOfEntriesOfLedger

        public java.util.PrimitiveIterator.OfLong getListOfEntriesOfLedger​(long ledgerId)
                                                                    throws java.io.IOException
        Description copied from interface: LedgerStorage
        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.
        Specified by:
        getListOfEntriesOfLedger in interface LedgerStorage
        Parameters:
        ledgerId - - id of the ledger
        Returns:
        the list of entries of the ledger available in this ledgerstorage.
        Throws:
        java.io.IOException
      • setLimboState

        public void setLimboState​(long ledgerId)
                           throws java.io.IOException
        Description copied from interface: LedgerStorage
        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.
        Specified by:
        setLimboState in interface LedgerStorage
        Throws:
        java.io.IOException
      • setStorageStateFlag

        public void setStorageStateFlag​(LedgerStorage.StorageState flags)
                                 throws java.io.IOException
        Description copied from interface: LedgerStorage
        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.
        Specified by:
        setStorageStateFlag in interface LedgerStorage
        Throws:
        java.io.IOException
      • clearStorageStateFlag

        public void clearStorageStateFlag​(LedgerStorage.StorageState flags)
                                   throws java.io.IOException
        Description copied from interface: LedgerStorage
        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.
        Specified by:
        clearStorageStateFlag in interface LedgerStorage
        Throws:
        java.io.IOException