Search in sources :

Example 11 with StreamConfigurationRecord

use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.

the class StreamMetadataTasksTest method testWorkflowCompletionTimeout.

@Test(timeout = 30000)
public void testWorkflowCompletionTimeout() {
    EventHelper helper = EventHelperMock.getEventHelperMock(executor, "host", ((AbstractStreamMetadataStore) streamStorePartialMock).getHostTaskIndex());
    StreamMetadataTasks streamMetadataTask = new StreamMetadataTasks(streamStorePartialMock, bucketStore, TaskStoreFactory.createZKStore(zkClient, executor), SegmentHelperMock.getSegmentHelperMock(), executor, "host", new GrpcAuthHelper(authEnabled, "key", 300), helper);
    streamMetadataTask.setCompletionTimeoutMillis(500L);
    StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    String completion = "completion";
    streamStorePartialMock.createStream(SCOPE, completion, configuration, System.currentTimeMillis(), null, executor).join();
    streamStorePartialMock.setState(SCOPE, completion, State.ACTIVE, null, executor).join();
    WriterMock requestEventWriter = new WriterMock(streamMetadataTask, executor);
    streamMetadataTask.setRequestEventWriter(requestEventWriter);
    StreamConfiguration configuration2 = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build();
    AssertExtensions.assertFutureThrows("update timedout", streamMetadataTask.updateStream(SCOPE, completion, configuration2, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
    ControllerEvent event = requestEventWriter.eventQueue.poll();
    assertTrue(event instanceof UpdateStreamEvent);
    VersionedMetadata<StreamConfigurationRecord> configurationRecord = streamStorePartialMock.getConfigurationRecord(SCOPE, completion, null, executor).join();
    assertTrue(configurationRecord.getObject().isUpdating());
    Map<Long, Long> streamCut = Collections.singletonMap(0L, 0L);
    AssertExtensions.assertFutureThrows("truncate timedout", streamMetadataTask.truncateStream(SCOPE, completion, streamCut, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
    event = requestEventWriter.eventQueue.poll();
    assertTrue(event instanceof TruncateStreamEvent);
    VersionedMetadata<StreamTruncationRecord> truncationRecord = streamStorePartialMock.getTruncationRecord(SCOPE, completion, null, executor).join();
    assertTrue(truncationRecord.getObject().isUpdating());
    AssertExtensions.assertFutureThrows("seal timedout", streamMetadataTask.sealStream(SCOPE, completion, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
    event = requestEventWriter.eventQueue.poll();
    assertTrue(event instanceof SealStreamEvent);
    VersionedMetadata<State> state = streamStorePartialMock.getVersionedState(SCOPE, completion, null, executor).join();
    assertEquals(state.getObject(), State.SEALING);
    streamStorePartialMock.setState(SCOPE, completion, State.SEALED, null, executor).join();
    AssertExtensions.assertFutureThrows("delete timedout", streamMetadataTask.deleteStream(SCOPE, completion, 0L), e -> Exceptions.unwrap(e) instanceof TimeoutException);
    event = requestEventWriter.eventQueue.poll();
    assertTrue(event instanceof DeleteStreamEvent);
}
Also used : DeleteStreamEvent(io.pravega.shared.controller.event.DeleteStreamEvent) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) TruncateStreamEvent(io.pravega.shared.controller.event.TruncateStreamEvent) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) State(io.pravega.controller.store.stream.State) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) EventHelper(io.pravega.controller.task.EventHelper) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) ControllerEventStreamWriterMock(io.pravega.controller.mocks.ControllerEventStreamWriterMock) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 12 with StreamConfigurationRecord

use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.

the class InMemoryStream method checkStreamExists.

@Override
CompletableFuture<CreateStreamResponse> checkStreamExists(StreamConfiguration configuration, long timestamp, final int startingSegmentNumber, OperationContext context) {
    CompletableFuture<CreateStreamResponse> result = new CompletableFuture<>();
    final long time;
    final StreamConfigurationRecord config;
    final VersionedMetadata<StateRecord> currentState;
    synchronized (lock) {
        time = creationTime.get();
        config = this.configuration == null ? null : this.configuration.getObject();
        currentState = this.state;
    }
    if (time != Long.MIN_VALUE) {
        if (config != null) {
            handleStreamMetadataExists(timestamp, result, time, startingSegmentNumber, config.getStreamConfiguration(), currentState, context);
        } else {
            result.complete(new CreateStreamResponse(CreateStreamResponse.CreateStatus.NEW, configuration, time, startingSegmentNumber));
        }
    } else {
        result.complete(new CreateStreamResponse(CreateStreamResponse.CreateStatus.NEW, configuration, timestamp, startingSegmentNumber));
    }
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) StateRecord(io.pravega.controller.store.stream.records.StateRecord) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord)

Example 13 with StreamConfigurationRecord

use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.

the class RequestHandlersTest method concurrentUpdateStream.

// concurrent update stream
@SuppressWarnings("unchecked")
@Test(timeout = 300000)
public void concurrentUpdateStream() throws Exception {
    String stream = "update";
    StreamMetadataStore streamStore1 = getStore();
    StreamMetadataStore streamStore1Spied = spy(getStore());
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(1, 2, 1)).build();
    streamStore1.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
    streamStore1.setState(scope, stream, State.ACTIVE, null, executor).join();
    StreamMetadataStore streamStore2 = getStore();
    UpdateStreamTask requestHandler1 = new UpdateStreamTask(streamMetadataTasks, streamStore1Spied, bucketStore, executor);
    UpdateStreamTask requestHandler2 = new UpdateStreamTask(streamMetadataTasks, streamStore2, bucketStore, executor);
    CompletableFuture<Void> wait = new CompletableFuture<>();
    CompletableFuture<Void> signal = new CompletableFuture<>();
    streamStore1.startUpdateConfiguration(scope, stream, config, null, executor).join();
    UpdateStreamEvent event = new UpdateStreamEvent(scope, stream, System.currentTimeMillis());
    doAnswer(x -> {
        signal.complete(null);
        wait.join();
        return streamStore1.completeUpdateConfiguration(x.getArgument(0), x.getArgument(1), x.getArgument(2), x.getArgument(3), x.getArgument(4));
    }).when(streamStore1Spied).completeUpdateConfiguration(anyString(), anyString(), any(), any(), any());
    CompletableFuture<Void> future1 = CompletableFuture.completedFuture(null).thenComposeAsync(v -> requestHandler1.execute(event), executor);
    signal.join();
    requestHandler2.execute(event).join();
    wait.complete(null);
    AssertExtensions.assertSuppliedFutureThrows("first update job should fail", () -> future1, e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
    // validate rolling txn done
    VersionedMetadata<StreamConfigurationRecord> versioned = streamStore1.getConfigurationRecord(scope, stream, null, executor).join();
    assertFalse(versioned.getObject().isUpdating());
    assertEquals(2, getVersionNumber(versioned.getVersion()));
    assertEquals(State.ACTIVE, streamStore1.getState(scope, stream, true, null, executor).join());
    streamStore1.close();
    streamStore2.close();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) StoreException(io.pravega.controller.store.stream.StoreException) Test(org.junit.Test)

Example 14 with StreamConfigurationRecord

use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.

the class RequestHandlersTest method idempotentUpdatePartialScaleCompleted.

@Test(timeout = 300000)
public void idempotentUpdatePartialScaleCompleted() throws Exception {
    String stream = "update2";
    StreamMetadataStore streamStore1 = getStore();
    StreamMetadataStore streamStore1Spied = spy(getStore());
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    streamStore1.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
    streamStore1.setState(scope, stream, State.ACTIVE, null, executor).join();
    StreamMetadataStore streamStore2 = getStore();
    UpdateStreamTask requestHandler1 = new UpdateStreamTask(streamMetadataTasks, streamStore1Spied, bucketStore, executor);
    UpdateStreamTask requestHandler2 = new UpdateStreamTask(streamMetadataTasks, streamStore2, bucketStore, executor);
    CompletableFuture<Void> wait = new CompletableFuture<>();
    CompletableFuture<Void> signal = new CompletableFuture<>();
    config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(2)).build();
    streamStore1.startUpdateConfiguration(scope, stream, config, null, executor).join();
    UpdateStreamEvent event = new UpdateStreamEvent(scope, stream, System.currentTimeMillis());
    // make this wait at reset epoch transition. this has already changed the state to updating. both executions are
    // performing the same update.
    doAnswer(x -> {
        signal.complete(null);
        wait.join();
        return streamStore1.scaleSegmentsSealed(x.getArgument(0), x.getArgument(1), x.getArgument(2), x.getArgument(3), x.getArgument(4), x.getArgument(5));
    }).when(streamStore1Spied).scaleSegmentsSealed(anyString(), anyString(), any(), any(), any(), any());
    CompletableFuture<Void> future1 = CompletableFuture.completedFuture(null).thenComposeAsync(v -> requestHandler1.execute(event), executor);
    signal.join();
    requestHandler2.execute(event).join();
    wait.complete(null);
    AssertExtensions.assertSuppliedFutureThrows("first update job should fail", () -> future1, e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
    VersionedMetadata<StreamConfigurationRecord> versioned = streamStore1.getConfigurationRecord(scope, stream, null, executor).join();
    assertFalse(versioned.getObject().isUpdating());
    assertEquals(2, getVersionNumber(versioned.getVersion()));
    assertEquals(State.ACTIVE, streamStore1.getState(scope, stream, true, null, executor).join());
    assertEquals(1, streamStore1.getActiveEpoch(scope, stream, null, true, executor).join().getEpoch());
    // repeat the above experiment with complete scale step also having been performed.
    streamStore1.close();
    streamStore2.close();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) StoreException(io.pravega.controller.store.stream.StoreException) Test(org.junit.Test)

Example 15 with StreamConfigurationRecord

use of io.pravega.controller.store.stream.records.StreamConfigurationRecord in project pravega by pravega.

the class RequestHandlersTest method updateSealedStream.

@SuppressWarnings("unchecked")
@Test(timeout = 300000)
public void updateSealedStream() throws Exception {
    String stream = "updateSealed";
    StreamMetadataStore streamStore = getStore();
    StreamMetadataStore streamStoreSpied = spy(getStore());
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.byEventRate(1, 2, 1)).build();
    streamStore.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
    streamStore.setState(scope, stream, State.ACTIVE, null, executor).join();
    streamStore.setState(scope, stream, State.SEALED, null, executor).join();
    UpdateStreamTask requestHandler = new UpdateStreamTask(streamMetadataTasks, streamStoreSpied, bucketStore, executor);
    CompletableFuture<Void> wait = new CompletableFuture<>();
    CompletableFuture<Void> signal = new CompletableFuture<>();
    streamStore.startUpdateConfiguration(scope, stream, config, null, executor).join();
    UpdateStreamEvent event = new UpdateStreamEvent(scope, stream, System.currentTimeMillis());
    doAnswer(x -> {
        signal.complete(null);
        wait.join();
        return streamStore.completeUpdateConfiguration(x.getArgument(0), x.getArgument(1), x.getArgument(2), x.getArgument(3), x.getArgument(4));
    }).when(streamStoreSpied).completeUpdateConfiguration(anyString(), anyString(), any(), any(), any());
    CompletableFuture<Void> future = CompletableFuture.completedFuture(null).thenComposeAsync(v -> requestHandler.execute(event), executor);
    signal.join();
    wait.complete(null);
    AssertExtensions.assertSuppliedFutureThrows("Updating sealed stream job should fail", () -> future, e -> Exceptions.unwrap(e) instanceof UnsupportedOperationException);
    // validate
    VersionedMetadata<StreamConfigurationRecord> versioned = streamStore.getConfigurationRecord(scope, stream, null, executor).join();
    assertFalse(versioned.getObject().isUpdating());
    assertEquals(2, getVersionNumber(versioned.getVersion()));
    assertEquals(State.SEALED, streamStore.getState(scope, stream, true, null, executor).join());
    streamStore.close();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Test(org.junit.Test)

Aggregations

StreamConfigurationRecord (io.pravega.controller.store.stream.records.StreamConfigurationRecord)28 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)23 Test (org.junit.Test)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)14 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)10 HashMap (java.util.HashMap)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 StreamTruncationRecord (io.pravega.controller.store.stream.records.StreamTruncationRecord)9 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)7 Lists (com.google.common.collect.Lists)6 Segment (io.pravega.client.segment.impl.Segment)6 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)6 Stream (io.pravega.client.stream.Stream)6 StreamCut (io.pravega.client.stream.StreamCut)6 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)6 Exceptions (io.pravega.common.Exceptions)6 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)6