Search in sources :

Example 1 with Status

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.

the class StreamMetadataTasksTest method truncateStreamTest.

@Test(timeout = 30000)
public void truncateStreamTest() throws Exception {
    final ScalingPolicy policy = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration = StreamConfiguration.builder().scope(SCOPE).streamName("test").scalingPolicy(policy).build();
    streamStorePartialMock.createStream(SCOPE, "test", configuration, System.currentTimeMillis(), null, executor).get();
    streamStorePartialMock.setState(SCOPE, "test", State.ACTIVE, null, executor).get();
    assertNotEquals(0, consumer.getCurrentSegments(SCOPE, "test").get().size());
    WriterMock requestEventWriter = new WriterMock(streamMetadataTasks, executor);
    streamMetadataTasks.setRequestEventWriter(requestEventWriter);
    List<AbstractMap.SimpleEntry<Double, Double>> newRanges = new ArrayList<>();
    newRanges.add(new AbstractMap.SimpleEntry<>(0.5, 0.75));
    newRanges.add(new AbstractMap.SimpleEntry<>(0.75, 1.0));
    ScaleResponse scaleOpResult = streamMetadataTasks.manualScale(SCOPE, "test", Collections.singletonList(1), newRanges, 30, null).get();
    assertTrue(scaleOpResult.getStatus().equals(ScaleStreamStatus.STARTED));
    ScaleOperationTask scaleTask = new ScaleOperationTask(streamMetadataTasks, streamStorePartialMock, executor);
    assertTrue(Futures.await(scaleTask.execute((ScaleOpEvent) requestEventWriter.eventQueue.take())));
    // start truncation
    StreamProperty<StreamTruncationRecord> truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
    assertFalse(truncProp.isUpdating());
    // 1. happy day test
    // update.. should succeed
    Map<Integer, Long> streamCut = new HashMap<>();
    streamCut.put(0, 1L);
    streamCut.put(1, 11L);
    CompletableFuture<UpdateStreamStatus.Status> truncateFuture = streamMetadataTasks.truncateStream(SCOPE, "test", streamCut, null);
    assertTrue(Futures.await(processEvent(requestEventWriter)));
    assertEquals(UpdateStreamStatus.Status.SUCCESS, truncateFuture.join());
    truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
    assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut));
    assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut));
    // 2. change state to scaling
    streamStorePartialMock.setState(SCOPE, "test", State.SCALING, null, executor).get();
    // call update should fail without posting the event
    Map<Integer, Long> streamCut2 = new HashMap<>();
    streamCut2.put(0, 1L);
    streamCut2.put(2, 1L);
    streamCut2.put(3, 1L);
    streamMetadataTasks.truncateStream(SCOPE, "test", streamCut2, null);
    AtomicBoolean loop = new AtomicBoolean(false);
    Futures.loop(() -> !loop.get(), () -> streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).thenApply(StreamProperty::isUpdating).thenAccept(loop::set), executor).join();
    // event posted, first step performed. now pick the event for processing
    TruncateStreamTask truncateStreamTask = new TruncateStreamTask(streamMetadataTasks, streamStorePartialMock, executor);
    TruncateStreamEvent taken = (TruncateStreamEvent) requestEventWriter.eventQueue.take();
    AssertExtensions.assertThrows("", truncateStreamTask.execute(taken), e -> Exceptions.unwrap(e) instanceof StoreException.OperationNotAllowedException);
    streamStorePartialMock.setState(SCOPE, "test", State.ACTIVE, null, executor).get();
    // now with state = active, process the same event. it should succeed now.
    assertTrue(Futures.await(truncateStreamTask.execute(taken)));
    // 3. multiple back to back updates.
    Map<Integer, Long> streamCut3 = new HashMap<>();
    streamCut3.put(0, 12L);
    streamCut3.put(2, 12L);
    streamCut3.put(3, 12L);
    CompletableFuture<UpdateStreamStatus.Status> truncateOp1 = streamMetadataTasks.truncateStream(SCOPE, "test", streamCut3, null);
    // ensure that previous updatestream has posted the event and set status to updating,
    // only then call second updateStream
    AtomicBoolean loop2 = new AtomicBoolean(false);
    Futures.loop(() -> !loop2.get(), () -> streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).thenApply(StreamProperty::isUpdating).thenAccept(loop2::set), executor).join();
    truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
    assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut3) && truncProp.isUpdating());
    // post the second update request. This should fail here itself as previous one has started.
    Map<Integer, Long> streamCut4 = new HashMap<>();
    streamCut4.put(0, 14L);
    streamCut4.put(2, 14L);
    streamCut4.put(3, 14L);
    CompletableFuture<UpdateStreamStatus.Status> truncateOpFuture2 = streamMetadataTasks.truncateStream(SCOPE, "test", streamCut4, null);
    assertEquals(UpdateStreamStatus.Status.FAILURE, truncateOpFuture2.join());
    // process event
    assertTrue(Futures.await(processEvent(requestEventWriter)));
    // verify that first request for update also completes with success.
    assertEquals(UpdateStreamStatus.Status.SUCCESS, truncateOp1.join());
    truncProp = streamStorePartialMock.getTruncationProperty(SCOPE, "test", true, null, executor).join();
    assertTrue(truncProp.getProperty().getStreamCut().equals(streamCut3) && !truncProp.isUpdating());
}
Also used : StreamTruncationRecord(io.pravega.controller.store.stream.tables.StreamTruncationRecord) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractMap(java.util.AbstractMap) TruncateStreamEvent(io.pravega.shared.controller.event.TruncateStreamEvent) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ControllerEventStreamWriterMock(io.pravega.controller.mocks.ControllerEventStreamWriterMock) ScaleStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse.ScaleStreamStatus) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StartScaleResponse(io.pravega.controller.store.stream.StartScaleResponse) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) ScaleOperationTask(io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask) StoreException(io.pravega.controller.store.stream.StoreException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TruncateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask) Test(org.junit.Test)

