Search in sources :

Example 11 with SealStreamTask

use of io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask in project pravega by pravega.

the class RequestHandlersTest method testDeleteStreamReplay.

@Test
public void testDeleteStreamReplay() {
    String stream = "delete";
    createStreamInStore(stream, scope);
    SealStreamTask sealStreamTask = new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStore, executor);
    DeleteStreamTask deleteStreamTask = new DeleteStreamTask(streamMetadataTasks, streamStore, bucketStore, executor);
    // seal stream.
    SealStreamEvent sealEvent = new SealStreamEvent(scope, stream, 0L);
    // set state to sealing and send event to the processor
    streamStore.setState(scope, stream, State.SEALING, null, executor).join();
    sealStreamTask.execute(sealEvent).join();
    assertEquals(State.SEALED, streamStore.getState(scope, stream, true, null, executor).join());
    // delete the stream
    long creationTime = streamStore.getCreationTime(scope, stream, null, executor).join();
    DeleteStreamEvent firstDeleteEvent = new DeleteStreamEvent(scope, stream, 0L, creationTime);
    deleteStreamTask.execute(firstDeleteEvent).join();
    // recreate stream with same name in the store
    createStreamInStore(stream, scope);
    long newCreationTime = streamStore.getCreationTime(scope, stream, null, executor).join();
    assertNotEquals(creationTime, newCreationTime);
    // seal stream.
    sealEvent = new SealStreamEvent(scope, stream, 0L);
    // set state to sealing and send event to the processor
    streamStore.setState(scope, stream, State.SEALING, null, executor).join();
    sealStreamTask.execute(sealEvent).join();
    assertEquals(State.SEALED, streamStore.getState(scope, stream, true, null, executor).join());
    // replay old event. it should not seal the stream
    AssertExtensions.assertFutureThrows("Replaying older delete event should have no effect", deleteStreamTask.execute(firstDeleteEvent), e -> Exceptions.unwrap(e) instanceof IllegalArgumentException);
    DeleteStreamEvent secondDeleteEvent = new DeleteStreamEvent(scope, stream, 0L, newCreationTime);
    // now delete should succeed
    deleteStreamTask.execute(secondDeleteEvent).join();
}
Also used : DeleteStreamEvent(io.pravega.shared.controller.event.DeleteStreamEvent) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 12 with SealStreamTask

use of io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask in project pravega by pravega.

the class RequestHandlersTest method testSealIgnoreFairness.

@Test
public void testSealIgnoreFairness() {
    StreamRequestHandler streamRequestHandler = new StreamRequestHandler(new AutoScaleTask(streamMetadataTasks, streamStore, executor), new ScaleOperationTask(streamMetadataTasks, streamStore, executor), new UpdateStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStore, executor), new DeleteStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new TruncateStreamTask(streamMetadataTasks, streamStore, executor), new CreateReaderGroupTask(streamMetadataTasks, streamStore, executor), new DeleteReaderGroupTask(streamMetadataTasks, streamStore, executor), new UpdateReaderGroupTask(streamMetadataTasks, streamStore, executor), streamStore, new DeleteScopeTask(streamMetadataTasks, streamStore, kvtStore, kvtTasks, executor), executor);
    String fairness = "fairness";
    streamStore.createScope(fairness, null, executor).join();
    streamMetadataTasks.createStream(fairness, fairness, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build(), System.currentTimeMillis(), 0L).join();
    // 1. set segment helper mock to throw exception
    doAnswer(x -> Futures.failedFuture(new RuntimeException())).when(segmentHelper).sealSegment(anyString(), anyString(), anyLong(), anyString(), anyLong());
    // 2. start process --> this should fail with a retryable exception while talking to segment store!
    streamStore.setState(fairness, fairness, State.SEALING, null, executor).join();
    assertEquals(State.SEALING, streamStore.getState(fairness, fairness, true, null, executor).join());
    SealStreamEvent event = new SealStreamEvent(fairness, fairness, 0L);
    AssertExtensions.assertFutureThrows("", streamRequestHandler.process(event, () -> false), e -> Exceptions.unwrap(e) instanceof RuntimeException);
    verify(segmentHelper, atLeastOnce()).sealSegment(anyString(), anyString(), anyLong(), anyString(), anyLong());
    // 3. set waiting processor to "random name"
    streamStore.createWaitingRequestIfAbsent(fairness, fairness, "myProcessor", null, executor).join();
    // 4. reset segment helper to return success
    doAnswer(x -> CompletableFuture.completedFuture(null)).when(segmentHelper).sealSegment(anyString(), anyString(), anyLong(), anyString(), anyLong());
    // 5. process again. it should succeed while ignoring waiting processor
    streamRequestHandler.process(event, () -> false).join();
    assertEquals(State.SEALED, streamStore.getState(fairness, fairness, true, null, executor).join());
    // 6. run a new update. it should fail because of waiting processor.
    SealStreamEvent event2 = new SealStreamEvent(fairness, fairness, 0L);
    AssertExtensions.assertFutureThrows("", streamRequestHandler.process(event2, () -> false), e -> Exceptions.unwrap(e) instanceof StoreException.OperationNotAllowedException);
    streamStore.deleteWaitingRequestConditionally(fairness, fairness, "myProcessor", null, executor).join();
}
Also used : DeleteScopeTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteScopeTask) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) CreateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.CreateReaderGroupTask) DeleteReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteReaderGroupTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ScaleOperationTask(io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask) StoreException(io.pravega.controller.store.stream.StoreException) AutoScaleTask(io.pravega.controller.server.eventProcessor.requesthandlers.AutoScaleTask) StreamRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.StreamRequestHandler) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) UpdateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateReaderGroupTask) TruncateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask) Test(org.junit.Test)

