Package org.apache.cassandra.transport
Class CQLMessageHandler<M extends Message>
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
org.apache.cassandra.net.AbstractMessageHandler
org.apache.cassandra.transport.CQLMessageHandler<M>
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,FrameDecoder.FrameProcessor
Implementation of
AbstractMessageHandler for processing CQL messages which comprise a Message wrapped
in an Envelope. This class is parameterized by a Message subtype, expected to be either
Message.Request or Message.Response. Most commonly, an instance for handling Message.Request
is created for each inbound CQL client connection.
# Small vs large messages
Small messages are deserialized in place, and then handed off to a consumer for processing.
Large messages accumulate frames until all bytes for the envelope are received, then concatenate and deserialize the
frames on the event loop thread and pass them on to the same consumer.
# Flow control (backpressure)
The size of an incoming message is explicit in the Envelope.Header.
By default, every connection has 1MiB of exlusive permits available before needing to access the per-endpoint
and global reserves. By default, those reserves are sized proportionally to the heap - 2.5% of heap per-endpoint
and a 10% for the global reserve.
Permits are held while CQL messages are processed and released after the response has been encoded into the
buffers of the response frame.
A connection level option (THROW_ON_OVERLOAD) allows clients to choose the backpressure strategy when a connection
has exceeded the maximum number of allowed permits. The choices are to either pause reads from the incoming socket
and allow TCP backpressure to do the work, or to throw an explict exception and rely on the client to back off.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.cassandra.net.AbstractMessageHandler
AbstractMessageHandler.OnHandlerClosed, AbstractMessageHandler.WaitQueueNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsFields inherited from class org.apache.cassandra.net.AbstractMessageHandler
channel, corruptFramesRecovered, corruptFramesUnrecovered, decoder, endpointReserveCapacity, endpointWaitQueue, globalReserveCapacity, globalWaitQueue, largeMessage, largeThreshold, onClosed, queueCapacity, receivedBytes, receivedCount, throttledCount, throttledNanos -
Method Summary
Modifier and TypeMethodDescriptionstatic OverloadedExceptionbuildOverloadedException(Supplier<String> endpointLimits, NonBlockingRateLimiter requestRateLimiter, ClientResourceLimits.Overload overload) static OverloadedExceptionbuildOverloadedException(ResourceLimits.Limit endpointReserve, ResourceLimits.Limit globalReserve, NonBlockingRateLimiter requestRateLimiter, ClientResourceLimits.Overload overload) protected voidfatalExceptionCaught(Throwable cause) protected Stringid()booleanprocess(FrameDecoder.Frame frame) Frame processor that the frames should be handed off to.protected voidprotected booleanprocessFirstFrameOfLargeMessage(FrameDecoder.IntactFrame frame, ResourceLimits.Limit endpointReserve, ResourceLimits.Limit globalReserve) protected booleanprocessOneContainedMessage(ShareableBytes bytes, ResourceLimits.Limit endpointReserve, ResourceLimits.Limit globalReserve) Checks limits on bytes in flight and the request rate limiter (if enabled), then takes one of three actions: 1.) If no limits are breached, process the request.protected booleanprocessRequest(Envelope request, ClientResourceLimits.Overload backpressure) Methods inherited from class org.apache.cassandra.net.AbstractMessageHandler
acquireCapacity, acquireCapacity, channelInactive, channelRead, handlerAdded, processSubsequentFrameOfLargeMessage, processUpToOneMessage, releaseCapacity, releaseProcessedCapacityMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, 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
handlerRemoved
-
Field Details
-
LARGE_MESSAGE_THRESHOLD
public static final int LARGE_MESSAGE_THRESHOLD- See Also:
-
RATE_LIMITER_DELAY_UNIT
-
-
Method Details
-
process
Description copied from interface:FrameDecoder.FrameProcessorFrame processor that the frames should be handed off to.- Specified by:
processin interfaceFrameDecoder.FrameProcessor- Overrides:
processin classAbstractMessageHandler- Returns:
- true if more frames can be taken by the processor, false if the decoder should pause until it's explicitly resumed.
- Throws:
IOException
-
buildOverloadedException
public static OverloadedException buildOverloadedException(ResourceLimits.Limit endpointReserve, ResourceLimits.Limit globalReserve, NonBlockingRateLimiter requestRateLimiter, ClientResourceLimits.Overload overload) -
buildOverloadedException
public static OverloadedException buildOverloadedException(Supplier<String> endpointLimits, NonBlockingRateLimiter requestRateLimiter, ClientResourceLimits.Overload overload) -
processRequest
-
processFirstFrameOfLargeMessage
protected boolean processFirstFrameOfLargeMessage(FrameDecoder.IntactFrame frame, ResourceLimits.Limit endpointReserve, ResourceLimits.Limit globalReserve) throws IOException - Specified by:
processFirstFrameOfLargeMessagein classAbstractMessageHandler- Throws:
IOException
-
id
- Specified by:
idin classAbstractMessageHandler
-
processCorruptFrame
- Specified by:
processCorruptFramein classAbstractMessageHandler
-
fatalExceptionCaught
- Specified by:
fatalExceptionCaughtin classAbstractMessageHandler
-