Example 2 with Status

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.

the class TimeoutServiceTest method testCloseUnknownTxn.

@Test(timeout = 5000)
public void testCloseUnknownTxn() {
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    TxnId txnId = convert(txData.getId());
    Controller.TxnState state = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
    Assert.assertEquals(TxnState.State.OPEN, state.getState());
    Controller.TxnStatus.Status status = controllerService.abortTransaction(SCOPE, STREAM, txnId).join().getStatus();
    Assert.assertEquals(Controller.TxnStatus.Status.SUCCESS, status);
}
Also used : TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 3 with Status

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.

the class TimeoutServiceTest method testTimeoutTaskFailureInvalidVersion.

@Test(timeout = 10000)
public void testTimeoutTaskFailureInvalidVersion() throws InterruptedException {
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    // Submit transaction to TimeoutService with incorrect tx version identifier.
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion() + 1, LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (1.25 * LEASE + RETRY_DELAY), TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    Assert.assertTrue(result.isPresent());
    Assert.assertEquals(StoreException.WriteConflictException.class, result.get().getClass());
    TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
}
Also used : VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) StoreException(io.pravega.controller.store.stream.StoreException) Test(org.junit.Test)

Example 4 with Status

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.

the class StreamMetadataStoreTest method deleteTest.

@Test
public void deleteTest() throws Exception {
    final String scope = "ScopeDelete";
    final String stream = "StreamDelete";
    final ScalingPolicy policy = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration = StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(policy).build();
    long start = System.currentTimeMillis();
    store.createScope(scope).get();
    store.createStream(scope, stream, configuration, start, null, executor).get();
    store.setState(scope, stream, State.ACTIVE, null, executor).get();
    assertTrue(store.checkStreamExists(scope, stream).join());
    store.deleteStream(scope, stream, null, executor).get();
    assertFalse(store.checkStreamExists(scope, stream).join());
    DeleteScopeStatus status = store.deleteScope(scope).join();
    assertEquals(status.getStatus(), DeleteScopeStatus.Status.SUCCESS);
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) Test(org.junit.Test)

Example 5 with Status

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.Status in project pravega by pravega.

the class StreamMetadataTasks method sealStream.

/**
 * Seal a stream.
 *
 * @param scope      scope.
 * @param stream     stream name.
 * @param contextOpt optional context
 * @return update status.
 */
