Package org.apache.bookkeeper.proto
Class PerChannelBookieClient
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
org.apache.bookkeeper.proto.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classConnection listener.(package private) static enum(package private) static classDecorator to preserve MDC for connection listener.Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final OpStatsLoggerprotected final Counter(package private) final longprotected final OpStatsLogger(package private) final io.netty.buffer.ByteBufAllocator(package private) final BookieAddressResolver(package private) final BookieId(package private) io.netty.channel.Channel(package private) final ReentrantReadWriteLockprotected final ClientConfiguration(package private) static final String(package private) final io.netty.channel.EventLoopGroup(package private) final OrderedExecutorprotected final OpStatsLoggerprotected final OpStatsLoggerprotected final OpStatsLogger(package private) final longprotected final OpStatsLoggerprotected final OpStatsLoggerprotected final OpStatsLogger(package private) static final org.slf4j.Logger(package private) final intprotected final booleanprotected final OpStatsLoggerprotected final Counter(package private) final longprotected final OpStatsLoggerprotected final OpStatsLoggerprotected final OpStatsLoggerprotected final OpStatsLogger(package private) final intprotected final OpStatsLogger(package private) PerChannelBookieClient.ConnectionStateprotected final OpStatsLoggerprotected final OpStatsLogger -
Constructor Summary
ConstructorsConstructorDescriptionPerChannelBookieClient(OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, BookieId bookieId, ClientAuthProvider.Factory authProviderFactory, com.google.protobuf.ExtensionRegistry extRegistry, BookieAddressResolver bookieAddressResolver) PerChannelBookieClient(OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, BookieId addr, BookieAddressResolver bookieAddressResolver) PerChannelBookieClient(ClientConfiguration conf, OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, io.netty.buffer.ByteBufAllocator allocator, BookieId bookieId, StatsLogger parentStatsLogger, ClientAuthProvider.Factory authProviderFactory, com.google.protobuf.ExtensionRegistry extRegistry, PerChannelBookieClientPool pcbcPool, SecurityHandlerFactory shFactory, BookieAddressResolver bookieAddressResolver) PerChannelBookieClient(ClientConfiguration conf, OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, BookieId bookieId, StatsLogger parentStatsLogger, ClientAuthProvider.Factory authProviderFactory, com.google.protobuf.ExtensionRegistry extRegistry, PerChannelBookieClientPool pcbcPool, BookieAddressResolver bookieAddressResolver) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddChannelListeners(io.netty.channel.ChannelFuture future, long connectStartTime) (package private) voidaddEntry(long ledgerId, byte[] masterKey, long entryId, io.netty.util.ReferenceCounted toSend, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx, int options, boolean allowFastFail, EnumSet<WriteFlag> writeFlags) This method should be called only after connection has been checked forconnectIfNeededAndDoOp(GenericCallback).(package private) static BookkeeperProtocol.Request.BuildervoidbatchReadEntries(long ledgerId, long startEntryId, int maxCount, long maxSize, BookkeeperInternalCallbacks.BatchedReadEntryCallback cb, Object ctx, int flags, byte[] masterKey, boolean allowFastFail) voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) If our channel has disconnected, we just error out the pending entries.voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) Called by netty when a message is received on a channel.voidchannelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) void(package private) voidvoidclose()Closes the bookie client permanently.voidclose(boolean wait) protected io.netty.channel.ChannelFutureconnect()(package private) void(package private) io.netty.channel.ChannelFutureListenercontextPreservingListener(io.netty.channel.ChannelFutureListener listener) voidDisconnects the bookie client.voiddisconnect(boolean wait) (package private) voiderrorOut(CompletionKey key) (package private) voiderrorOut(CompletionKey key, int rc) (package private) voiderrorOutOutstandingEntries(int rc) Errors out pending entries.(package private) voiderrorOutPendingOps(int rc) Errors out pending ops from per channel bookie client.voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) Called by netty when an exception happens in one of the netty threads (mostly due to what we do in the netty threads).protected voidfailTLS(int rc) (package private) voidforceLedger(long ledgerId, BookkeeperInternalCallbacks.ForceLedgerCallback cb, Object ctx) voidgetBookieInfo(long requested, BookkeeperInternalCallbacks.GetBookieInfoCallback cb, Object ctx) voidgetListOfEntriesOfLedger(long ledgerId, BookkeeperInternalCallbacks.GetListOfEntriesOfLedgerCallback cb) protected long(package private) voidboolean(package private) CompletionKeynewCompletionKey(long txnId, BookkeeperProtocol.OperationType operationType) voidreadEntry(long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, Object ctx, int flags, byte[] masterKey, boolean allowFastFail) Normal Reads.voidreadEntryWaitForLACUpdate(long ledgerId, long entryId, long previousLAC, long timeOutInMillis, boolean piggyBackEntry, BookkeeperInternalCallbacks.ReadEntryCallback cb, Object ctx) Long Poll Reads.voidreadLac(long ledgerId, BookkeeperInternalCallbacks.ReadLacCallback cb, Object ctx) (package private) voidvoidsetWritable(boolean val) (package private) BookkeeperProtocol.Request.Builder(package private) voidwriteLac(long ledgerId, byte[] masterKey, long lac, ByteBufList toSend, BookkeeperInternalCallbacks.WriteLacCallback cb, Object ctx) Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
LOG
static final org.slf4j.Logger LOG -
EXPECTED_BK_OPERATION_ERRORS
-
CONSOLIDATION_HANDLER_NAME
- See Also:
-
bookieId
-
bookieAddressResolver
-
eventLoopGroup
final io.netty.channel.EventLoopGroup eventLoopGroup -
allocator
final io.netty.buffer.ByteBufAllocator allocator -
executor
-
addEntryTimeoutNanos
final long addEntryTimeoutNanos -
readEntryTimeoutNanos
final long readEntryTimeoutNanos -
maxFrameSize
final int maxFrameSize -
getBookieInfoTimeoutNanos
final long getBookieInfoTimeoutNanos -
startTLSTimeout
final int startTLSTimeout -
readEntryOpLogger
@StatsDoc(name="READ_ENTRY", help="channel stats of read entries requests") protected final OpStatsLogger readEntryOpLogger -
readTimeoutOpLogger
@StatsDoc(name="TIMEOUT_READ_ENTRY", help="timeout stats of read entries requests") protected final OpStatsLogger readTimeoutOpLogger -
addEntryOpLogger
@StatsDoc(name="ADD_ENTRY", help="channel stats of add entries requests") protected final OpStatsLogger addEntryOpLogger -
writeLacOpLogger
@StatsDoc(name="WRITE_LAC", help="channel stats of write_lac requests") protected final OpStatsLogger writeLacOpLogger -
forceLedgerOpLogger
@StatsDoc(name="FORCE", help="channel stats of force requests") protected final OpStatsLogger forceLedgerOpLogger -
readLacOpLogger
@StatsDoc(name="READ_LAC", help="channel stats of read_lac requests") protected final OpStatsLogger readLacOpLogger -
addTimeoutOpLogger
@StatsDoc(name="TIMEOUT_ADD_ENTRY", help="timeout stats of add entries requests") protected final OpStatsLogger addTimeoutOpLogger -
writeLacTimeoutOpLogger
@StatsDoc(name="TIMEOUT_WRITE_LAC", help="timeout stats of write_lac requests") protected final OpStatsLogger writeLacTimeoutOpLogger -
forceLedgerTimeoutOpLogger
@StatsDoc(name="TIMEOUT_FORCE", help="timeout stats of force requests") protected final OpStatsLogger forceLedgerTimeoutOpLogger -
readLacTimeoutOpLogger
@StatsDoc(name="TIMEOUT_READ_LAC", help="timeout stats of read_lac requests") protected final OpStatsLogger readLacTimeoutOpLogger -
getBookieInfoOpLogger
@StatsDoc(name="GET_BOOKIE_INFO", help="channel stats of get_bookie_info requests") protected final OpStatsLogger getBookieInfoOpLogger -
getBookieInfoTimeoutOpLogger
@StatsDoc(name="TIMEOUT_GET_BOOKIE_INFO", help="timeout stats of get_bookie_info requests") protected final OpStatsLogger getBookieInfoTimeoutOpLogger -
startTLSOpLogger
@StatsDoc(name="START_TLS", help="channel stats of start_tls requests") protected final OpStatsLogger startTLSOpLogger -
startTLSTimeoutOpLogger
@StatsDoc(name="TIMEOUT_START_TLS", help="timeout stats of start_tls requests") protected final OpStatsLogger startTLSTimeoutOpLogger -
getListOfEntriesOfLedgerCompletionOpLogger
-
getListOfEntriesOfLedgerCompletionTimeoutOpLogger
-
addEntryOutstanding
-
readEntryOutstanding
-
preserveMdcForTaskExecution
protected final boolean preserveMdcForTaskExecution -
channel
volatile io.netty.channel.Channel channel -
state
-
closeLock
-
conf
-
-
Constructor Details
-
PerChannelBookieClient
public PerChannelBookieClient(OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, BookieId addr, BookieAddressResolver bookieAddressResolver) throws SecurityException - Throws:
SecurityException
-
PerChannelBookieClient
public PerChannelBookieClient(OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, BookieId bookieId, ClientAuthProvider.Factory authProviderFactory, com.google.protobuf.ExtensionRegistry extRegistry, BookieAddressResolver bookieAddressResolver) throws SecurityException - Throws:
SecurityException
-
PerChannelBookieClient
public PerChannelBookieClient(ClientConfiguration conf, OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, BookieId bookieId, StatsLogger parentStatsLogger, ClientAuthProvider.Factory authProviderFactory, com.google.protobuf.ExtensionRegistry extRegistry, PerChannelBookieClientPool pcbcPool, BookieAddressResolver bookieAddressResolver) throws SecurityException - Throws:
SecurityException
-
PerChannelBookieClient
public PerChannelBookieClient(ClientConfiguration conf, OrderedExecutor executor, io.netty.channel.EventLoopGroup eventLoopGroup, io.netty.buffer.ByteBufAllocator allocator, BookieId bookieId, StatsLogger parentStatsLogger, ClientAuthProvider.Factory authProviderFactory, com.google.protobuf.ExtensionRegistry extRegistry, PerChannelBookieClientPool pcbcPool, SecurityHandlerFactory shFactory, BookieAddressResolver bookieAddressResolver) throws SecurityException - Throws:
SecurityException
-
-
Method Details
-
getNumPendingCompletionRequests
protected long getNumPendingCompletionRequests() -
connect
protected io.netty.channel.ChannelFuture connect() -
addChannelListeners
protected void addChannelListeners(io.netty.channel.ChannelFuture future, long connectStartTime) -
cleanDisconnectAndClose
void cleanDisconnectAndClose() -
isWritable
public boolean isWritable()- Returns:
- boolean, true is PCBC is writable
-
setWritable
public void setWritable(boolean val) -
connectIfNeededAndDoOp
-
writeLac
void writeLac(long ledgerId, byte[] masterKey, long lac, ByteBufList toSend, BookkeeperInternalCallbacks.WriteLacCallback cb, Object ctx) -
forceLedger
-
addEntry
void addEntry(long ledgerId, byte[] masterKey, long entryId, io.netty.util.ReferenceCounted toSend, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx, int options, boolean allowFastFail, EnumSet<WriteFlag> writeFlags) This method should be called only after connection has been checked forconnectIfNeededAndDoOp(GenericCallback).- Parameters:
ledgerId- Ledger IdmasterKey- Master KeyentryId- Entry IdtoSend- Buffer to sendcb- Write callbackctx- Write callback contextallowFastFail- allowFastFail flagwriteFlags- WriteFlags
-
readLac
-
getListOfEntriesOfLedger
public void getListOfEntriesOfLedger(long ledgerId, BookkeeperInternalCallbacks.GetListOfEntriesOfLedgerCallback cb) -
readEntryWaitForLACUpdate
public void readEntryWaitForLACUpdate(long ledgerId, long entryId, long previousLAC, long timeOutInMillis, boolean piggyBackEntry, BookkeeperInternalCallbacks.ReadEntryCallback cb, Object ctx) Long Poll Reads. -
readEntry
public void readEntry(long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, Object ctx, int flags, byte[] masterKey, boolean allowFastFail) Normal Reads. -
batchReadEntries
public void batchReadEntries(long ledgerId, long startEntryId, int maxCount, long maxSize, BookkeeperInternalCallbacks.BatchedReadEntryCallback cb, Object ctx, int flags, byte[] masterKey, boolean allowFastFail) -
getBookieInfo
public void getBookieInfo(long requested, BookkeeperInternalCallbacks.GetBookieInfoCallback cb, Object ctx) -
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
- Specified by:
channelWritabilityChangedin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelWritabilityChangedin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
errorOut
-
errorOut
-
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
If our channel has disconnected, we just error out the pending entries.- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws 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:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead
Called by netty when a message is received on a channel.- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
initTLSHandshake
void initTLSHandshake() -
newCompletionKey
-
withRequestContext
-
appendRequestContext
static BookkeeperProtocol.Request.Builder appendRequestContext(BookkeeperProtocol.Request.Builder builder) -
contextPreservingListener
io.netty.channel.ChannelFutureListener contextPreservingListener(io.netty.channel.ChannelFutureListener listener) -
failTLS
protected void failTLS(int rc)
-