Search in sources :

Example 1 with StreamMessageHeader

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

the class CassandraEntireSSTableStreamWriterTest method testBlockReadingAndWritingOverWire.

@Test
public void testBlockReadingAndWritingOverWire() throws Throwable {
    StreamSession session = setupStreamingSessionForTest();
    InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
    // This is needed as Netty releases the ByteBuffers as soon as the channel is flushed
    ByteBuf serializedFile = Unpooled.buffer(8192);
    EmbeddedChannel channel = createMockNettyChannel(serializedFile);
    try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
        ComponentContext context = ComponentContext.create(descriptor)) {
        CassandraEntireSSTableStreamWriter writer = new CassandraEntireSSTableStreamWriter(sstable, session, context);
        writer.write(out);
        session.prepareReceiving(new StreamSummary(sstable.metadata().id, 1, 5104));
        CassandraStreamHeader header = CassandraStreamHeader.builder().withSSTableFormat(sstable.descriptor.formatType).withSSTableVersion(sstable.descriptor.version).withSSTableLevel(0).withEstimatedKeys(sstable.estimatedKeys()).withSections(Collections.emptyList()).withSerializationHeader(sstable.header.toComponent()).withComponentManifest(context.manifest()).isEntireSSTable(true).withFirstKey(sstable.first).withTableId(sstable.metadata().id).build();
        CassandraEntireSSTableStreamReader reader = new CassandraEntireSSTableStreamReader(new StreamMessageHeader(sstable.metadata().id, peer, session.planId(), false, 0, 0, 0, null), header, session);
        SSTableMultiWriter sstableWriter = reader.read(new DataInputBuffer(serializedFile.nioBuffer(), false));
        Collection<SSTableReader> newSstables = sstableWriter.finished();
        assertEquals(1, newSstables.size());
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) AsyncStreamingOutputPlus(org.apache.cassandra.net.AsyncStreamingOutputPlus) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) StreamSession(org.apache.cassandra.streaming.StreamSession) StreamSummary(org.apache.cassandra.streaming.StreamSummary) StreamMessageHeader(org.apache.cassandra.streaming.messages.StreamMessageHeader) SSTableMultiWriter(org.apache.cassandra.io.sstable.SSTableMultiWriter) Test(org.junit.Test)

Example 2 with StreamMessageHeader

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

the class StreamingInboundHandlerTest method StreamDeserializingTask_deserialize_ISM_NoSession.

@Test(expected = IllegalStateException.class)
public void StreamDeserializingTask_deserialize_ISM_NoSession() throws IOException {
    StreamMessageHeader header = new StreamMessageHeader(TableId.generate(), REMOTE_ADDR, UUID.randomUUID(), true, 0, 0, 0, UUID.randomUUID());
    ByteBuffer temp = ByteBuffer.allocate(1024);
    DataOutputPlus out = new DataOutputBuffer(temp);
    StreamMessageHeader.serializer.serialize(header, out, MessagingService.current_version);
    temp.flip();
    DataInputPlus in = new DataInputBuffer(temp, false);
    // session not found
    IncomingStreamMessage.serializer.deserialize(in, MessagingService.current_version);
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) ByteBuffer(java.nio.ByteBuffer) DataOutputPlus(org.apache.cassandra.io.util.DataOutputPlus) StreamMessageHeader(org.apache.cassandra.streaming.messages.StreamMessageHeader) Test(org.junit.Test)

Example 3 with StreamMessageHeader

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

the class StreamingInboundHandlerTest method StreamDeserializingTask_deserialize_ISM_HasSession.

