Search in sources :

Example 21 with StreamTruncationRecord

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

the class StreamMetadataTasksTest method checkTruncateCompleteTest.

@Test(timeout = 10000)
public void checkTruncateCompleteTest() throws ExecutionException, InterruptedException {
    final ScalingPolicy policy = ScalingPolicy.fixed(1);
    final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build();
    String test = "testTruncate";
    streamStorePartialMock.createStream(SCOPE, test, configuration, System.currentTimeMillis(), null, executor).get();
    streamStorePartialMock.setState(SCOPE, test, State.ACTIVE, null, executor).get();
    streamMetadataTasks.setRequestEventWriter(new EventStreamWriterMock<>());
    // region truncate
    Map<Long, Long> map = Collections.singletonMap(0L, 1L);
    streamMetadataTasks.truncateStream(SCOPE, test, map, 0L);
    // wait till configuration is updated
    Supplier<Boolean> truncationStarted = () -> !streamStorePartialMock.getTruncationRecord(SCOPE, test, null, executor).join().getObject().isUpdating();
    Futures.loop(truncationStarted, () -> Futures.delayedFuture(Duration.ofMillis(100), executor), executor).join();
    streamStorePartialMock.setState(SCOPE, test, State.TRUNCATING, null, executor).join();
    assertFalse(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
    VersionedMetadata<StreamTruncationRecord> truncationRecord = streamStorePartialMock.getTruncationRecord(SCOPE, test, null, executor).join();
    assertTrue(truncationRecord.getObject().isUpdating());
    streamStorePartialMock.completeTruncation(SCOPE, test, truncationRecord, null, executor).join();
    assertFalse(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
    streamStorePartialMock.setState(SCOPE, test, State.ACTIVE, null, executor).join();
    assertTrue(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
    // start next update with different configuration.
    Map<Long, Long> map2 = Collections.singletonMap(0L, 10L);
    streamMetadataTasks.truncateStream(SCOPE, test, map2, 0L);
    Futures.loop(truncationStarted, () -> Futures.delayedFuture(Duration.ofMillis(100), executor), executor).join();
    streamStorePartialMock.setState(SCOPE, test, State.TRUNCATING, null, executor).join();
    // we should still get complete for previous configuration we attempted to update
    assertTrue(streamMetadataTasks.isTruncated(SCOPE, test, map, null).get());
    assertFalse(streamMetadataTasks.isTruncated(SCOPE, test, map2, null).get());
    // test truncate on a sealed stream
    String testStream = "testTruncateSealed";
    streamStorePartialMock.createStream(SCOPE, testStream, configuration, System.currentTimeMillis(), null, executor).get();
    streamStorePartialMock.setState(SCOPE, testStream, State.ACTIVE, null, executor).get();
    streamMetadataTasks.setRequestEventWriter(new EventStreamWriterMock<>());
    // region truncate
    map = Collections.singletonMap(0L, 1L);
    streamMetadataTasks.truncateStream(SCOPE, testStream, map, 0L);
    truncationStarted = () -> !streamStorePartialMock.getTruncationRecord(SCOPE, testStream, null, executor).join().getObject().isUpdating();
    Futures.loop(truncationStarted, () -> Futures.delayedFuture(Duration.ofMillis(100), executor), executor).join();
    truncationRecord = streamStorePartialMock.getTruncationRecord(SCOPE, testStream, null, executor).join();
    assertTrue(truncationRecord.getObject().isUpdating());
    streamStorePartialMock.completeTruncation(SCOPE, testStream, truncationRecord, null, executor).join();
    streamStorePartialMock.setState(SCOPE, testStream, State.SEALED, null, executor).join();
    assertFutureThrows("Should throw UnsupportedOperationException", streamMetadataTasks.isTruncated(SCOPE, testStream, map, null), e -> UnsupportedOperationException.class.isAssignableFrom(e.getClass()));
// end region
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 22 with StreamTruncationRecord

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

the class PersistentStreamBase method completeTruncation.

@Override
public CompletableFuture<Void> completeTruncation(VersionedMetadata<StreamTruncationRecord> record, OperationContext context) {
    Preconditions.checkNotNull(context, "operation context cannot be null");
    Preconditions.checkNotNull(record);
    Preconditions.checkArgument(record.getObject().isUpdating());
    StreamTruncationRecord current = record.getObject();
    if (current.isUpdating()) {
        StreamTruncationRecord completedProp = StreamTruncationRecord.complete(current);
        return Futures.toVoid(setTruncationData(new VersionedMetadata<>(completedProp, record.getVersion()), context));
    } else {
        // idempotent
        return CompletableFuture.completedFuture(null);
    }
}
Also used : StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) VersionedMetadata(io.pravega.controller.store.VersionedMetadata)

Example 23 with StreamTruncationRecord

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

the class StreamMetadataStoreTest method truncationTest.

@Test(timeout = 30000)
public void truncationTest() throws Exception {
    final String scope = "ScopeTruncate";
    final String stream = "ScopeTruncate";
    final ScalingPolicy policy = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build();
    long start = System.currentTimeMillis();
    store.createScope(scope, null, executor).get();
    store.createStream(scope, stream, configuration, start, null, executor).get();
    store.setState(scope, stream, State.ACTIVE, null, executor).get();
    Map<Long, Long> truncation = new HashMap<>();
    truncation.put(0L, 0L);
    truncation.put(1L, 0L);
    assertTrue(Futures.await(store.startTruncation(scope, stream, truncation, null, executor)));
    store.setState(scope, stream, State.TRUNCATING, null, executor).join();
    StreamTruncationRecord truncationProperty = store.getTruncationRecord(scope, stream, null, executor).join().getObject();
    assertTrue(truncationProperty.isUpdating());
    Map<Long, Long> truncation2 = new HashMap<>();
    truncation2.put(0L, 1L);
    truncation2.put(1L, 1L);
    assertFalse(Futures.await(store.startTruncation(scope, stream, truncation2, null, executor)));
    VersionedMetadata<StreamTruncationRecord> record = store.getTruncationRecord(scope, stream, null, executor).join();
    assertTrue(Futures.await(store.completeTruncation(scope, stream, record, null, executor)));
    truncationProperty = store.getTruncationRecord(scope, stream, null, executor).join().getObject();
    assertEquals(truncation, truncationProperty.getStreamCut());
    assertTrue(truncationProperty.getSpan().size() == 2);
    Map<Long, Long> truncation3 = new HashMap<>();
    truncation3.put(0L, 2L);
    truncation3.put(1L, 2L);
    assertTrue(Futures.await(store.startTruncation(scope, stream, truncation3, null, executor)));
    record = store.getTruncationRecord(scope, stream, null, executor).join();
    assertTrue(Futures.await(store.completeTruncation(scope, stream, record, null, executor)));
    store.setState(scope, stream, State.ACTIVE, null, executor).join();
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) HashMap(java.util.HashMap) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 24 with StreamTruncationRecord

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

the class StreamTestBase method testCreateStream.

@Test(timeout = 30000L)
public void testCreateStream() {
    OperationContext context = getContext();
    PersistentStreamBase stream = createStream("scope", "stream", System.currentTimeMillis(), 2, 0);
    assertEquals(State.ACTIVE, stream.getState(true, context).join());
    EpochRecord activeEpoch = stream.getActiveEpoch(true, context).join();
    assertEquals(0, activeEpoch.getEpoch());
    assertEquals(2, activeEpoch.getSegments().size());
    VersionedMetadata<StreamTruncationRecord> truncationRecord = stream.getTruncationRecord(context).join();
    assertEquals(StreamTruncationRecord.EMPTY, truncationRecord.getObject());
    VersionedMetadata<EpochTransitionRecord> etr = stream.getEpochTransition(context).join();
    assertEquals(EpochTransitionRecord.EMPTY, etr.getObject());
    VersionedMetadata<CommittingTransactionsRecord> ctr = stream.getVersionedCommitTransactionsRecord(context).join();
    assertEquals(CommittingTransactionsRecord.EMPTY, ctr.getObject());
    assertEquals(activeEpoch, stream.getEpochRecord(0, context).join());
    AssertExtensions.assertFutureThrows("", stream.getEpochRecord(1, context), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
}
Also used : TestOperationContext(io.pravega.controller.store.TestOperationContext) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) Test(org.junit.Test)

Aggregations

StreamTruncationRecord (io.pravega.controller.store.stream.records.StreamTruncationRecord)24 Test (org.junit.Test)19 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)17 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)16 HashMap (java.util.HashMap)15 AtomicLong (java.util.concurrent.atomic.AtomicLong)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)13 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)12 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)12 StreamCutRecord (io.pravega.controller.store.stream.records.StreamCutRecord)12 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)11 RGStreamCutRecord (io.pravega.shared.controller.event.RGStreamCutRecord)11 Segment (io.pravega.client.segment.impl.Segment)10 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)10 Stream (io.pravega.client.stream.Stream)10 StreamCut (io.pravega.client.stream.StreamCut)10 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)10 StreamConfigurationRecord (io.pravega.controller.store.stream.records.StreamConfigurationRecord)9 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)7