use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class ControllerImpl method getSuccessors.
@Override
public CompletableFuture<StreamSegmentsWithPredecessors> getSuccessors(Segment segment) {
Exceptions.checkNotClosed(closed.get(), this);
final long requestId = requestIdGenerator.get();
long traceId = LoggerHelpers.traceEnter(log, "getSuccessors", segment, requestId);
final CompletableFuture<SuccessorResponse> resultFuture = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<SuccessorResponse> callback = new RPCAsyncCallback<>(requestId, "getSuccessors", segment);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, GET_SEGMENTS_IMMEDIATELY_FOLLOWING, segment.getScopedName()).getSegmentsImmediatelyFollowing(ModelHelper.decode(segment), callback);
return callback.getFuture();
}, this.executor);
return resultFuture.thenApplyAsync(successors -> {
log.debug(requestId, "Received the following data from the controller {}", successors.getSegmentsList());
Map<SegmentWithRange, List<Long>> result = new HashMap<>();
for (SuccessorResponse.SegmentEntry entry : successors.getSegmentsList()) {
result.put(encode(entry.getSegment()), entry.getValueList());
}
return new StreamSegmentsWithPredecessors(result, successors.getDelegationToken());
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "getSuccessors of segment {} failed: ", segment.getSegmentId(), e);
}
LoggerHelpers.traceLeave(log, "getSuccessors", traceId, requestId);
});
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class ControllerImpl method getCurrentSegmentsForKeyValueTable.
@Override
public CompletableFuture<KeyValueTableSegments> getCurrentSegmentsForKeyValueTable(String scope, String kvtName) {
Exceptions.checkNotClosed(closed.get(), this);
Exceptions.checkNotNullOrEmpty(scope, "scope");
Exceptions.checkNotNullOrEmpty(kvtName, "stream");
long traceId = LoggerHelpers.traceEnter(log, "getCurrentSegmentsForKeyValueTable", scope, kvtName);
final long requestId = requestIdGenerator.get();
final CompletableFuture<SegmentRanges> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<SegmentRanges> callback = new RPCAsyncCallback<>(traceId, "getCurrentSegmentsKeyValueTable", scope, kvtName);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, GET_CURRENT_SEGMENTS_KEY_VALUE_TABLE, scope, kvtName).getCurrentSegmentsKeyValueTable(ModelHelper.createKeyValueTableInfo(scope, kvtName), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(ranges -> {
log.debug(requestId, "Received the following data from the controller {}", ranges.getSegmentRangesList());
NavigableMap<Double, SegmentWithRange> rangeMap = new TreeMap<>();
for (SegmentRange r : ranges.getSegmentRangesList()) {
Preconditions.checkState(r.getMinKey() <= r.getMaxKey(), "Min keyrange %s was not less than maximum keyRange %s for segment %s", r.getMinKey(), r.getMaxKey(), r.getSegmentId());
rangeMap.put(r.getMaxKey(), new SegmentWithRange(encode(r.getSegmentId()), r.getMinKey(), r.getMaxKey()));
}
return new KeyValueTableSegments(rangeMap);
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "getCurrentSegmentsForKeyValueTable for {}/{} failed: ", scope, kvtName, e);
}
LoggerHelpers.traceLeave(log, "getCurrentSegmentsForKeyValueTable", traceId);
});
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class ControllerImpl method convert.
private TxnSegments convert(CreateTxnResponse response) {
NavigableMap<Double, SegmentWithRange> rangeMap = new TreeMap<>();
for (SegmentRange r : response.getActiveSegmentsList()) {
Preconditions.checkState(r.getMinKey() <= r.getMaxKey());
rangeMap.put(r.getMaxKey(), new SegmentWithRange(encode(r.getSegmentId()), r.getMinKey(), r.getMaxKey()));
}
StreamSegments segments = new StreamSegments(rangeMap);
return new TxnSegments(segments, encode(response.getTxnId()));
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class ControllerImpl method getStreamSegments.
private StreamSegments getStreamSegments(final SegmentRanges ranges, long requestId) {
log.debug(requestId, "Received the following data from the controller {}", ranges.getSegmentRangesList());
NavigableMap<Double, SegmentWithRange> rangeMap = new TreeMap<>();
for (SegmentRange r : ranges.getSegmentRangesList()) {
Preconditions.checkState(r.getMinKey() <= r.getMaxKey(), "Min keyrange %s was not less than maximum keyRange %s for segment %s", r.getMinKey(), r.getMaxKey(), r.getSegmentId());
rangeMap.put(r.getMaxKey(), new SegmentWithRange(encode(r.getSegmentId()), r.getMinKey(), r.getMaxKey()));
}
return new StreamSegments(rangeMap);
}
use of io.pravega.client.stream.impl.SegmentWithRange in project pravega by pravega.
the class MockStreamManager method createReaderGroup.
@Override
public boolean createReaderGroup(String groupName, ReaderGroupConfig config) {
NameUtils.validateReaderGroupName(groupName);
createStreamHelper(NameUtils.getStreamForReaderGroup(groupName), StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
if (ReaderGroupConfig.DEFAULT_UUID.equals(config.getReaderGroupId())) {
config = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
}
@Cleanup StateSynchronizer<ReaderGroupState> synchronizer = clientFactory.createStateSynchronizer(NameUtils.getStreamForReaderGroup(groupName), new ReaderGroupStateUpdatesSerializer(), new ReaderGroupStateInitSerializer(), SynchronizerConfig.builder().build());
Futures.getThrowingException(controller.createReaderGroup(scope, groupName, config));
Map<SegmentWithRange, Long> segments = ReaderGroupImpl.getSegmentsForStreams(controller, config);
synchronizer.initialize(new ReaderGroupState.ReaderGroupStateInit(config, segments, getEndSegmentsForStreams(config), false));
return true;
}
Aggregations