Search in sources :

Example 1 with OutgoingStreamMessage

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

the class StreamTransferTask method complete.

/**
 * Received ACK for stream at {@code sequenceNumber}.
 *
 * @param sequenceNumber sequence number of stream
 */
public void complete(int sequenceNumber) {
    boolean signalComplete;
    synchronized (this) {
        ScheduledFuture timeout = timeoutTasks.remove(sequenceNumber);
        if (timeout != null)
            timeout.cancel(false);
        OutgoingStreamMessage stream = streams.remove(sequenceNumber);
        if (stream != null)
            stream.complete();
        logger.debug("received sequenceNumber {}, remaining files {}", sequenceNumber, streams.keySet());
        signalComplete = streams.isEmpty();
    }
    // all file sent, notify session this task is complete.
    if (signalComplete)
        session.taskCompleted(this);
}
Also used : OutgoingStreamMessage(org.apache.cassandra.streaming.messages.OutgoingStreamMessage) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 2 with OutgoingStreamMessage

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

the class StreamTransferTask method addTransferStream.

public synchronized void addTransferStream(OutgoingStream stream) {
    Preconditions.checkArgument(tableId.equals(stream.getTableId()));
    OutgoingStreamMessage message = new OutgoingStreamMessage(tableId, session, stream, sequenceNumber.getAndIncrement());
    message = StreamHook.instance.reportOutgoingStream(session, stream, message);
    streams.put(message.header.sequenceNumber, message);
    totalSize += message.stream.getEstimatedSize();
    totalFiles += message.stream.getNumFiles();
}
Also used : OutgoingStreamMessage(org.apache.cassandra.streaming.messages.OutgoingStreamMessage)

Example 3 with OutgoingStreamMessage

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

the class StreamingMultiplexedChannel method sendMessage.

public Future<?> sendMessage(StreamingChannel channel, StreamMessage message) {
    if (closed)
        throw new RuntimeException("stream has been closed, cannot send " + message);
    if (message instanceof OutgoingStreamMessage) {
        if (session.isPreview())
            throw new RuntimeException("Cannot send stream data messages for preview streaming sessions");
        if (logger.isDebugEnabled())
            logger.debug("{} Sending {}", createLogTag(session), message);
        return fileTransferExecutor.submit(new FileStreamTask((OutgoingStreamMessage) message));
    }
    try {
        Future<?> promise = channel.send(outSupplier -> {
            // we anticipate that the control messages are rather small, so allocating a ByteBuf shouldn't  blow out of memory.
            long messageSize = serializedSize(message, messagingVersion);
            if (messageSize > 1 << 30) {
                throw new IllegalStateException(format("%s something is seriously wrong with the calculated stream control message's size: %d bytes, type is %s", createLogTag(session, controlChannel.id()), messageSize, message.type));
            }
            try (StreamingDataOutputPlus out = outSupplier.apply((int) messageSize)) {
                StreamMessage.serialize(message, out, messagingVersion, session);
            }
        });
        promise.addListener(future -> onMessageComplete(future, message));
        return promise;
    } catch (Exception e) {
        close();
        session.onError(e);
        return ImmediateFuture.failure(e);
    }
}
Also used : OutgoingStreamMessage(org.apache.cassandra.streaming.messages.OutgoingStreamMessage) StreamingDataOutputPlus(org.apache.cassandra.streaming.StreamingDataOutputPlus) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 4 with OutgoingStreamMessage

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

the class StreamTransferTask method abort.

public synchronized void abort() {
    if (aborted)
        return;
    aborted = true;
    for (ScheduledFuture future : timeoutTasks.values()) future.cancel(false);
    timeoutTasks.clear();
    Throwable fail = null;
    for (OutgoingStreamMessage stream : streams.values()) {
        try {
            stream.complete();
        } catch (Throwable t) {
            if (fail == null)
                fail = t;
            else
                fail.addSuppressed(t);
        }
    }
    streams.clear();
    if (fail != null)
        Throwables.propagate(fail);
}
Also used : OutgoingStreamMessage(org.apache.cassandra.streaming.messages.OutgoingStreamMessage) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 5 with OutgoingStreamMessage

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

the class StreamTransferTask method timeout.

/**
 * Received ACK for stream at {@code sequenceNumber}.
 *
 * @param sequenceNumber sequence number of stream
 */
public void timeout(int sequenceNumber) {
    synchronized (this) {
        timeoutTasks.remove(sequenceNumber);
        OutgoingStreamMessage stream = streams.remove(sequenceNumber);
        if (stream == null)
            return;
        stream.complete();
        logger.debug("timeout sequenceNumber {}, remaining files {}", sequenceNumber, streams.keySet());
    }
    session.sessionTimeout();
}
Also used : OutgoingStreamMessage(org.apache.cassandra.streaming.messages.OutgoingStreamMessage)

Aggregations

OutgoingStreamMessage (org.apache.cassandra.streaming.messages.OutgoingStreamMessage)6 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 IOException (java.io.IOException)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 CancellationException (java.util.concurrent.CancellationException)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 CassandraOutgoingFile (org.apache.cassandra.db.streaming.CassandraOutgoingFile)1 Range (org.apache.cassandra.dht.Range)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 StreamingDataOutputPlus (org.apache.cassandra.streaming.StreamingDataOutputPlus)1 NettyStreamingConnectionFactory (org.apache.cassandra.streaming.async.NettyStreamingConnectionFactory)1 Ref (org.apache.cassandra.utils.concurrent.Ref)1 UncheckedInterruptedException (org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)1 Test (org.junit.Test)1