use of io.pravega.segmentstore.contracts.AttributeUpdate in project pravega by pravega.
the class AppendProcessorTest method testConditionalAppendFailure.
@Test
public void testConditionalAppendFailure() {
String streamSegmentName = "scope/stream/testConditionalAppendFailure";
UUID clientId = UUID.randomUUID();
byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
StreamSegmentStore store = mock(StreamSegmentStore.class);
ServerConnection connection = mock(ServerConnection.class);
val mockedRecorder = Mockito.mock(SegmentStatsRecorder.class);
ConnectionTracker tracker = mock(ConnectionTracker.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).statsRecorder(mockedRecorder).build();
setupGetAttributes(streamSegmentName, clientId, store);
val ac1 = interceptAppend(store, streamSegmentName, 0, updateEventNumber(clientId, 1), CompletableFuture.completedFuture((long) data.length));
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
processor.append(new Append(streamSegmentName, clientId, 1, 1, Unpooled.wrappedBuffer(data), 0L, requestId));
val ac2 = interceptAppend(store, streamSegmentName, 0, updateEventNumber(clientId, 2, 1, 1), Futures.failedFuture(new BadOffsetException(streamSegmentName, data.length, 0)));
processor.append(new Append(streamSegmentName, clientId, 2, 1, Unpooled.wrappedBuffer(data), 0L, requestId));
val ac3 = interceptAppend(store, streamSegmentName, 0, updateEventNumber(clientId, 3, 1, 1), Futures.failedFuture(new BadAttributeUpdateException(streamSegmentName, new AttributeUpdate(AttributeId.fromUUID(clientId), null, 0), true, "test")));
processor.append(new Append(streamSegmentName, clientId, 3, 1, Unpooled.wrappedBuffer(data), 0L, requestId));
verify(store).getAttributes(anyString(), eq(Collections.singleton(AttributeId.fromUUID(clientId))), eq(true), eq(AppendProcessor.TIMEOUT));
verifyStoreAppend(ac1, data);
verifyStoreAppend(ac2, data);
verifyStoreAppend(ac3, data);
verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
verify(tracker, times(3)).updateOutstandingBytes(connection, data.length, data.length);
verify(connection).send(new DataAppended(requestId, clientId, 1, 0, data.length));
verify(connection).send(new ConditionalCheckFailed(clientId, 2, requestId));
verify(connection).send(new InvalidEventNumber(clientId, requestId, "test"));
verify(connection).close();
verify(tracker, times(3)).updateOutstandingBytes(connection, -data.length, 0);
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
verify(mockedRecorder).recordAppend(eq(streamSegmentName), eq(8L), eq(1), any());
}
use of io.pravega.segmentstore.contracts.AttributeUpdate in project pravega by pravega.
the class AppendProcessorTest method testBadAttributeException.
@Test(timeout = 5000)
public void testBadAttributeException() throws Exception {
String streamSegmentName = "scope/stream/testAppendSegment";
UUID clientId = UUID.randomUUID();
byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
// Setup mocks.
StreamSegmentStore store = mock(StreamSegmentStore.class);
setupGetAttributes(streamSegmentName, clientId, store);
val ex = new BadAttributeUpdateException(streamSegmentName, new AttributeUpdate(AttributeId.randomUUID(), AttributeUpdateType.ReplaceIfEquals, 100, 101), false, "error");
interceptAppend(store, streamSegmentName, updateEventNumber(clientId, data.length), Futures.failedFuture(ex));
@Cleanup EmbeddedChannel channel = createChannel(store);
// Send a setup append WireCommand.
Reply reply = sendRequest(channel, new SetupAppend(requestId, clientId, streamSegmentName, ""));
assertEquals(new AppendSetup(requestId, streamSegmentName, clientId, 0), reply);
// Send an append which will cause a RuntimeException to be thrown by the store.
reply = sendRequest(channel, new Append(streamSegmentName, clientId, data.length, 1, Unpooled.wrappedBuffer(data), null, requestId));
// validate InvalidEventNumber Wirecommand is sent before closing the Channel.
assertNotNull("Invalid Event WireCommand is expected", reply);
assertEquals(WireCommandType.INVALID_EVENT_NUMBER.getCode(), ((WireCommand) reply).getType().getCode());
assertEquals(requestId, ((InvalidEventNumber) reply).getRequestId());
// Verify that the channel is closed by the AppendProcessor.
assertEventuallyEquals(false, channel::isOpen, 3000);
}
use of io.pravega.segmentstore.contracts.AttributeUpdate in project pravega by pravega.
the class StreamSegmentContainer method saveStorageSnapshot.
private CompletableFuture<Void> saveStorageSnapshot(SnapshotInfo checkpoint, Duration timeout) {
TimeoutTimer timer = new TimeoutTimer(timeout);
val attributeUpdates = AttributeUpdateCollection.from(new AttributeUpdate(ATTRIBUTE_SLTS_LATEST_SNAPSHOT_ID, AttributeUpdateType.Replace, checkpoint.getSnapshotId()), new AttributeUpdate(ATTRIBUTE_SLTS_LATEST_SNAPSHOT_EPOCH, AttributeUpdateType.Replace, checkpoint.getEpoch()));
return this.metadataStore.getOrAssignSegmentId(NameUtils.getMetadataSegmentName(this.metadata.getContainerId()), timer.getRemaining(), streamSegmentId -> updateAttributesForSegment(streamSegmentId, attributeUpdates, timer.getRemaining())).thenRun(() -> log.debug("{}: Save SLTS snapshot. {}", this.traceObjectId, checkpoint));
}
use of io.pravega.segmentstore.contracts.AttributeUpdate in project pravega by pravega.
the class SegmentStoreAdapter method append.
// endregion
// region Stream Operations
@Override
public CompletableFuture<Void> append(String streamName, Event event, Duration timeout) {
ensureRunning();
val au = AttributeUpdateCollection.from(new AttributeUpdate(Attributes.EVENT_COUNT, AttributeUpdateType.Replace, 1), new AttributeUpdate(AttributeId.uuid(EVENT_SEQ_NO_PREFIX, event.getOwnerId()), AttributeUpdateType.Replace, event.getSequence()), new AttributeUpdate(AttributeId.uuid(EVENT_RK_PREFIX, event.getOwnerId()), AttributeUpdateType.Replace, event.getRoutingKey()));
return Futures.toVoid(this.streamSegmentStore.append(streamName, new ByteBufWrapper(event.getWriteBuffer()), au, timeout).exceptionally(ex -> attemptReconcile(ex, streamName, timeout)));
}
use of io.pravega.segmentstore.contracts.AttributeUpdate in project pravega by pravega.
the class AppendProcessorAdapter method createStream.
@Override
public CompletableFuture<Void> createStream(String streamName, Duration timeout) {
String segmentName = streamToSegment(streamName);
val attributes = Arrays.asList(new AttributeUpdate(Attributes.SCALE_POLICY_TYPE, AttributeUpdateType.Replace, ScaleType.NoScaling.getValue()), new AttributeUpdate(Attributes.SCALE_POLICY_RATE, AttributeUpdateType.Replace, 0L));
return this.segmentStoreAdapter.getStreamSegmentStore().createStreamSegment(segmentName, SegmentType.STREAM_SEGMENT, attributes, timeout).thenRun(() -> {
SegmentHandler handler = new SegmentHandler(segmentName, this.testConfig.getProducerCount(), this.segmentStoreAdapter.getStreamSegmentStore());
synchronized (this.handlers) {
this.handlers.put(segmentName, handler);
}
handler.initialize();
});
}
Aggregations