Search in sources :

Example 1 with AsyncStreamingOutputPlus

use of org.apache.cassandra.net.AsyncStreamingOutputPlus in project cassandra by apache.

the class ZeroCopyStreamingBenchmark method partialStreamWriter.

@Benchmark
@BenchmarkMode(Mode.Throughput)
public void partialStreamWriter(BenchmarkState state) throws Exception {
    EmbeddedChannel channel = createMockNettyChannel();
    AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
    state.partialStreamWriter.write(out);
    out.close();
    channel.finishAndReleaseAll();
}
Also used : AsyncStreamingOutputPlus(org.apache.cassandra.net.AsyncStreamingOutputPlus) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with AsyncStreamingOutputPlus

use of org.apache.cassandra.net.AsyncStreamingOutputPlus in project cassandra by apache.

the class CassandraEntireSSTableStreamWriterTest method testBlockWriterOverWire.

@Test
public void testBlockWriterOverWire() throws IOException {
    StreamSession session = setupStreamingSessionForTest();
    EmbeddedChannel channel = new EmbeddedChannel();
    try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
        ComponentContext context = ComponentContext.create(descriptor)) {
        CassandraEntireSSTableStreamWriter writer = new CassandraEntireSSTableStreamWriter(sstable, session, context);
        writer.write(out);
        Queue msgs = channel.outboundMessages();
        assertTrue(msgs.peek() instanceof DefaultFileRegion);
    }
}
Also used : StreamSession(org.apache.cassandra.streaming.StreamSession) AsyncStreamingOutputPlus(org.apache.cassandra.net.AsyncStreamingOutputPlus) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SharedDefaultFileRegion(org.apache.cassandra.net.SharedDefaultFileRegion) DefaultFileRegion(io.netty.channel.DefaultFileRegion) Queue(java.util.Queue) Test(org.junit.Test)

Example 3 with AsyncStreamingOutputPlus

use of org.apache.cassandra.net.AsyncStreamingOutputPlus 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 4 with AsyncStreamingOutputPlus

use of org.apache.cassandra.net.AsyncStreamingOutputPlus in project cassandra by apache.

the class EntireSSTableStreamingCorrectFilesCountTest method constructDataOutputStream.

private AsyncStreamingOutputPlus constructDataOutputStream() {
    // This is needed as Netty releases the ByteBuffers as soon as the channel is flushed
    ByteBuf serializedFile = Unpooled.buffer(8192);
    EmbeddedChannel channel = createMockNettyChannel(serializedFile);
    return new AsyncStreamingOutputPlus(channel) {

        public void flush() throws IOException {
        // NO-OP
        }
    };
}
Also used : AsyncStreamingOutputPlus(org.apache.cassandra.net.AsyncStreamingOutputPlus) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with AsyncStreamingOutputPlus

use of org.apache.cassandra.net.AsyncStreamingOutputPlus 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

AsyncStreamingOutputPlus (org.apache.cassandra.net.AsyncStreamingOutputPlus)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 ByteBuf (io.netty.buffer.ByteBuf)3 StreamSession (org.apache.cassandra.streaming.StreamSession)3 Test (org.junit.Test)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)2 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)2 StreamSummary (org.apache.cassandra.streaming.StreamSummary)2 StreamMessageHeader (org.apache.cassandra.streaming.messages.StreamMessageHeader)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)2 DefaultFileRegion (io.netty.channel.DefaultFileRegion)1 Queue (java.util.Queue)1 CassandraOutgoingFile (org.apache.cassandra.db.streaming.CassandraOutgoingFile)1 Descriptor (org.apache.cassandra.io.sstable.Descriptor)1 SSTableMultiWriter (org.apache.cassandra.io.sstable.SSTableMultiWriter)1 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)1 SharedDefaultFileRegion (org.apache.cassandra.net.SharedDefaultFileRegion)1 OutgoingStream (org.apache.cassandra.streaming.OutgoingStream)1