Search in sources :

Example 1 with StreamInitMessage

use of org.apache.cassandra.streaming.messages.StreamInitMessage in project cassandra by apache.

the class IncomingStreamingConnection method run.

@Override
// Not closing constructed DataInputPlus's as the stream needs to remain open.
@SuppressWarnings("resource")
public void run() {
    try {
        // we can't do anything with a wrong-version stream connection, so drop it.
        if (version != StreamMessage.CURRENT_VERSION)
            throw new IOException(String.format("Received stream using protocol version %d (my version %d). Terminating connection", version, StreamMessage.CURRENT_VERSION));
        DataInputPlus input = new DataInputStreamPlus(socket.getInputStream());
        StreamInitMessage init = StreamInitMessage.serializer.deserialize(input, version);
        //Set SO_TIMEOUT on follower side
        if (!init.isForOutgoing)
            socket.setSoTimeout(DatabaseDescriptor.getStreamingSocketTimeout());
        // The initiator makes two connections, one for incoming and one for outgoing.
        // The receiving side distinguish two connections by looking at StreamInitMessage#isForOutgoing.
        // Note: we cannot use the same socket for incoming and outgoing streams because we want to
        // parallelize said streams and the socket is blocking, so we might deadlock.
        StreamResultFuture.initReceivingSide(init.sessionIndex, init.planId, init.description, init.from, this, init.isForOutgoing, version, init.keepSSTableLevel, init.isIncremental, init.pendingRepair);
    } catch (Throwable t) {
        logger.error("Error while reading from socket from {}.", socket.getRemoteSocketAddress(), t);
        close();
    }
}
Also used : DataInputStreamPlus(org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) StreamInitMessage(org.apache.cassandra.streaming.messages.StreamInitMessage) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)1 DataInputStreamPlus (org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus)1 StreamInitMessage (org.apache.cassandra.streaming.messages.StreamInitMessage)1