Interface BookieClient

  • All Known Implementing Classes:
    BookieClientImpl

    public interface BookieClient
    Low level client for talking to bookies.
    • Field Detail

      • PENDINGREQ_NOTWRITABLE_MASK

        static final long PENDINGREQ_NOTWRITABLE_MASK
        See Also:
        Constant Field Values
    • Method Detail

      • getFaultyBookies

        java.util.List<BookieId> getFaultyBookies()
        Get the list of bookies which have exhibited more error responses than a configured threshold.
        Returns:
        the list of faulty bookies
      • isWritable

        boolean isWritable​(BookieId address,
                           long ledgerId)
        Check whether the channel used to write to a bookie channel is writable. A channel becomes non-writable when its buffer become full, and will stay non-writable until some of the buffer is cleared.

        This can be used to apply backpressure. If a channel is not writable, requests will end up queuing.

        As as we use pooling, there may be multiple channels per bookie, so we also pass the ledger ID to check the writability of the correct channel.

        This has nothing to do with the bookie read-only status.

        Parameters:
        address - the address of the bookie
        ledgerId - the ledger we wish to send a request to
      • getNumPendingRequests

        long getNumPendingRequests​(BookieId address,
                                   long ledgerId)
        Get the number of outstanding requests on the channel used to connect to a bookie at address for a ledger with ledgerId. It is necessary to specify the ledgerId as there may be multiple channels for a single bookie if pooling is in use. If the bookie is not writable, then the PENDINGREQ_NOTWRITABLE_MASK will be logically or'd with the returned value.
        Parameters:
        address - the address of the bookie
        ledgerId - the ledger whose channel we wish to query
        Returns:
        the number of requests currently outstanding
      • forceLedger

        void forceLedger​(BookieId address,
                         long ledgerId,
                         BookkeeperInternalCallbacks.ForceLedgerCallback cb,
                         java.lang.Object ctx)
        Send a force request to the server. When complete all entries which have been written for ledgerId to this bookie will be persisted on disk. This is for use with WriteFlag.DEFERRED_SYNC.
        Parameters:
        address - the address of the bookie
        ledgerId - the ledger whose entries we want persisted
        cb - the callback notified when the request completes
        ctx - a context object passed to the callback on completion
      • readLac

        void readLac​(BookieId address,
                     long ledgerId,
                     BookkeeperInternalCallbacks.ReadLacCallback cb,
                     java.lang.Object ctx)
        Read the last add confirmed for ledger ledgerId from the bookie at address.
        Parameters:
        address - the address of the bookie
        ledgerId - the ledger whose last add confirm we wish to know
        cb - the callback notified when the request completes
        ctx - a context object passed to the callback on completion
      • writeLac

        void writeLac​(BookieId address,
                      long ledgerId,
                      byte[] masterKey,
                      long lac,
                      ByteBufList toSend,
                      BookkeeperInternalCallbacks.WriteLacCallback cb,
                      java.lang.Object ctx)
        Explicitly write the last add confirmed for ledger ledgerId to the bookie at address.
        Parameters:
        address - the address of the bookie
        ledgerId - the ledger whose last add confirm we wish to know
        masterKey - the master key of the ledger
        lac - the last add confirmed we wish to write
        toSend - a buffer also containing the lac, along with a digest
        cb - the callback notified when the request completes
        ctx - a context object passed to the callback on completion
      • addEntry

        void addEntry​(BookieId address,
                      long ledgerId,
                      byte[] masterKey,
                      long entryId,
                      io.netty.util.ReferenceCounted toSend,
                      BookkeeperInternalCallbacks.WriteCallback cb,
                      java.lang.Object ctx,
                      int options,
                      boolean allowFastFail,
                      java.util.EnumSet<WriteFlag> writeFlags)
        Add an entry for ledger ledgerId on the bookie at address address.
        Parameters:
        address - the address of the bookie
        ledgerId - the ledger to which we wish to add the entry
        entryId - the id of the entry we wish to add
        toSend - a buffer containing the entry and its digest
        cb - the callback notified when the request completes
        ctx - a context object passed to the callback on completion
        options - a bit mask of flags from BookieProtocol.FLAG_* BookieProtocol
        allowFastFail - fail the add immediately if the channel is non-writable isWritable(BookieId,long)
        writeFlags - a set of write flags WriteFlag
      • readEntry

        void readEntry​(BookieId address,
                       long ledgerId,
                       long entryId,
                       BookkeeperInternalCallbacks.ReadEntryCallback cb,
                       java.lang.Object ctx,
                       int flags,
                       byte[] masterKey,
                       boolean allowFastFail)
        Read an entry from bookie at address address.
        Parameters:
        address - address of the bookie to read from
        ledgerId - id of the ledger the entry belongs to
        entryId - id of the entry we wish to read
        cb - the callback notified when the request completes
        ctx - a context object passed to the callback on completion
        flags - a bit mask of flags from BookieProtocol.FLAG_* BookieProtocol
        masterKey - the master key of the ledger being read from. This is only required if the FLAG_DO_FENCING is specified.
        allowFastFail - fail the read immediately if the channel is non-writable isWritable(BookieId,long)
      • batchReadEntries

        void batchReadEntries​(BookieId address,
                              long ledgerId,
                              long startEntryId,
                              int maxCount,
                              long maxSize,
                              BookkeeperInternalCallbacks.BatchedReadEntryCallback cb,
                              java.lang.Object ctx,
                              int flags,
                              byte[] masterKey,
                              boolean allowFastFail)
        Batch read entries from bookie at address address.
        Parameters:
        address - address of the bookie to read from
        ledgerId - id of the ledger the entry belongs to
        startEntryId - id of the entry started
        maxCount - the total entries count in this batch
        maxSize - the total entries size in this batch
        cb - the callback notified when the request completes
        ctx - a context object passed to the callback on completion
        flags - a bit mask of flags from BookieProtocol.FLAG_* BookieProtocol
        masterKey - the master key of the ledger being read from. This is only required if the FLAG_DO_FENCING is specified.
        allowFastFail - fail the read immediately if the channel is non-writable isWritable(BookieId,long)
      • readEntryWaitForLACUpdate

        void readEntryWaitForLACUpdate​(BookieId address,
                                       long ledgerId,
                                       long entryId,
                                       long previousLAC,
                                       long timeOutInMillis,
                                       boolean piggyBackEntry,
                                       BookkeeperInternalCallbacks.ReadEntryCallback cb,
                                       java.lang.Object ctx)
        Send a long poll request to bookie, waiting for the last add confirmed to be updated. The client can also request that the full entry is returned with the new last add confirmed.
        Parameters:
        address - address of bookie to send the long poll address to
        ledgerId - ledger whose last add confirmed we are interested in
        entryId - the id of the entry we expect to read
        previousLAC - the previous lac value
        timeOutInMillis - number of millis to wait for LAC update
        piggyBackEntry - whether to read the requested entry when LAC is updated
        cb - the callback notified when the request completes
        ctx - a context object passed to the callback on completion
      • getListOfEntriesOfLedger

        java.util.concurrent.CompletableFuture<AvailabilityOfEntriesOfLedger> getListOfEntriesOfLedger​(BookieId address,
                                                                                                       long ledgerId)
        Makes async request for getting list of entries of ledger from a bookie and returns Future for the result.
        Parameters:
        address - BookieId of the bookie
        ledgerId - ledgerId
        Returns:
        returns Future
      • isClosed

        boolean isClosed()
        Returns:
        whether bookie client object has been closed
      • close

        void close()
        Close the bookie client object.