Class BookieImpl

  • All Implemented Interfaces:
    java.lang.Runnable, java.lang.Thread.UncaughtExceptionHandler, Bookie
    Direct Known Subclasses:
    ReadOnlyBookie

    public class BookieImpl
    extends BookieCriticalThread
    implements Bookie
    Implements a bookie.
    • 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
        Overrides:
        start in class java.lang.Thread
      • 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()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • 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
      • 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
      • 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