Example 13 with SealStreamTask

use of io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask in project pravega by pravega.

the class RequestHandlersTest method testDeleteAssociatedStream.

@Test
public void testDeleteAssociatedStream() {
    String stream = "deleteAssociated";
    createStreamInStore(stream, scope);
    String markStream = NameUtils.getMarkStreamForStream(stream);
    createStreamInStore(markStream, scope);
    SealStreamTask sealStreamTask = new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStore, executor);
    DeleteStreamTask deleteStreamTask = new DeleteStreamTask(streamMetadataTasks, streamStore, bucketStore, executor);
    // create mark stream
    // seal stream.
    SealStreamEvent sealEvent = new SealStreamEvent(scope, stream, 0L);
    // set state to sealing and send event to the processor
    streamStore.setState(scope, stream, State.SEALING, null, executor).join();
    sealStreamTask.execute(sealEvent).join();
    assertEquals(State.SEALED, streamStore.getState(scope, stream, true, null, executor).join());
    // mark stream should still be present and active
    assertTrue(streamStore.checkStreamExists(scope, markStream, null, executor).join());
    assertEquals(streamStore.getState(scope, markStream, true, null, executor).join(), State.ACTIVE);
    // delete the stream
    long creationTime = streamStore.getCreationTime(scope, stream, null, executor).join();
    DeleteStreamEvent firstDeleteEvent = new DeleteStreamEvent(scope, stream, 0L, creationTime);
    deleteStreamTask.execute(firstDeleteEvent).join();
    // verify that mark stream is also deleted
    assertFalse(streamStore.checkStreamExists(scope, markStream, null, executor).join());
}
Also used : DeleteStreamEvent(io.pravega.shared.controller.event.DeleteStreamEvent) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 14 with SealStreamTask

use of io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask in project pravega by pravega.

the class RequestHandlersTest method testUpdateIgnoreFairness.

