Search in sources :

Example 26 with Append

use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.

the class CommandEncoderTest method testExactBatch.

@Test
public void testExactBatch() throws IOException {
    AppendBatchSizeTracker batchSizeTracker = new FixedBatchSizeTracker(100);
    DecodingOutputStream output = new DecodingOutputStream();
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
    CommandEncoder commandEncoder = new CommandEncoder(x -> batchSizeTracker, null, output, null, endpoint);
    UUID writerId = UUID.randomUUID();
    WireCommand setupAppend = new WireCommands.SetupAppend(0, writerId, "seg", "");
    commandEncoder.write(setupAppend);
    assertEquals(output.decoded.remove(0), setupAppend);
    ByteBuf data = Unpooled.wrappedBuffer(new byte[100]);
    Event event = new WireCommands.Event(data);
    Append append = new Append("seg", writerId, 1, event, 0);
    commandEncoder.write(append);
    AppendBlock block = (AppendBlock) output.decoded.remove(0);
    assertEquals(108, block.getData().readableBytes());
    AppendBlockEnd blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId, blockEnd.getWriterId());
    assertEquals(108, blockEnd.getSizeOfWholeEvents());
    assertEquals(0, blockEnd.getData().readableBytes());
    assertEquals(1, blockEnd.getNumEvents());
}
Also used : WireCommand(io.pravega.shared.protocol.netty.WireCommand) AppendBatchSizeTracker(io.pravega.shared.protocol.netty.AppendBatchSizeTracker) ByteBuf(io.netty.buffer.ByteBuf) AppendBlock(io.pravega.shared.protocol.netty.WireCommands.AppendBlock) Append(io.pravega.shared.protocol.netty.Append) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AppendBlockEnd(io.pravega.shared.protocol.netty.WireCommands.AppendBlockEnd) Event(io.pravega.shared.protocol.netty.WireCommands.Event) UUID(java.util.UUID) Test(org.junit.Test)

Example 27 with Append

use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.

the class CommandEncoderTest method testOverBatchSize.

@Test
public void testOverBatchSize() throws IOException {
    AppendBatchSizeTracker batchSizeTracker = new FixedBatchSizeTracker(100);
    DecodingOutputStream output = new DecodingOutputStream();
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
    CommandEncoder commandEncoder = new CommandEncoder(x -> batchSizeTracker, null, output, null, endpoint);
    UUID writerId = UUID.randomUUID();
    WireCommand setupAppend = new WireCommands.SetupAppend(0, writerId, "seg", "");
    commandEncoder.write(setupAppend);
    assertEquals(output.decoded.remove(0), setupAppend);
    ByteBuf data = Unpooled.wrappedBuffer(new byte[200]);
    Event event = new WireCommands.Event(data);
    Append append = new Append("seg", writerId, 1, event, 0);
    commandEncoder.write(append);
    AppendBlock block = (AppendBlock) output.decoded.remove(0);
    assertEquals(208, block.getData().readableBytes());
    AppendBlockEnd blockEnd = (AppendBlockEnd) output.decoded.remove(0);
    assertEquals(writerId, blockEnd.getWriterId());
    assertEquals(208, blockEnd.getSizeOfWholeEvents());
    assertEquals(0, blockEnd.getData().readableBytes());
    assertEquals(1, blockEnd.getNumEvents());
}
Also used : WireCommand(io.pravega.shared.protocol.netty.WireCommand) AppendBatchSizeTracker(io.pravega.shared.protocol.netty.AppendBatchSizeTracker) ByteBuf(io.netty.buffer.ByteBuf) AppendBlock(io.pravega.shared.protocol.netty.WireCommands.AppendBlock) Append(io.pravega.shared.protocol.netty.Append) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AppendBlockEnd(io.pravega.shared.protocol.netty.WireCommands.AppendBlockEnd) Event(io.pravega.shared.protocol.netty.WireCommands.Event) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with Append

use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.

the class AppendTest method sendLargeAppend.

@Test(timeout = 10000)
public void sendLargeAppend() throws Exception {
    String segment = "sendLargeAppend";
    ByteBuf data = Unpooled.wrappedBuffer(new byte[Serializer.MAX_EVENT_SIZE]);
    StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
    @Cleanup EmbeddedChannel channel = createChannel(store);
    SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, "", 1024L));
    assertEquals(segment, created.getSegment());
    UUID uuid = UUID.randomUUID();
    AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, ""));
    assertEquals(segment, setup.getSegment());
    assertEquals(uuid, setup.getWriterId());
    DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, data.readableBytes(), new Event(data), 1L));
    assertEquals(uuid, ack.getWriterId());
    assertEquals(data.readableBytes(), ack.getEventNumber());
    assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Cleanup(lombok.Cleanup) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) Event(io.pravega.shared.protocol.netty.WireCommands.Event) PendingEvent(io.pravega.client.stream.impl.PendingEvent) UUID(java.util.UUID) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Test(org.junit.Test)

Example 29 with Append

use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.

the class AppendTest method testMultipleAppends.

