Class BookieClientImpl

    • Constructor Detail

      • BookieClientImpl

        public BookieClientImpl​(ClientConfiguration conf,
                                io.netty.channel.EventLoopGroup eventLoopGroup,
                                io.netty.buffer.ByteBufAllocator allocator,
                                OrderedExecutor executor,
                                java.util.concurrent.ScheduledExecutorService scheduler,
                                StatsLogger statsLogger,
                                BookieAddressResolver bookieAddressResolver)
                         throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getFaultyBookies

        public java.util.List<BookieId> getFaultyBookies()
        Description copied from interface: BookieClient
        Get the list of bookies which have exhibited more error responses than a configured threshold.
        Specified by:
        getFaultyBookies in interface BookieClient
        Returns:
        the list of faulty bookies
      • isWritable

        public boolean isWritable​(BookieId address,
                                  long key)
        Description copied from interface: BookieClient
        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.

        Specified by:
        isWritable in interface BookieClient
        Parameters:
        address - the address of the bookie
        key - the ledger we wish to send a request to
      • getNumPendingRequests

        public long getNumPendingRequests​(BookieId address,
                                          long ledgerId)
        Description copied from interface: BookieClient
        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 BookieClient.PENDINGREQ_NOTWRITABLE_MASK will be logically or'd with the returned value.
        Specified by:
        getNumPendingRequests in interface BookieClient
        Parameters:
        address - the address of the bookie
        ledgerId - the ledger whose channel we wish to query
        Returns:
        the number of requests currently outstanding
      • forceLedger

        public void forceLedger​(BookieId addr,
                                long ledgerId,
                                BookkeeperInternalCallbacks.ForceLedgerCallback cb,
                                java.lang.Object ctx)
        Description copied from interface: BookieClient
        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.
        Specified by:
        forceLedger in interface BookieClient
        Parameters:
        addr - 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
      • writeLac

        public void writeLac​(BookieId addr,
                             long ledgerId,
                             byte[] masterKey,
                             long lac,
                             ByteBufList toSend,
                             BookkeeperInternalCallbacks.WriteLacCallback cb,
                             java.lang.Object ctx)
        Description copied from interface: BookieClient
        Explicitly write the last add confirmed for ledger ledgerId to the bookie at address.
        Specified by:
        writeLac in interface BookieClient
        Parameters:
        addr - 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

        public void addEntry​(BookieId addr,
                             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)
        Description copied from interface: BookieClient
        Add an entry for ledger ledgerId on the bookie at address address.
        Specified by:
        addEntry in interface BookieClient
        Parameters:
        addr - 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 BookieClient.isWritable(BookieId,long)
        writeFlags - a set of write flags WriteFlag
      • getListOfEntriesOfLedger

        public java.util.concurrent.CompletableFuture<AvailabilityOfEntriesOfLedger> getListOfEntriesOfLedger​(BookieId address,
                                                                                                              long ledgerId)
        Description copied from interface: BookieClient
        Makes async request for getting list of entries of ledger from a bookie and returns Future for the result.
        Specified by:
        getListOfEntriesOfLedger in interface BookieClient
        Parameters:
        address - BookieId of the bookie
        ledgerId - ledgerId
        Returns:
        returns Future
      • readLac

        public void readLac​(BookieId addr,
                            long ledgerId,
                            BookkeeperInternalCallbacks.ReadLacCallback cb,
                            java.lang.Object ctx)
        Description copied from interface: BookieClient
        Read the last add confirmed for ledger ledgerId from the bookie at address.
        Specified by:
        readLac in interface BookieClient
        Parameters:
        addr - 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
      • readEntry

        public void readEntry​(BookieId addr,
                              long ledgerId,
                              long entryId,
                              BookkeeperInternalCallbacks.ReadEntryCallback cb,
                              java.lang.Object ctx,
                              int flags,
                              byte[] masterKey,
                              boolean allowFastFail)
        Description copied from interface: BookieClient
        Read an entry from bookie at address address.
        Specified by:
        readEntry in interface BookieClient
        Parameters:
        addr - 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 BookieClient.isWritable(BookieId,long)
      • batchReadEntries

        public 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)
        Description copied from interface: BookieClient
        Batch read entries from bookie at address address.
        Specified by:
        batchReadEntries in interface BookieClient
        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 BookieClient.isWritable(BookieId,long)
      • readEntryWaitForLACUpdate

        public void readEntryWaitForLACUpdate​(BookieId addr,
                                              long ledgerId,
                                              long entryId,
                                              long previousLAC,
                                              long timeOutInMillis,
                                              boolean piggyBackEntry,
                                              BookkeeperInternalCallbacks.ReadEntryCallback cb,
                                              java.lang.Object ctx)
        Description copied from interface: BookieClient
        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.
        Specified by:
        readEntryWaitForLACUpdate in interface BookieClient
        Parameters:
        addr - 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
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface BookieClient
        Returns:
        whether bookie client object has been closed
      • close

        public void close()
        Description copied from interface: BookieClient
        Close the bookie client object.
        Specified by:
        close in interface BookieClient
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.NumberFormatException,
                                java.io.IOException,
                                java.lang.InterruptedException
        Parameters:
        args -
        Throws:
        java.io.IOException
        java.lang.NumberFormatException
        java.lang.InterruptedException