public class StreamSession extends java.lang.Object implements IEndpointStateChangeSubscriber
ConnectionHandler
that will create
two connections to the remote node (the follower in the following) with whom to stream and send
a StreamInit message. The first connection will be the incoming connection for the
initiator, and the second connection will be the outgoing.
(b) Upon reception of that StreamInit message, the follower creates its own StreamSession,
initialize it if it still does not exist, and attach connecting socket to its ConnectionHandler
according to StreamInit message's isForOutgoing flag.
(d) When the both incoming and outgoing connections are established, StreamSession calls
StreamSession#onInitializationComplete method to start the streaming prepare phase
(StreamResultFuture.startStreaming()).
2. Streaming preparation phase
(a) This phase is started when the initiator onInitializationComplete() method is called. This method sends a
PrepareMessage that includes what files/sections this node will stream to the follower
(stored in a StreamTransferTask, each column family has it's own transfer task) and what
the follower needs to stream back (StreamReceiveTask, same as above). If the initiator has
nothing to receive from the follower, it goes directly to its Streaming phase. Otherwise,
it waits for the follower PrepareMessage.
(b) Upon reception of the PrepareMessage, the follower records which files/sections it will receive
and send back its own PrepareMessage with a summary of the files/sections that will be sent to
the initiator (prepare()). After having sent that message, the follower goes to its Streamning
phase.
(c) When the initiator receives the follower PrepareMessage, it records which files/sections it will
receive and then goes to his own Streaming phase.
3. Streaming phase
(a) The streaming phase is started by each node (the sender in the follower, but note that each side
of the StreamSession may be sender for some of the files) involved by calling startStreamingFiles().
This will sequentially send a FileMessage for each file of each SteamTransferTask. Each FileMessage
consists of a FileMessageHeader that indicates which file is coming and then start streaming the
content for that file (StreamWriter in FileMessage.serialize()). When a file is fully sent, the
fileSent() method is called for that file. If all the files for a StreamTransferTask are sent
(StreamTransferTask.complete()), the task is marked complete (taskCompleted()).
(b) On the receiving side, a SSTable will be written for the incoming file (StreamReader in
FileMessage.deserialize()) and once the FileMessage is fully received, the file will be marked as
complete (received()). When all files for the StreamReceiveTask have been received, the sstables
are added to the CFS (and 2ndary index are built, StreamReceiveTask.complete()) and the task
is marked complete (taskCompleted())
(b) If during the streaming of a particular file an I/O error occurs on the receiving end of a stream
(FileMessage.deserialize), the node will retry the file (up to DatabaseDescriptor.getMaxStreamingRetries())
by sending a RetryMessage to the sender. On receiving a RetryMessage, the sender simply issue a new
FileMessage for that file.
(c) When all transfer and receive tasks for a session are complete, the move to the Completion phase
(maybeCompleted()).
4. Completion phase
(a) When a node has finished all transfer and receive task, it enter the completion phase (maybeCompleted()).
If it had already received a CompleteMessage from the other side (it is in the WAIT_COMPLETE state), that
session is done is is closed (closeSession()). Otherwise, the node switch to the WAIT_COMPLETE state and
send a CompleteMessage to the other side.Modifier and Type | Class and Description |
---|---|
static class |
StreamSession.SSTableStreamingSections |
static class |
StreamSession.State |
Modifier and Type | Field and Description |
---|---|
java.net.InetAddress |
connecting
Actual connecting address.
|
ConnectionHandler |
handler |
java.net.InetAddress |
peer
Streaming endpoint.
|
protected java.util.Set<StreamRequest> |
requests |
Constructor and Description |
---|
StreamSession(java.net.InetAddress peer,
java.net.InetAddress connecting,
StreamConnectionFactory factory,
int index,
boolean keepSSTableLevel,
boolean isIncremental)
Create new streaming session with the peer.
|
Modifier and Type | Method and Description |
---|---|
void |
addStreamRequest(java.lang.String keyspace,
java.util.Collection<Range<Token>> ranges,
java.util.Collection<java.lang.String> columnFamilies,
long repairedAt)
Request data fetch task to this session.
|
void |
addTransferFiles(java.util.Collection<StreamSession.SSTableStreamingSections> sstableDetails) |
void |
addTransferRanges(java.lang.String keyspace,
java.util.Collection<Range<Token>> ranges,
java.util.Collection<java.lang.String> columnFamilies,
boolean flushTables,
long repairedAt)
Set up transfer for specific keyspace/ranges/CFs
Used in repair - a streamed sstable in repair will be marked with the given repairedAt time
|
void |
beforeChange(java.net.InetAddress endpoint,
EndpointState currentState,
ApplicationState newStateKey,
VersionedValue newValue) |
void |
complete()
Check if session is completed on receiving
StreamMessage.Type.COMPLETE message. |
java.net.Socket |
createConnection() |
java.lang.String |
description() |
void |
doRetry(FileMessageHeader header,
java.lang.Throwable e) |
void |
fileSent(FileMessageHeader header)
Call back after sending FileMessageHeader.
|
SessionInfo |
getSessionInfo() |
LifecycleTransaction |
getTransaction(java.util.UUID cfId) |
void |
init(StreamResultFuture streamResult)
Bind this session to report to specific
StreamResultFuture and
perform pre-streaming initialization. |
boolean |
isIncremental() |
boolean |
isSuccess()
Return if this session completed successfully.
|
boolean |
keepSSTableLevel() |
void |
messageReceived(StreamMessage message) |
void |
onAlive(java.net.InetAddress endpoint,
EndpointState state) |
void |
onChange(java.net.InetAddress endpoint,
ApplicationState state,
VersionedValue value) |
void |
onDead(java.net.InetAddress endpoint,
EndpointState state) |
void |
onError(java.lang.Throwable e)
l
Call back for handling exception during streaming.
|
void |
onInitializationComplete()
Call back when connection initialization is complete to start the prepare phase.
|
void |
onJoin(java.net.InetAddress endpoint,
EndpointState epState)
Use to inform interested parties about the change in the state
for specified endpoint
|
void |
onRemove(java.net.InetAddress endpoint) |
void |
onRestart(java.net.InetAddress endpoint,
EndpointState epState)
Called whenever a node is restarted.
|
java.util.UUID |
planId() |
void |
prepare(java.util.Collection<StreamRequest> requests,
java.util.Collection<StreamSummary> summaries)
Prepare this session for sending/receiving files.
|
void |
progress(Descriptor desc,
ProgressInfo.Direction direction,
long bytes,
long total) |
void |
receive(IncomingFileMessage message)
Call back after receiving FileMessageHeader.
|
void |
received(java.util.UUID cfId,
int sequenceNumber) |
void |
retry(java.util.UUID cfId,
int sequenceNumber)
Call back on receiving
StreamMessage.Type.RETRY message. |
void |
sessionFailed()
Call back on receiving
StreamMessage.Type.SESSION_FAILED message. |
int |
sessionIndex() |
void |
start() |
StreamSession.State |
state() |
void |
state(StreamSession.State newState)
Set current state to
newState . |
void |
taskCompleted(StreamReceiveTask completedTask) |
void |
taskCompleted(StreamTransferTask completedTask) |
public final java.net.InetAddress peer
StreamSession
is identified by this InetAddress which is broadcast address of the node streaming.public final java.net.InetAddress connecting
protected final java.util.Set<StreamRequest> requests
public final ConnectionHandler handler
public StreamSession(java.net.InetAddress peer, java.net.InetAddress connecting, StreamConnectionFactory factory, int index, boolean keepSSTableLevel, boolean isIncremental)
peer
- Address of streaming peerconnecting
- Actual connecting addressfactory
- is used for establishing connectionpublic java.util.UUID planId()
public int sessionIndex()
public java.lang.String description()
public boolean keepSSTableLevel()
public boolean isIncremental()
public LifecycleTransaction getTransaction(java.util.UUID cfId)
public void init(StreamResultFuture streamResult)
StreamResultFuture
and
perform pre-streaming initialization.streamResult
- result to report topublic void start()
public java.net.Socket createConnection() throws java.io.IOException
java.io.IOException
public void addStreamRequest(java.lang.String keyspace, java.util.Collection<Range<Token>> ranges, java.util.Collection<java.lang.String> columnFamilies, long repairedAt)
keyspace
- Requesting keyspaceranges
- Ranges to retrieve datacolumnFamilies
- ColumnFamily names. Can be empty if requesting all CF under the keyspace.public void addTransferRanges(java.lang.String keyspace, java.util.Collection<Range<Token>> ranges, java.util.Collection<java.lang.String> columnFamilies, boolean flushTables, long repairedAt)
keyspace
- Transfer keyspaceranges
- Transfer rangescolumnFamilies
- Transfer ColumnFamiliesflushTables
- flush tables?repairedAt
- the time the repair started.public void addTransferFiles(java.util.Collection<StreamSession.SSTableStreamingSections> sstableDetails)
public void state(StreamSession.State newState)
newState
.newState
- new state to setpublic StreamSession.State state()
public boolean isSuccess()
public void messageReceived(StreamMessage message)
public void onInitializationComplete()
public void onError(java.lang.Throwable e)
e
- thrown exceptionpublic void prepare(java.util.Collection<StreamRequest> requests, java.util.Collection<StreamSummary> summaries)
public void fileSent(FileMessageHeader header)
header
- sent headerpublic void receive(IncomingFileMessage message)
message
- received filepublic void progress(Descriptor desc, ProgressInfo.Direction direction, long bytes, long total)
public void received(java.util.UUID cfId, int sequenceNumber)
public void retry(java.util.UUID cfId, int sequenceNumber)
StreamMessage.Type.RETRY
message.cfId
- ColumnFamily IDsequenceNumber
- Sequence number to indicate which file to stream againpublic void complete()
StreamMessage.Type.COMPLETE
message.public void sessionFailed()
StreamMessage.Type.SESSION_FAILED
message.public void doRetry(FileMessageHeader header, java.lang.Throwable e)
public SessionInfo getSessionInfo()
public void taskCompleted(StreamReceiveTask completedTask)
public void taskCompleted(StreamTransferTask completedTask)
public void onJoin(java.net.InetAddress endpoint, EndpointState epState)
IEndpointStateChangeSubscriber
onJoin
in interface IEndpointStateChangeSubscriber
endpoint
- endpoint for which the state change occurred.epState
- state that actually changed for the above endpoint.public void beforeChange(java.net.InetAddress endpoint, EndpointState currentState, ApplicationState newStateKey, VersionedValue newValue)
beforeChange
in interface IEndpointStateChangeSubscriber
public void onChange(java.net.InetAddress endpoint, ApplicationState state, VersionedValue value)
onChange
in interface IEndpointStateChangeSubscriber
public void onAlive(java.net.InetAddress endpoint, EndpointState state)
onAlive
in interface IEndpointStateChangeSubscriber
public void onDead(java.net.InetAddress endpoint, EndpointState state)
onDead
in interface IEndpointStateChangeSubscriber
public void onRemove(java.net.InetAddress endpoint)
onRemove
in interface IEndpointStateChangeSubscriber
public void onRestart(java.net.InetAddress endpoint, EndpointState epState)
IEndpointStateChangeSubscriber
state.isAlive() == false
as state
is from before the restarted node is marked up.onRestart
in interface IEndpointStateChangeSubscriber
Copyright © 2016 The Apache Software Foundation