Search in sources :

Example 1 with ReaderGroupConfigRecord

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

the class AbstractReaderGroup method startUpdateConfiguration.

@Override
public CompletableFuture<Void> startUpdateConfiguration(ReaderGroupConfig configuration, OperationContext context) {
    return getVersionedConfigurationRecord(context).thenCompose(configRecord -> {
        Preconditions.checkArgument(!configRecord.getObject().isUpdating());
        Preconditions.checkArgument(configRecord.getObject().getGeneration() == configuration.getGeneration());
        ReaderGroupConfigRecord update = ReaderGroupConfigRecord.update(configuration, configuration.getGeneration() + 1, true);
        return Futures.toVoid(setConfigurationData(new VersionedMetadata<>(update, configRecord.getVersion()), context));
    });
}
Also used : ReaderGroupConfigRecord(io.pravega.controller.store.stream.records.ReaderGroupConfigRecord) VersionedMetadata(io.pravega.controller.store.VersionedMetadata)

Example 2 with ReaderGroupConfigRecord

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

the class StreamMetadataStoreTest method testReaderGroups.

@Test(timeout = 30000)
public void testReaderGroups() throws Exception {
    final String scopeRGTest = "scopeRGTest";
    final String streamRGTest = "streamRGTest";
    final ScalingPolicy policy = ScalingPolicy.fixed(1);
    final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build();
    long start = System.currentTimeMillis();
    Controller.CreateScopeStatus createScopeStatus = store.createScope(scopeRGTest, null, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    store.createStream(scopeRGTest, streamRGTest, configuration, start, null, executor).join();
    store.setState(scopeRGTest, streamRGTest, State.ACTIVE, null, executor).join();
    final String rgName = "readerGroupRGTest";
    final UUID rgId = UUID.randomUUID();
    final Segment seg0 = new Segment(scopeRGTest, streamRGTest, 0L);
    final Segment seg1 = new Segment(scopeRGTest, streamRGTest, 1L);
    ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
    Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of(scopeRGTest, streamRGTest), new StreamCutImpl(Stream.of(scopeRGTest, streamRGTest), startStreamCut));
    ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
    Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of(scopeRGTest, streamRGTest), new StreamCutImpl(Stream.of(scopeRGTest, streamRGTest), endStreamCut));
    ReaderGroupConfig rgConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
    rgConfig = ReaderGroupConfig.cloneConfig(rgConfig, rgId, 0L);
    final OperationContext rgContext = store.createRGContext(scopeRGTest, rgName, 0L);
    store.addReaderGroupToScope(scopeRGTest, rgName, rgConfig.getReaderGroupId(), rgContext, executor).join();
    store.createReaderGroup(scopeRGTest, rgName, rgConfig, System.currentTimeMillis(), rgContext, executor).join();
    UUID readerGroupId = store.getReaderGroupId(scopeRGTest, rgName, rgContext, executor).get();
    assertEquals(rgId, readerGroupId);
    ReaderGroupConfigRecord cfgRecord = store.getReaderGroupConfigRecord(scopeRGTest, rgName, rgContext, executor).join().getObject();
    assertEquals(false, cfgRecord.isUpdating());
    assertEquals(rgConfig.getGeneration(), cfgRecord.getGeneration());
    assertEquals(rgConfig.getAutomaticCheckpointIntervalMillis(), cfgRecord.getAutomaticCheckpointIntervalMillis());
    assertEquals(rgConfig.getGroupRefreshTimeMillis(), cfgRecord.getGroupRefreshTimeMillis());
    assertEquals(rgConfig.getStartingStreamCuts().size(), cfgRecord.getStartingStreamCuts().size());
    VersionedMetadata<ReaderGroupState> rgState = store.getVersionedReaderGroupState(scopeRGTest, rgName, true, rgContext, executor).get();
    assertEquals(ReaderGroupState.CREATING, rgState.getObject());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamCut(io.pravega.client.stream.StreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ReaderGroupConfigRecord(io.pravega.controller.store.stream.records.ReaderGroupConfigRecord) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Segment(io.pravega.client.segment.impl.Segment) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with ReaderGroupConfigRecord

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

the class InMemoryReaderGroup method createConfigurationIfAbsent.

@Override
CompletableFuture<Void> createConfigurationIfAbsent(ReaderGroupConfig config, OperationContext context) {
    Preconditions.checkNotNull(config);
    synchronized (lock) {
        if (configuration == null) {
            ReaderGroupConfigRecord configRecord = ReaderGroupConfigRecord.update(config, 0L, false);
            configuration = new VersionedMetadata<>(configRecord, new Version.IntVersion(0));
            log.debug("InMemoryReaderGroup::createConfigurationIfAbsent");
        }
    }
    return CompletableFuture.completedFuture(null);
}
Also used : ReaderGroupConfigRecord(io.pravega.controller.store.stream.records.ReaderGroupConfigRecord)

Aggregations

ReaderGroupConfigRecord (io.pravega.controller.store.stream.records.ReaderGroupConfigRecord)3 Segment (io.pravega.client.segment.impl.Segment)1 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)1 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)1 Stream (io.pravega.client.stream.Stream)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 StreamCut (io.pravega.client.stream.StreamCut)1 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)1 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)1 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)1 UUID (java.util.UUID)1 Test (org.junit.Test)1