Class PerChannelBookieClient

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

    @StatsDoc(name="per_channel_bookie_client",
              help="Per channel bookie client stats")
    @Sharable
    public class PerChannelBookieClient
    extends io.netty.channel.ChannelInboundHandlerAdapter
    This class manages all details of connection to a particular bookie. It also has reconnect logic if a connection to a bookie fails.
    • Field Detail

      • LOG

        static final org.slf4j.Logger LOG
      • CONSOLIDATION_HANDLER_NAME

        static final java.lang.String CONSOLIDATION_HANDLER_NAME
        See Also:
        Constant Field Values
      • eventLoopGroup

        final io.netty.channel.EventLoopGroup eventLoopGroup
      • allocator

        final io.netty.buffer.ByteBufAllocator allocator
      • addEntryTimeoutNanos

        final long addEntryTimeoutNanos
      • readEntryTimeoutNanos

        final long readEntryTimeoutNanos
      • maxFrameSize

        final int maxFrameSize
      • getBookieInfoTimeoutNanos

        final long getBookieInfoTimeoutNanos
      • startTLSTimeout

        final int startTLSTimeout
      • channel

        volatile io.netty.channel.Channel channel
      • closeLock

        final java.util.concurrent.locks.ReentrantReadWriteLock closeLock
    • Method Detail

      • getNumPendingCompletionRequests

        protected long getNumPendingCompletionRequests()
      • connect

        protected io.netty.channel.ChannelFuture connect()
      • cleanDisconnectAndClose

        void cleanDisconnectAndClose()
      • isWritable

        public boolean isWritable()
        Returns:
        boolean, true is PCBC is writable
      • setWritable

        public void setWritable​(boolean val)
      • addEntry

        void addEntry​(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)
        This method should be called only after connection has been checked for connectIfNeededAndDoOp(GenericCallback).
        Parameters:
        ledgerId - Ledger Id
        masterKey - Master Key
        entryId - Entry Id
        toSend - Buffer to send
        cb - Write callback
        ctx - Write callback context
        allowFastFail - allowFastFail flag
        writeFlags - WriteFlags
      • readEntryWaitForLACUpdate

        public void readEntryWaitForLACUpdate​(long ledgerId,
                                              long entryId,
                                              long previousLAC,
                                              long timeOutInMillis,
                                              boolean piggyBackEntry,
                                              BookkeeperInternalCallbacks.ReadEntryCallback cb,
                                              java.lang.Object ctx)
        Long Poll Reads.
      • checkTimeoutOnPendingOperations

        public void checkTimeoutOnPendingOperations()
      • disconnect

        public void disconnect()
        Disconnects the bookie client. It can be reused.
      • disconnect

        public void disconnect​(boolean wait)
      • close

        public void close()
        Closes the bookie client permanently. It cannot be reused.
      • close

        public void close​(boolean wait)
      • channelWritabilityChanged

        public void channelWritabilityChanged​(io.netty.channel.ChannelHandlerContext ctx)
                                       throws java.lang.Exception
        Specified by:
        channelWritabilityChanged in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelWritabilityChanged in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        java.lang.Exception
      • errorOutPendingOps

        void errorOutPendingOps​(int rc)
        Errors out pending ops from per channel bookie client. As the channel is being closed, all the operations waiting on the connection will be sent to completion with error.
      • errorOutOutstandingEntries

        void errorOutOutstandingEntries​(int rc)
        Errors out pending entries. We call this method from one thread to avoid concurrent executions to QuorumOpMonitor (implements callbacks). It seems simpler to call it from BookieHandle instead of calling directly from here.
      • recordError

        void recordError()
      • channelInactive

        public void channelInactive​(io.netty.channel.ChannelHandlerContext ctx)
                             throws java.lang.Exception
        If our channel has disconnected, we just error out the pending entries.
        Specified by:
        channelInactive in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        java.lang.Exception
      • exceptionCaught

        public void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx,
                                    java.lang.Throwable cause)
                             throws java.lang.Exception
        Called by netty when an exception happens in one of the netty threads (mostly due to what we do in the netty threads).
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelHandler
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        java.lang.Exception
      • channelRead

        public void channelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                java.lang.Object msg)
                         throws java.lang.Exception
        Called by netty when a message is received on a channel.
        Specified by:
        channelRead in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        java.lang.Exception
      • initTLSHandshake

        void initTLSHandshake()
      • acquireV2Key

        org.apache.bookkeeper.proto.PerChannelBookieClient.EntryCompletionKey acquireV2Key​(long ledgerId,
                                                                                           long entryId,
                                                                                           BookkeeperProtocol.OperationType operationType)
      • contextPreservingListener

        io.netty.channel.ChannelFutureListener contextPreservingListener​(io.netty.channel.ChannelFutureListener listener)