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);
}
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();
}
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);
}
}
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);
}
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();
}
Aggregations