@Test(timeout = 10000)
public void testMultipleAppends() throws Exception {
    String segment = "testMultipleAppends";
    ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes());
    StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
    @Cleanup EmbeddedChannel channel = createChannel(store);
    SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, "", 1024L));
    assertEquals(segment, created.getSegment());
    UUID uuid = UUID.randomUUID();
    AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, ""));
    assertEquals(segment, setup.getSegment());
    assertEquals(uuid, setup.getWriterId());
    data.retain();
    DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, 1, new Event(data), 1L));
    assertEquals(uuid, ack.getWriterId());
    assertEquals(1, ack.getEventNumber());
    assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
    DataAppended ack2 = (DataAppended) sendRequest(channel, new Append(segment, uuid, 2, new Event(data), 1L));
    assertEquals(uuid, ack2.getWriterId());
    assertEquals(2, ack2.getEventNumber());
    assertEquals(1, ack2.getPreviousEventNumber());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Cleanup(lombok.Cleanup) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) Event(io.pravega.shared.protocol.netty.WireCommands.Event) PendingEvent(io.pravega.client.stream.impl.PendingEvent) UUID(java.util.UUID) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Test(org.junit.Test)

Example 30 with Append

use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.

the class AppendProcessor method append.

/**
 * Append data to the store.
 */
@Override
public void append(Append append) {
    long traceId = LoggerHelpers.traceEnter(log, "append", append);
    UUID id = append.getWriterId();
    WriterState state = this.writerStates.get(Pair.of(append.getSegment(), id));
    Preconditions.checkState(state != null, "Data from unexpected connection: Segment=%s, WriterId=%s.", append.getSegment(), id);
    long previousEventNumber = state.beginAppend(append.getEventNumber());
    int appendLength = append.getData().readableBytes();
    this.connection.adjustOutstandingBytes(appendLength);
    Timer timer = new Timer();
    storeAppend(append, previousEventNumber).whenComplete((newLength, ex) -> {
        handleAppendResult(append, newLength, ex, state, timer);
        LoggerHelpers.traceLeave(log, "storeAppend", traceId, append, ex);
    }).whenComplete((v, e) -> {
        this.connection.adjustOutstandingBytes(-appendLength);
        append.getData().release();
    });
}
Also used : Arrays(java.util.Arrays) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) TokenExpiredException(io.pravega.auth.TokenExpiredException) AuthHandler(io.pravega.auth.AuthHandler) LoggerFactory(org.slf4j.LoggerFactory) CREATION_TIME(io.pravega.segmentstore.contracts.Attributes.CREATION_TIME) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) TagLogger(io.pravega.common.tracing.TagLogger) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Attributes(io.pravega.segmentstore.contracts.Attributes) CancellationException(java.util.concurrent.CancellationException) NonNull(lombok.NonNull) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) UUID(java.util.UUID) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) Builder(lombok.Builder) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) DelegationTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.DelegationTokenVerifier) ATTRIBUTE_SEGMENT_TYPE(io.pravega.segmentstore.contracts.Attributes.ATTRIBUTE_SEGMENT_TYPE) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) Futures(io.pravega.common.concurrent.Futures) Getter(lombok.Getter) IllegalContainerStateException(io.pravega.segmentstore.server.IllegalContainerStateException) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) Exceptions(io.pravega.common.Exceptions) ConditionalCheckFailed(io.pravega.shared.protocol.netty.WireCommands.ConditionalCheckFailed) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) BadAttributeUpdateException(io.pravega.segmentstore.contracts.BadAttributeUpdateException) Append(io.pravega.shared.protocol.netty.Append) DelegatingRequestProcessor(io.pravega.shared.protocol.netty.DelegatingRequestProcessor) CreateTransientSegment(io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment) JsonWebToken(io.pravega.shared.security.token.JsonWebToken) HashSet(java.util.HashSet) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SegmentType(io.pravega.segmentstore.contracts.SegmentType) FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) TokenException(io.pravega.auth.TokenException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Hello(io.pravega.shared.protocol.netty.WireCommands.Hello) SegmentAlreadyExists(io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists) ByteBufWrapper(io.pravega.shared.protocol.netty.ByteBufWrapper) LoggerHelpers(io.pravega.common.LoggerHelpers) NameUtils(io.pravega.shared.NameUtils) EVENT_COUNT(io.pravega.segmentstore.contracts.Attributes.EVENT_COUNT) AttributeId(io.pravega.segmentstore.contracts.AttributeId) Throwables(com.google.common.base.Throwables) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Timer(io.pravega.common.Timer) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) InvalidEventNumber(io.pravega.shared.protocol.netty.WireCommands.InvalidEventNumber) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) RequestProcessor(io.pravega.shared.protocol.netty.RequestProcessor) OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) Collections(java.util.Collections) Timer(io.pravega.common.Timer) UUID(java.util.UUID)

Aggregations

Append (io.pravega.shared.protocol.netty.Append)74 UUID (java.util.UUID)67 Test (org.junit.Test)64 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)52 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)44 WireCommands (io.pravega.shared.protocol.netty.WireCommands)37 Cleanup (lombok.Cleanup)37 CompletableFuture (java.util.concurrent.CompletableFuture)33 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)31 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)27 InOrder (org.mockito.InOrder)22 ClientConnection (io.pravega.client.connection.impl.ClientConnection)21 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)21 MockController (io.pravega.client.stream.mock.MockController)21 Event (io.pravega.shared.protocol.netty.WireCommands.Event)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 lombok.val (lombok.val)20 DataAppended (io.pravega.shared.protocol.netty.WireCommands.DataAppended)17 ByteBuffer (java.nio.ByteBuffer)17 ByteBuf (io.netty.buffer.ByteBuf)16