Class DbLedgerStorage

  • All Implemented Interfaces:
    LedgerStorage

    public class DbLedgerStorage
    extends java.lang.Object
    implements LedgerStorage
    Implementation of LedgerStorage that uses RocksDB to keep the indexes for entries stored in EntryLogs.
    • Field Detail

      • WRITE_CACHE_MAX_SIZE_MB

        public static final java.lang.String WRITE_CACHE_MAX_SIZE_MB
        See Also:
        Constant Field Values
      • READ_AHEAD_CACHE_MAX_SIZE_MB

        public static final java.lang.String READ_AHEAD_CACHE_MAX_SIZE_MB
        See Also:
        Constant Field Values
      • DIRECT_IO_ENTRYLOGGER

        public static final java.lang.String DIRECT_IO_ENTRYLOGGER
        See Also:
        Constant Field Values
      • DIRECT_IO_ENTRYLOGGER_TOTAL_WRITEBUFFER_SIZE_MB

        public static final java.lang.String DIRECT_IO_ENTRYLOGGER_TOTAL_WRITEBUFFER_SIZE_MB
        See Also:
        Constant Field Values
      • DIRECT_IO_ENTRYLOGGER_TOTAL_READBUFFER_SIZE_MB

        public static final java.lang.String DIRECT_IO_ENTRYLOGGER_TOTAL_READBUFFER_SIZE_MB
        See Also:
        Constant Field Values
      • DIRECT_IO_ENTRYLOGGER_READBUFFER_SIZE_MB

        public static final java.lang.String DIRECT_IO_ENTRYLOGGER_READBUFFER_SIZE_MB
        See Also:
        Constant Field Values
      • DIRECT_IO_ENTRYLOGGER_MAX_FD_CACHE_TIME_SECONDS

        public static final java.lang.String DIRECT_IO_ENTRYLOGGER_MAX_FD_CACHE_TIME_SECONDS
        See Also:
        Constant Field Values
      • MAX_THROTTLE_TIME_MILLIS

        static final java.lang.String MAX_THROTTLE_TIME_MILLIS
        See Also:
        Constant Field Values
      • READ_AHEAD_CACHE_BATCH_SIZE

        static final java.lang.String READ_AHEAD_CACHE_BATCH_SIZE
        See Also:
        Constant Field Values
      • READ_AHEAD_CACHE_BATCH_BYTES_SIZE

        static final java.lang.String READ_AHEAD_CACHE_BATCH_BYTES_SIZE
        See Also:
        Constant Field Values
      • allocator

        protected io.netty.buffer.ByteBufAllocator allocator
    • Constructor Detail

      • DbLedgerStorage

        public DbLedgerStorage()
    • Method Detail

      • 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
      • 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
      • 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,
                                BookieException
        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
        BookieException
      • 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
      • addEntry

        public long addEntry​(io.netty.buffer.ByteBuf entry)
                      throws java.io.IOException,
                             BookieException
        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
        BookieException
      • 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
      • 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
      • 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
      • deleteLedger

        public void deleteLedger​(long ledgerId)
                          throws java.io.IOException
        Specified by:
        deleteLedger in interface LedgerStorage
        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
      • addLedgerToIndex

        public long addLedgerToIndex​(long ledgerId,
                                     boolean isFenced,
                                     byte[] masterKey,
                                     LedgerCache.PageEntriesIterable pages)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getLastEntryInLedger

        public long getLastEntryInLedger​(long ledgerId)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getLocation

        public long getLocation​(long ledgerId,
                                long entryId)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getActiveLedgersInRange

        public java.lang.Iterable<java.lang.Long> getActiveLedgersInRange​(long firstLedgerId,
                                                                          long lastLedgerId)
                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getLastEntry

        public io.netty.buffer.ByteBuf getLastEntry​(long ledgerId)
                                             throws java.io.IOException,
                                                    BookieException
        Throws:
        java.io.IOException
        BookieException
      • isFlushRequired

        boolean isFlushRequired()
      • readLedgerIndexEntries

        public static void readLedgerIndexEntries​(long ledgerId,
                                                  ServerConfiguration serverConf,
                                                  SingleDirectoryDbLedgerStorage.LedgerLoggerProcessor processor)
                                           throws java.io.IOException
        Reads ledger index entries to get list of entry-logger that contains given ledgerId.
        Parameters:
        ledgerId -
        serverConf -
        processor -
        Throws:
        java.io.IOException
      • 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
      • entryLocationCompact

        public void entryLocationCompact​(java.util.List<java.lang.String> locations)
        Specified by:
        entryLocationCompact in interface LedgerStorage
      • isEntryLocationCompacting

        public java.util.Map<java.lang.String,​java.lang.Boolean> isEntryLocationCompacting​(java.util.List<java.lang.String> locations)
        Specified by:
        isEntryLocationCompacting in interface LedgerStorage
      • getLongVariableOrDefault

        static long getLongVariableOrDefault​(ServerConfiguration conf,
                                             java.lang.String keyName,
                                             long defaultValue)
      • getBooleanVariableOrDefault

        static boolean getBooleanVariableOrDefault​(ServerConfiguration conf,
                                                   java.lang.String keyName,
                                                   boolean defaultValue)
      • 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 flag)
                                 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 flag)
                                   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