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));
});
}
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());
}
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);
}
Aggregations