public CompletableFuture<UpdateStreamStatus.Status> sealStream(String scope, String stream, OperationContext contextOpt) {
    final OperationContext context = contextOpt == null ? streamMetadataStore.createContext(scope, stream) : contextOpt;
    // 1. post event for seal.
    SealStreamEvent event = new SealStreamEvent(scope, stream);
    return writeEvent(event).thenCompose(x -> streamMetadataStore.getState(scope, stream, false, context, executor)).thenCompose(state -> {
        if (state.equals(State.SEALED)) {
            return CompletableFuture.completedFuture(true);
        } else {
            return streamMetadataStore.setState(scope, stream, State.SEALING, context, executor);
        }
    }).thenCompose(result -> {
        if (result) {
            return checkDone(() -> isSealed(scope, stream, context)).thenApply(x -> UpdateStreamStatus.Status.SUCCESS);
        } else {
            return CompletableFuture.completedFuture(UpdateStreamStatus.Status.FAILURE);
        }
    }).exceptionally(ex -> {
        log.warn("Exception thrown in trying to notify sealed segments {}", ex.getMessage());
        return handleUpdateStreamError(ex);
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) ControllerEventProcessors(io.pravega.controller.server.eventProcessor.ControllerEventProcessors) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TaskStepsRetryHelper.withRetries(io.pravega.controller.task.Stream.TaskStepsRetryHelper.withRetries) Duration(java.time.Duration) Map(java.util.Map) TaskExceptions(io.pravega.controller.server.eventProcessor.requesthandlers.TaskExceptions) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) ScaleOperationExceptions(io.pravega.controller.store.stream.ScaleOperationExceptions) ImmutableMap(com.google.common.collect.ImmutableMap) DeleteStreamEvent(io.pravega.shared.controller.event.DeleteStreamEvent) CompletionException(java.util.concurrent.CompletionException) State(io.pravega.controller.store.stream.tables.State) Collectors(java.util.stream.Collectors) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) Serializable(java.io.Serializable) MetricsProvider(io.pravega.shared.metrics.MetricsProvider) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CompletionStage(java.util.concurrent.CompletionStage) Config(io.pravega.controller.util.Config) ClientFactory(io.pravega.client.ClientFactory) Optional(java.util.Optional) Resource(io.pravega.controller.store.task.Resource) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) IntStream(java.util.stream.IntStream) NotImplementedException(org.apache.commons.lang3.NotImplementedException) OperationContext(io.pravega.controller.store.stream.OperationContext) SegmentHelper(io.pravega.controller.server.SegmentHelper) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Exceptions(io.pravega.common.Exceptions) PravegaInterceptor(io.pravega.controller.server.rpc.auth.PravegaInterceptor) TruncateStreamEvent(io.pravega.shared.controller.event.TruncateStreamEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScaleStatusResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) StreamCutRecord(io.pravega.controller.store.stream.StreamCutRecord) DynamicLogger(io.pravega.shared.metrics.DynamicLogger) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Segment(io.pravega.controller.store.stream.Segment) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ModelHelper(io.pravega.client.stream.impl.ModelHelper) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Task(io.pravega.controller.task.Task) TaskBase(io.pravega.controller.task.TaskBase) MetricsNames.nameFromStream(io.pravega.shared.MetricsNames.nameFromStream) CreateStreamResponse(io.pravega.controller.store.stream.CreateStreamResponse) WireCommands(io.pravega.shared.protocol.netty.WireCommands) SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) AbstractMap(java.util.AbstractMap) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) RETENTION_FREQUENCY(io.pravega.shared.MetricsNames.RETENTION_FREQUENCY) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ScaleOpEvent(io.pravega.shared.controller.event.ScaleOpEvent) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent)

Aggregations

Test (org.junit.Test)14 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)11 TxnStatus (io.pravega.controller.store.stream.TxnStatus)10 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)10 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)8 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)6 UUID (java.util.UUID)6 StoreException (io.pravega.controller.store.stream.StoreException)5 UpdateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Futures (io.pravega.common.concurrent.Futures)3 SegmentHelper (io.pravega.controller.server.SegmentHelper)3 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)3 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)3 CreateScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 TimeUnit (java.util.concurrent.TimeUnit)3 Slf4j (lombok.extern.slf4j.Slf4j)3