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
-
Field Summary
Fields Modifier and Type Field Description (package private) long
addEntryTimeoutNanos
(package private) io.netty.buffer.ByteBufAllocator
allocator
(package private) BookieAddressResolver
bookieAddressResolver
(package private) BookieId
bookieId
(package private) io.netty.channel.Channel
channel
(package private) java.util.concurrent.locks.ReentrantReadWriteLock
closeLock
(package private) static java.lang.String
CONSOLIDATION_HANDLER_NAME
(package private) io.netty.channel.EventLoopGroup
eventLoopGroup
(package private) OrderedExecutor
executor
(package private) long
getBookieInfoTimeoutNanos
(package private) static org.slf4j.Logger
LOG
(package private) int
maxFrameSize
(package private) long
readEntryTimeoutNanos
(package private) int
startTLSTimeout
(package private) PerChannelBookieClient.ConnectionState
state
-
Constructor Summary
Constructors Constructor Description PerChannelBookieClient(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) PerChannelBookieClient.AddCompletion
acquireAddCompletion(PerChannelBookieClient.CompletionKey key, BookkeeperInternalCallbacks.WriteCallback originalCallback, java.lang.Object originalCtx, long ledgerId, long entryId)
(package private) org.apache.bookkeeper.proto.PerChannelBookieClient.EntryCompletionKey
acquireV2Key(long ledgerId, long entryId, BookkeeperProtocol.OperationType operationType)
(package private) 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 forconnectIfNeededAndDoOp(GenericCallback)
.(package private) static BookkeeperProtocol.Request.Builder
appendRequestContext(BookkeeperProtocol.Request.Builder builder)
void
batchReadEntries(long ledgerId, long startEntryId, int maxCount, long maxSize, BookkeeperInternalCallbacks.BatchedReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey, boolean allowFastFail)
void
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
If our channel has disconnected, we just error out the pending entries.void
channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg)
Called by netty when a message is received on a channel.void
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)
void
checkTimeoutOnPendingOperations()
(package private) void
cleanDisconnectAndClose()
void
close()
Closes the bookie client permanently.void
close(boolean wait)
protected io.netty.channel.ChannelFuture
connect()
(package private) void
connectIfNeededAndDoOp(BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient> op)
(package private) io.netty.channel.ChannelFutureListener
contextPreservingListener(io.netty.channel.ChannelFutureListener listener)
void
disconnect()
Disconnects the bookie client.void
disconnect(boolean wait)
(package private) void
errorOut(PerChannelBookieClient.CompletionKey key)
(package private) void
errorOut(PerChannelBookieClient.CompletionKey key, int rc)
(package private) void
errorOutOutstandingEntries(int rc)
Errors out pending entries.(package private) void
errorOutPendingOps(int rc)
Errors out pending ops from per channel bookie client.void
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.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).(package private) void
forceLedger(long ledgerId, BookkeeperInternalCallbacks.ForceLedgerCallback cb, java.lang.Object ctx)
void
getBookieInfo(long requested, BookkeeperInternalCallbacks.GetBookieInfoCallback cb, java.lang.Object ctx)
void
getListOfEntriesOfLedger(long ledgerId, BookkeeperInternalCallbacks.GetListOfEntriesOfLedgerCallback cb)
protected long
getNumPendingCompletionRequests()
(package private) void
initTLSHandshake()
boolean
isWritable()
(package private) PerChannelBookieClient.CompletionKey
newCompletionKey(long txnId, BookkeeperProtocol.OperationType operationType)
void
readEntry(long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx, int flags, byte[] masterKey, boolean allowFastFail)
Normal Reads.void
readEntryWaitForLACUpdate(long ledgerId, long entryId, long previousLAC, long timeOutInMillis, boolean piggyBackEntry, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.Object ctx)
Long Poll Reads.void
readLac(long ledgerId, BookkeeperInternalCallbacks.ReadLacCallback cb, java.lang.Object ctx)
(package private) void
recordError()
void
setWritable(boolean val)
(package private) BookkeeperProtocol.Request.Builder
withRequestContext(BookkeeperProtocol.Request.Builder builder)
(package private) void
writeLac(long ledgerId, byte[] masterKey, long lac, ByteBufList toSend, BookkeeperInternalCallbacks.WriteLacCallback cb, java.lang.Object ctx)
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
-
-
-
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
-
bookieId
final BookieId bookieId
-
bookieAddressResolver
final BookieAddressResolver bookieAddressResolver
-
eventLoopGroup
final io.netty.channel.EventLoopGroup eventLoopGroup
-
allocator
final io.netty.buffer.ByteBufAllocator allocator
-
executor
final OrderedExecutor executor
-
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
-
state
volatile PerChannelBookieClient.ConnectionState state
-
closeLock
final java.util.concurrent.locks.ReentrantReadWriteLock closeLock
-
-
Constructor Detail
-
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 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)
-
connectIfNeededAndDoOp
void connectIfNeededAndDoOp(BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient> op)
-
writeLac
void writeLac(long ledgerId, byte[] masterKey, long lac, ByteBufList toSend, BookkeeperInternalCallbacks.WriteLacCallback cb, java.lang.Object ctx)
-
forceLedger
void forceLedger(long ledgerId, BookkeeperInternalCallbacks.ForceLedgerCallback cb, java.lang.Object ctx)
-
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 forconnectIfNeededAndDoOp(GenericCallback)
.- Parameters:
ledgerId
- Ledger IdmasterKey
- Master KeyentryId
- Entry IdtoSend
- Buffer to sendcb
- Write callbackctx
- Write callback contextallowFastFail
- allowFastFail flagwriteFlags
- WriteFlags
-
readLac
public void readLac(long ledgerId, BookkeeperInternalCallbacks.ReadLacCallback cb, java.lang.Object ctx)
-
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, java.lang.Object ctx)
Long Poll Reads.
-
readEntry
public void readEntry(long ledgerId, long entryId, BookkeeperInternalCallbacks.ReadEntryCallback cb, java.lang.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, java.lang.Object ctx, int flags, byte[] masterKey, boolean allowFastFail)
-
getBookieInfo
public void getBookieInfo(long requested, BookkeeperInternalCallbacks.GetBookieInfoCallback cb, java.lang.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
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelWritabilityChanged
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelWritabilityChanged
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
errorOut
void errorOut(PerChannelBookieClient.CompletionKey key)
-
errorOut
void errorOut(PerChannelBookieClient.CompletionKey key, int rc)
-
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 interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.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 interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.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 interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
initTLSHandshake
void initTLSHandshake()
-
acquireAddCompletion
PerChannelBookieClient.AddCompletion acquireAddCompletion(PerChannelBookieClient.CompletionKey key, BookkeeperInternalCallbacks.WriteCallback originalCallback, java.lang.Object originalCtx, long ledgerId, long entryId)
-
newCompletionKey
PerChannelBookieClient.CompletionKey newCompletionKey(long txnId, BookkeeperProtocol.OperationType operationType)
-
acquireV2Key
org.apache.bookkeeper.proto.PerChannelBookieClient.EntryCompletionKey acquireV2Key(long ledgerId, long entryId, BookkeeperProtocol.OperationType operationType)
-
withRequestContext
BookkeeperProtocol.Request.Builder withRequestContext(BookkeeperProtocol.Request.Builder builder)
-
appendRequestContext
static BookkeeperProtocol.Request.Builder appendRequestContext(BookkeeperProtocol.Request.Builder builder)
-
contextPreservingListener
io.netty.channel.ChannelFutureListener contextPreservingListener(io.netty.channel.ChannelFutureListener listener)
-
-