public class StreamSession extends java.lang.Object implements IEndpointStateChangeSubscriber
StreamSession
. A streaming
session has the following life-cycle:
1. Session Initialization (a) A node (the initiator in the following) create a newIn brief, the message passing looks like this (I for initiator, F for follwer):StreamSession
, initialize itinit(StreamResultFuture)
, and then start it (start()
). Starting a session causes aStreamInitMessage
to be sent. (b) Upon reception of thatStreamInitMessage
, the follower creates its ownStreamSession
, and initializes it if it still does not exist. (c) After the initiator sends theStreamInitMessage
, it invokesonInitializationComplete()
to start the streaming prepare phase. 2. Streaming preparation phase (a) APrepareSynMessage
is sent that includes a) what files/sections this node will stream to the follower (stored locally in aStreamTransferTask
, one for each table) and b) what the follower needs to stream back (stored locally in aStreamReceiveTask
, one for each table). (b) Upon reception of thePrepareSynMessage
, the follower records which files/sections it will receive and send back aPrepareSynAckMessage
, which contains a summary of the files/sections that will be sent to the initiator. (c) When the initiator receives thePrepareSynAckMessage
, it records which files/sections it will receive, and then goes to it's Streaming phase (see next section). If the intiator is to receive files, it sends aPrepareAckMessage
to the follower to indicate that it can start streaming to the initiator. (d) (Optional) If the follower receives aPrepareAckMessage
, it enters it's Streaming phase. 3. Streaming phase (a) The streaming phase is started at each node by callingStreamSession#startStreamingFiles(boolean)
. This will send, sequentially on each outbound streaming connection (seeStreamingMultiplexedChannel
), anOutgoingStreamMessage
for each stream in each of theStreamTransferTask
. EachOutgoingStreamMessage
consists of aStreamMessageHeader
that contains metadata about the stream, followed by the stream content itself. Once all the files for aStreamTransferTask
are sent, the task is marked completeStreamTransferTask.complete(int)
. (b) On the receiving side, the incoming data is written to disk, and once the stream is fully received, it will be marked as complete (StreamReceiveTask.received(IncomingStream)
). When all streams for theStreamReceiveTask
have been received, the data is added to the CFS (and 2ndary indexes/MV are built), and the task is marked complete (taskCompleted(StreamReceiveTask)
). (b) If during the streaming of a particular stream an error occurs on the receiving end of a stream (it may be either the initiator or the follower), the node will send aSessionFailedMessage
to the sender and close the stream session. (c) When all transfer and receive tasks for a session are complete, the session moves to the Completion phase (maybeCompleted()
). 4. Completion phase (a) When the initiator finishes streaming, it enters theStreamSession.State.WAIT_COMPLETE
state, and waits for the follower to send aCompleteMessage
once it finishes streaming too. Once theCompleteMessage
is received, initiator sets its own state toStreamSession.State.COMPLETE
and closes all channels attached to this session.
(session init) I: StreamInitMessage (session prepare) I: PrepareSynMessage F: PrepareSynAckMessage I: PrepareAckMessage (stream - this can happen in both directions) I: OutgoingStreamMessage F: ReceivedMessage (completion) F: CompleteMessageAll messages which derive from
StreamMessage
are sent by the standard internode messaging
(via MessagingService
, while the actual files themselves are sent by a special
"streaming" connection type. See StreamingMultiplexedChannel
for details. Because of the asynchronousModifier and Type | Class and Description |
---|---|
static interface |
StreamSession.MessageStateSink |
static class |
StreamSession.PrepareDirection |
static class |
StreamSession.State
State Transition:
|
Modifier and Type | Field and Description |
---|---|
InetAddressAndPort |
peer
Streaming endpoint.
|
protected java.util.Set<StreamRequest> |
requests |
static StreamSession.MessageStateSink |
sink |
protected java.util.concurrent.ConcurrentHashMap<TableId,StreamTransferTask> |
transfers |
Constructor and Description |
---|
StreamSession(StreamOperation streamOperation,
InetAddressAndPort peer,
StreamingChannel.Factory factory,
StreamingChannel controlChannel,
int messagingVersion,
boolean isFollower,
int index,
TimeUUID pendingRepair,
PreviewKind previewKind)
Create new streaming session with the peer.
|
Modifier and Type | Method and Description |
---|---|
void |
abort() |
void |
addStreamRequest(java.lang.String keyspace,
RangesAtEndpoint fullRanges,
RangesAtEndpoint transientRanges,
java.util.Collection<java.lang.String> columnFamilies)
Request data fetch task to this session.
|
boolean |
attachInbound(StreamingChannel channel)
Attach a channel to this session upon receiving the first inbound message.
|
boolean |
attachOutbound(StreamingChannel channel)
Attach a channel to this session upon sending the first outbound message.
|
void |
complete()
Check if session is completed on receiving
StreamMessage.Type.COMPLETE message. |
void |
countStreamedIn(boolean isEntireSSTable) |
static java.lang.String |
createLogTag(StreamSession session) |
static java.lang.String |
createLogTag(StreamSession session,
io.netty.channel.Channel channel) |
static java.lang.String |
createLogTag(StreamSession session,
java.lang.Object channelId) |
static java.lang.String |
createLogTag(StreamSession session,
StreamingChannel channel) |
StreamReceiver |
getAggregator(TableId tableId) |
StreamingMultiplexedChannel |
getChannel() |
int |
getNumRequests() |
int |
getNumTransfers() |
java.util.List<OutgoingStream> |
getOutgoingStreamsForRanges(RangesAtEndpoint replicas,
java.util.Collection<ColumnFamilyStore> stores,
TimeUUID pendingRepair,
PreviewKind previewKind) |
TimeUUID |
getPendingRepair() |
PreviewKind |
getPreviewKind() |
SessionInfo |
getSessionInfo() |
StreamOperation |
getStreamOperation() |
void |
init(StreamResultFuture streamResult)
Bind this session to report to specific
StreamResultFuture and
perform pre-streaming initialization. |
boolean |
isFailedOrAborted()
Return if this session was failed or aborted
|
boolean |
isFollower() |
boolean |
isPreview() |
boolean |
isSuccess()
Return if this session completed successfully.
|
void |
messageReceived(StreamMessage message) |
io.netty.util.concurrent.Future<?> |
onError(java.lang.Throwable e)
Signal an error to this stream session: if it's an EOF exception, it tries to understand if the socket was closed
after completion or because the peer was down, otherwise sends a
SessionFailedMessage and closes
the session as StreamSession.State.FAILED . |
void |
onInitializationComplete()
Call back when connection initialization is complete to start the prepare phase.
|
void |
onRemove(InetAddressAndPort endpoint) |
void |
onRestart(InetAddressAndPort endpoint,
EndpointState epState)
Called whenever a node is restarted.
|
TimeUUID |
planId() |
void |
prepare(java.util.Collection<StreamRequest> requests,
java.util.Collection<StreamSummary> summaries)
Prepare this session for sending/receiving files.
|
void |
prepareReceiving(StreamSummary summary) |
void |
progress(java.lang.String filename,
ProgressInfo.Direction direction,
long bytes,
long delta,
long total) |
void |
receive(IncomingStreamMessage message)
Call back after receiving a stream.
|
void |
received(TableId tableId,
int sequenceNumber) |
void |
sessionFailed()
Call back on receiving
StreamMessage.Type.SESSION_FAILED message. |
int |
sessionIndex() |
void |
sessionTimeout()
Call back on receiving
StreamMessage.Type.SESSION_FAILED message. |
void |
start()
invoked by the node that begins the stream session (it may be sending files, receiving files, or both)
|
StreamSession.State |
state() |
void |
state(StreamSession.State newState)
Set current state to
newState . |
StreamOperation |
streamOperation() |
void |
streamSent(OutgoingStreamMessage message)
Call back after sending StreamMessageHeader.
|
void |
taskCompleted(StreamReceiveTask completedTask) |
void |
taskCompleted(StreamTransferTask completedTask) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
beforeChange, onAlive, onChange, onDead, onJoin
public static volatile StreamSession.MessageStateSink sink
public final InetAddressAndPort peer
StreamSession
is identified by this InetAddressAndPort which is broadcast address of the node streaming.protected final java.util.Set<StreamRequest> requests
protected final java.util.concurrent.ConcurrentHashMap<TableId,StreamTransferTask> transfers
public StreamSession(StreamOperation streamOperation, InetAddressAndPort peer, StreamingChannel.Factory factory, @Nullable StreamingChannel controlChannel, int messagingVersion, boolean isFollower, int index, TimeUUID pendingRepair, PreviewKind previewKind)
public boolean isFollower()
public TimeUUID planId()
public int sessionIndex()
public StreamOperation streamOperation()
public StreamOperation getStreamOperation()
public TimeUUID getPendingRepair()
public boolean isPreview()
public PreviewKind getPreviewKind()
public StreamReceiver getAggregator(TableId tableId)
public void init(StreamResultFuture streamResult)
StreamResultFuture
and
perform pre-streaming initialization.streamResult
- result to report topublic boolean attachInbound(StreamingChannel channel)
channel
- The channel to attach.public boolean attachOutbound(StreamingChannel channel)
channel
- The channel to attach.public void start()
public void addStreamRequest(java.lang.String keyspace, RangesAtEndpoint fullRanges, RangesAtEndpoint transientRanges, java.util.Collection<java.lang.String> columnFamilies)
keyspace
- Requesting keyspacefullRanges
- Ranges to retrieve data that will return full data from the sourcetransientRanges
- Ranges to retrieve data that will return transient data from the sourcecolumnFamilies
- ColumnFamily names. Can be empty if requesting all CF under the keyspace.public java.util.List<OutgoingStream> getOutgoingStreamsForRanges(RangesAtEndpoint replicas, java.util.Collection<ColumnFamilyStore> stores, TimeUUID pendingRepair, PreviewKind previewKind)
public void state(StreamSession.State newState)
newState
.newState
- new state to setpublic StreamSession.State state()
public StreamingMultiplexedChannel getChannel()
public boolean isSuccess()
public boolean isFailedOrAborted()
public void messageReceived(StreamMessage message)
public void onInitializationComplete()
public io.netty.util.concurrent.Future<?> onError(java.lang.Throwable e)
SessionFailedMessage
and closes
the session as StreamSession.State.FAILED
.public void prepare(java.util.Collection<StreamRequest> requests, java.util.Collection<StreamSummary> summaries)
public void countStreamedIn(boolean isEntireSSTable)
public void streamSent(OutgoingStreamMessage message)
message
- sent stream messagepublic void receive(IncomingStreamMessage message)
message
- received streampublic void progress(java.lang.String filename, ProgressInfo.Direction direction, long bytes, long delta, long total)
public void received(TableId tableId, int sequenceNumber)
public void complete()
StreamMessage.Type.COMPLETE
message.public void sessionFailed()
StreamMessage.Type.SESSION_FAILED
message.public void sessionTimeout()
StreamMessage.Type.SESSION_FAILED
message.public SessionInfo getSessionInfo()
public void taskCompleted(StreamReceiveTask completedTask)
public void taskCompleted(StreamTransferTask completedTask)
public void onRemove(InetAddressAndPort endpoint)
onRemove
in interface IEndpointStateChangeSubscriber
public void onRestart(InetAddressAndPort endpoint, EndpointState epState)
IEndpointStateChangeSubscriber
state.isAlive() == false
as state
is from before the restarted node is marked up.onRestart
in interface IEndpointStateChangeSubscriber
public void prepareReceiving(StreamSummary summary)
public int getNumRequests()
public int getNumTransfers()
public static java.lang.String createLogTag(StreamSession session)
public static java.lang.String createLogTag(StreamSession session, StreamingChannel channel)
public static java.lang.String createLogTag(StreamSession session, io.netty.channel.Channel channel)
public static java.lang.String createLogTag(StreamSession session, java.lang.Object channelId)
public void abort()
Copyright © 2009- The Apache Software Foundation