@Test
public void StreamDeserializingTask_deserialize_ISM_HasSession() {
    UUID planId = UUID.randomUUID();
    StreamResultFuture future = StreamResultFuture.createFollower(0, planId, StreamOperation.REPAIR, REMOTE_ADDR, streamingChannel, streamingChannel.messagingVersion, UUID.randomUUID(), PreviewKind.ALL);
    StreamManager.instance.registerFollower(future);
    StreamMessageHeader header = new StreamMessageHeader(TableId.generate(), REMOTE_ADDR, planId, false, 0, 0, 0, UUID.randomUUID());
    // IncomingStreamMessage.serializer.deserialize
    StreamSession session = StreamManager.instance.findSession(header.sender, header.planId, header.sessionIndex, header.sendByFollower);
    Assert.assertNotNull(session);
    session = StreamManager.instance.findSession(header.sender, header.planId, header.sessionIndex, !header.sendByFollower);
    Assert.assertNull(session);
}
Also used : StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) StreamSession(org.apache.cassandra.streaming.StreamSession) UUID(java.util.UUID) StreamMessageHeader(org.apache.cassandra.streaming.messages.StreamMessageHeader) Test(org.junit.Test)

Example 4 with StreamMessageHeader

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

the class EntireSSTableStreamConcurrentComponentMutationTest method testStreamWithConcurrentComponentMutation.

private void testStreamWithConcurrentComponentMutation(Callable<?> runBeforeStreaming, Callable<?> runConcurrentWithStreaming) throws Throwable {
    ByteBuf serializedFile = Unpooled.buffer(8192);
    InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
    StreamSession session = setupStreamingSessionForTest();
    Collection<OutgoingStream> outgoingStreams = store.getStreamManager().createOutgoingStreams(session, rangesAtEndpoint, NO_PENDING_REPAIR, PreviewKind.NONE);
    CassandraOutgoingFile outgoingFile = (CassandraOutgoingFile) Iterables.getOnlyElement(outgoingStreams);
    Future<?> streaming = executeAsync(() -> {
        runBeforeStreaming.call();
        try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(createMockNettyChannel(serializedFile))) {
            outgoingFile.write(session, out, MessagingService.current_version);
            assertTrue(sstable.descriptor.getTemporaryFiles().isEmpty());
        }
        return null;
    });
    Future<?> concurrentMutations = executeAsync(runConcurrentWithStreaming);
    streaming.get(3, TimeUnit.MINUTES);
    concurrentMutations.get(3, TimeUnit.MINUTES);
    session.prepareReceiving(new StreamSummary(sstable.metadata().id, 1, 5104));
    StreamMessageHeader messageHeader = new StreamMessageHeader(sstable.metadata().id, peer, session.planId(), false, 0, 0, 0, null);
    try (DataInputBuffer in = new DataInputBuffer(serializedFile.nioBuffer(), false)) {
        CassandraStreamHeader header = CassandraStreamHeader.serializer.deserialize(in, MessagingService.current_version);
        CassandraEntireSSTableStreamReader reader = new CassandraEntireSSTableStreamReader(messageHeader, header, session);
        SSTableReader streamedSSTable = Iterables.getOnlyElement(reader.read(in).finished());
        SSTableUtils.assertContentEquals(sstable, streamedSSTable);
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) AsyncStreamingOutputPlus(org.apache.cassandra.net.AsyncStreamingOutputPlus) ByteBuf(io.netty.buffer.ByteBuf) OutgoingStream(org.apache.cassandra.streaming.OutgoingStream) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) StreamSession(org.apache.cassandra.streaming.StreamSession) StreamSummary(org.apache.cassandra.streaming.StreamSummary) StreamMessageHeader(org.apache.cassandra.streaming.messages.StreamMessageHeader)

Aggregations

StreamMessageHeader (org.apache.cassandra.streaming.messages.StreamMessageHeader)4 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)3 StreamSession (org.apache.cassandra.streaming.StreamSession)3 Test (org.junit.Test)3 ByteBuf (io.netty.buffer.ByteBuf)2 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)2 AsyncStreamingOutputPlus (org.apache.cassandra.net.AsyncStreamingOutputPlus)2 StreamSummary (org.apache.cassandra.streaming.StreamSummary)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 ByteBuffer (java.nio.ByteBuffer)1 UUID (java.util.UUID)1 SSTableMultiWriter (org.apache.cassandra.io.sstable.SSTableMultiWriter)1 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)1 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)1 DataOutputPlus (org.apache.cassandra.io.util.DataOutputPlus)1 OutgoingStream (org.apache.cassandra.streaming.OutgoingStream)1 StreamResultFuture (org.apache.cassandra.streaming.StreamResultFuture)1