@Test
public void testUpdateIgnoreFairness() {
    StreamRequestHandler streamRequestHandler = new StreamRequestHandler(new AutoScaleTask(streamMetadataTasks, streamStore, executor), new ScaleOperationTask(streamMetadataTasks, streamStore, executor), new UpdateStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStore, executor), new DeleteStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new TruncateStreamTask(streamMetadataTasks, streamStore, executor), new CreateReaderGroupTask(streamMetadataTasks, streamStore, executor), new DeleteReaderGroupTask(streamMetadataTasks, streamStore, executor), new UpdateReaderGroupTask(streamMetadataTasks, streamStore, executor), streamStore, new DeleteScopeTask(streamMetadataTasks, streamStore, kvtStore, kvtTasks, executor), executor);
    String fairness = "fairness";
    streamStore.createScope(fairness, null, executor).join();
    streamMetadataTasks.createStream(fairness, fairness, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build(), System.currentTimeMillis(), 0L).join();
    // 1. set segment helper mock to throw exception
    doAnswer(x -> Futures.failedFuture(new RuntimeException())).when(segmentHelper).updatePolicy(anyString(), anyString(), any(), anyLong(), anyString(), anyLong());
    // 2. start process --> this should fail with a retryable exception while talking to segment store!
    streamStore.startUpdateConfiguration(fairness, fairness, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build(), null, executor).join();
    streamStore.setState(fairness, fairness, State.UPDATING, null, executor).join();
    assertEquals(State.UPDATING, streamStore.getState(fairness, fairness, true, null, executor).join());
    UpdateStreamEvent event = new UpdateStreamEvent(fairness, fairness, 0L);
    AssertExtensions.assertFutureThrows("", streamRequestHandler.process(event, () -> false), e -> Exceptions.unwrap(e) instanceof RuntimeException);
    verify(segmentHelper, atLeastOnce()).updatePolicy(anyString(), anyString(), any(), anyLong(), anyString(), anyLong());
    // 3. set waiting processor to "random name"
    streamStore.createWaitingRequestIfAbsent(fairness, fairness, "myProcessor", null, executor).join();
    // 4. reset segment helper to return success
    doAnswer(x -> CompletableFuture.completedFuture(null)).when(segmentHelper).updatePolicy(anyString(), anyString(), any(), anyLong(), anyString(), anyLong());
    // 5. process again. it should succeed while ignoring waiting processor
    streamRequestHandler.process(event, () -> false).join();
    assertEquals(State.ACTIVE, streamStore.getState(fairness, fairness, true, null, executor).join());
    // 6. run a new update. it should fail because of waiting processor and our state does not allow us to ignore waiting processor
    UpdateStreamEvent event2 = new UpdateStreamEvent(fairness, fairness, 0L);
    AssertExtensions.assertFutureThrows("", streamRequestHandler.process(event2, () -> false), e -> Exceptions.unwrap(e) instanceof StoreException.OperationNotAllowedException);
    streamStore.deleteWaitingRequestConditionally(fairness, fairness, "myProcessor", null, executor).join();
}
Also used : DeleteScopeTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteScopeTask) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) CreateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.CreateReaderGroupTask) DeleteReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteReaderGroupTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ScaleOperationTask(io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask) StoreException(io.pravega.controller.store.stream.StoreException) AutoScaleTask(io.pravega.controller.server.eventProcessor.requesthandlers.AutoScaleTask) StreamRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.StreamRequestHandler) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) UpdateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateReaderGroupTask) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) TruncateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask) Test(org.junit.Test)

Example 15 with SealStreamTask

use of io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask in project pravega by pravega.

the class RequestHandlersTest method testScaleIgnoreFairness.

