Class BookieImpl

  • All Implemented Interfaces:
    Bookie
    Direct Known Subclasses:
    ReadOnlyBookie

    public class BookieImpl
    extends java.lang.Object
    implements Bookie
    Implements a bookie.
    • Field Detail

      • journalDirectories

        final java.util.List<java.io.File> journalDirectories
      • journals

        final java.util.List<Journal> journals
      • entryLogPerLedgerEnabled

        final boolean entryLogPerLedgerEnabled
      • METAENTRY_ID_LEDGER_KEY

        public static final long METAENTRY_ID_LEDGER_KEY
        See Also:
        Constant Field Values
      • METAENTRY_ID_FENCE_KEY

        public static final long METAENTRY_ID_FENCE_KEY
        See Also:
        Constant Field Values
      • METAENTRY_ID_FORCE_LEDGER

        public static final long METAENTRY_ID_FORCE_LEDGER
        See Also:
        Constant Field Values
      • METAENTRY_ID_LEDGER_EXPLICITLAC

        static final long METAENTRY_ID_LEDGER_EXPLICITLAC
        See Also:
        Constant Field Values
      • bookieServiceInfoProvider

        protected final java.util.function.Supplier<BookieServiceInfo> bookieServiceInfoProvider
      • shutdownTriggered

        java.util.concurrent.atomic.AtomicBoolean shutdownTriggered
      • lock

        java.util.concurrent.locks.ReentrantLock lock
    • Method Detail

      • checkDirectoryStructure

        public static void checkDirectoryStructure​(java.io.File dir)
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • getBookieId

        public static BookieId getBookieId​(ServerConfiguration conf)
                                    throws java.net.UnknownHostException
        Throws:
        java.net.UnknownHostException
      • getBookieAddress

        public static BookieSocketAddress getBookieAddress​(ServerConfiguration conf)
                                                    throws java.net.UnknownHostException
        Return the configured address of the bookie.
        Throws:
        java.net.UnknownHostException
      • getTotalDiskSpace

        public long getTotalDiskSpace()
                               throws java.io.IOException
        Specified by:
        getTotalDiskSpace in interface Bookie
        Throws:
        java.io.IOException
      • getTotalFreeSpace

        public long getTotalFreeSpace()
                               throws java.io.IOException
        Specified by:
        getTotalFreeSpace in interface Bookie
        Throws:
        java.io.IOException
      • getCurrentDirectory

        public static java.io.File getCurrentDirectory​(java.io.File dir)
      • getCurrentDirectories

        public static java.io.File[] getCurrentDirectories​(java.io.File[] dirs)
      • mountLedgerStorageOffline

        public static LedgerStorage mountLedgerStorageOffline​(ServerConfiguration conf,
                                                              LedgerStorage ledgerStorage)
                                                       throws java.io.IOException
        Initialize LedgerStorage instance without checkpointing for use within the shell and other RO users. ledgerStorage must not have already been initialized.

        The caller is responsible for disposing of the ledgerStorage object.

        Parameters:
        conf - Bookie config.
        ledgerStorage - Instance to initialize.
        Returns:
        Passed ledgerStorage instance
        Throws:
        java.io.IOException
      • initializeStateManager

        StateManager initializeStateManager()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • start

        public void start()
        Specified by:
        start in interface Bookie
      • join

        public void join()
                  throws java.lang.InterruptedException
        Specified by:
        join in interface Bookie
        Throws:
        java.lang.InterruptedException
      • isAlive

        public boolean isAlive()
      • isReadOnly

        public boolean isReadOnly()
        Specified by:
        isReadOnly in interface Bookie
      • isAvailableForHighPriorityWrites

        public boolean isAvailableForHighPriorityWrites()
        Check whether Bookie is available for high priority writes.
        Specified by:
        isAvailableForHighPriorityWrites in interface Bookie
        Returns:
        true if the bookie is able to take high priority writes.
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface Bookie
      • run

        public void run()
      • triggerBookieShutdown

        void triggerBookieShutdown​(int exitCode)
      • shutdown

        public int shutdown()
        Specified by:
        shutdown in interface Bookie
      • shutdown

        int shutdown​(int exitCode)
      • getLedgerForEntry

        LedgerDescriptor getLedgerForEntry​(io.netty.buffer.ByteBuf entry,
                                           byte[] masterKey)
                                    throws java.io.IOException,
                                           BookieException
        Retrieve the ledger descriptor for the ledger which entry should be added to. The LedgerDescriptor returned from this method should be eventually freed with #putHandle().
        Throws:
        BookieException - if masterKey does not match the master key of the ledger
        java.io.IOException
      • createMasterKeyEntry

        public io.netty.buffer.ByteBuf createMasterKeyEntry​(long ledgerId,
                                                            byte[] masterKey)
      • recoveryAddEntry

        public void recoveryAddEntry​(io.netty.buffer.ByteBuf entry,
                                     BookkeeperInternalCallbacks.WriteCallback cb,
                                     java.lang.Object ctx,
                                     byte[] masterKey)
                              throws java.io.IOException,
                                     BookieException,
                                     java.lang.InterruptedException
        Add entry to a ledger, even if the ledger has previous been fenced. This should only happen in bookie recovery or ledger recovery cases, where entries are being replicates so that they exist on a quorum of bookies. The corresponding client side call for this is not exposed to users.
        Specified by:
        recoveryAddEntry in interface Bookie
        Throws:
        java.io.IOException
        BookieException
        java.lang.InterruptedException
      • createExplicitLACEntry

        public io.netty.buffer.ByteBuf createExplicitLACEntry​(long ledgerId,
                                                              io.netty.buffer.ByteBuf explicitLac)
      • forceLedger

        public void forceLedger​(long ledgerId,
                                BookkeeperInternalCallbacks.WriteCallback cb,
                                java.lang.Object ctx)
        Force sync given 'ledgerId' entries on the journal to the disk. It works like a regular addEntry with ackBeforeSync=false. This is useful for ledgers with DEFERRED_SYNC write flag.
        Specified by:
        forceLedger in interface Bookie
      • fenceLedger

        public java.util.concurrent.CompletableFuture<java.lang.Boolean> fenceLedger​(long ledgerId,
                                                                                     byte[] masterKey)
                                                                              throws java.io.IOException,
                                                                                     BookieException
        Fences a ledger. From this point on, clients will be unable to write to this ledger. Only recoveryAddEntry will be able to add entries to the ledger. This method is idempotent. Once a ledger is fenced, it can never be unfenced. Fencing a fenced ledger has no effect.
        Specified by:
        fenceLedger in interface Bookie
        Returns:
        Throws:
        java.io.IOException
        BookieException
      • getAllocator

        public io.netty.buffer.ByteBufAllocator getAllocator()
      • format

        public static boolean format​(ServerConfiguration conf,
                                     boolean isInteractive,
                                     boolean force)
        Format the bookie server data.
        Parameters:
        conf - ServerConfiguration
        isInteractive - Whether format should ask prompt for confirmation if old data exists or not.
        force - If non interactive and force is true, then old data will be removed without confirm prompt.
        Returns:
        Returns true if the format is success else returns false
      • getExitCode

        public int getExitCode()
        Returns exit code - cause of failure.
        Specified by:
        getExitCode in interface Bookie
        Returns:
        ExitCode
      • getJournals

        public java.util.List<Journal> getJournals()