@Test
public void testScaleIgnoreFairness() {
    StreamRequestHandler streamRequestHandler = new StreamRequestHandler(new AutoScaleTask(streamMetadataTasks, streamStore, executor), new ScaleOperationTask(streamMetadataTasks, streamStore, executor), new UpdateStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStore, executor), new DeleteStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new TruncateStreamTask(streamMetadataTasks, streamStore, executor), new CreateReaderGroupTask(streamMetadataTasks, streamStore, executor), new DeleteReaderGroupTask(streamMetadataTasks, streamStore, executor), new UpdateReaderGroupTask(streamMetadataTasks, streamStore, executor), streamStore, new DeleteScopeTask(streamMetadataTasks, streamStore, kvtStore, kvtTasks, executor), executor);
    String fairness = "fairness";
    streamStore.createScope(fairness, null, executor).join();
    streamMetadataTasks.createStream(fairness, fairness, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build(), System.currentTimeMillis(), 0L).join();
    // 1. set segment helper mock to throw exception
    doAnswer(x -> Futures.failedFuture(new RuntimeException())).when(segmentHelper).sealSegment(anyString(), anyString(), anyLong(), anyString(), anyLong());
    // 2. start scale --> this should fail with a retryable exception while talking to segment store!
    ScaleOpEvent scaleEvent = new ScaleOpEvent(fairness, fairness, Collections.singletonList(0L), Collections.singletonList(new AbstractMap.SimpleEntry<>(0.0, 1.0)), false, System.currentTimeMillis(), 0L);
    AssertExtensions.assertFutureThrows("", streamRequestHandler.process(scaleEvent, () -> false), e -> Exceptions.unwrap(e) instanceof RuntimeException);
    // verify that scale was started
    assertEquals(State.SCALING, streamStore.getState(fairness, fairness, true, null, executor).join());
    // 3. set waiting processor to "random name"
    streamStore.createWaitingRequestIfAbsent(fairness, fairness, "myProcessor", null, executor).join();
    // 4. reset segment helper to return success
    doAnswer(x -> CompletableFuture.completedFuture(true)).when(segmentHelper).sealSegment(anyString(), anyString(), anyLong(), anyString(), anyLong());
    // 5. process again. it should succeed while ignoring waiting processor
    streamRequestHandler.process(scaleEvent, () -> false).join();
    EpochRecord activeEpoch = streamStore.getActiveEpoch(fairness, fairness, null, true, executor).join();
    assertEquals(1, activeEpoch.getEpoch());
    assertEquals(State.ACTIVE, streamStore.getState(fairness, fairness, true, null, executor).join());
    // 6. run a new scale. it should fail because of waiting processor.
    ScaleOpEvent scaleEvent2 = new ScaleOpEvent(fairness, fairness, Collections.singletonList(NameUtils.computeSegmentId(1, 1)), Collections.singletonList(new AbstractMap.SimpleEntry<>(0.0, 1.0)), false, System.currentTimeMillis(), 0L);
    AssertExtensions.assertFutureThrows("", streamRequestHandler.process(scaleEvent2, () -> false), e -> Exceptions.unwrap(e) instanceof StoreException.OperationNotAllowedException);
    streamStore.deleteWaitingRequestConditionally(fairness, fairness, "myProcessor", null, executor).join();
}
Also used : DeleteScopeTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteScopeTask) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) CreateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.CreateReaderGroupTask) DeleteReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteReaderGroupTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ScaleOperationTask(io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask) ScaleOpEvent(io.pravega.shared.controller.event.ScaleOpEvent) StoreException(io.pravega.controller.store.stream.StoreException) AutoScaleTask(io.pravega.controller.server.eventProcessor.requesthandlers.AutoScaleTask) StreamRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.StreamRequestHandler) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) UpdateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateReaderGroupTask) TruncateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask) Test(org.junit.Test)

Aggregations

SealStreamTask (io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask)19 DeleteStreamTask (io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask)17 ScaleOperationTask (io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask)16 AutoScaleTask (io.pravega.controller.server.eventProcessor.requesthandlers.AutoScaleTask)15 StreamRequestHandler (io.pravega.controller.server.eventProcessor.requesthandlers.StreamRequestHandler)15 TruncateStreamTask (io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask)15 UpdateStreamTask (io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask)15 CreateReaderGroupTask (io.pravega.controller.server.eventProcessor.requesthandlers.CreateReaderGroupTask)12 DeleteReaderGroupTask (io.pravega.controller.server.eventProcessor.requesthandlers.DeleteReaderGroupTask)12 DeleteScopeTask (io.pravega.controller.server.eventProcessor.requesthandlers.DeleteScopeTask)12 UpdateReaderGroupTask (io.pravega.controller.server.eventProcessor.requesthandlers.UpdateReaderGroupTask)12 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)11 Test (org.junit.Test)10 StreamMetadataTasks (io.pravega.controller.task.Stream.StreamMetadataTasks)9 StreamTransactionMetadataTasks (io.pravega.controller.task.Stream.StreamTransactionMetadataTasks)9 StoreException (io.pravega.controller.store.stream.StoreException)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ControllerService (io.pravega.controller.server.ControllerService)7 BucketStore (io.pravega.controller.store.stream.BucketStore)7 EventHelper (io.pravega.controller.task.EventHelper)7