use of io.pravega.shared.controller.tracing.RPCTracingTags.GET_SEGMENTS in project pravega by pravega.
the class ControllerImpl method getSegmentsAtTime.
@Override
public CompletableFuture<Map<Segment, Long>> getSegmentsAtTime(final Stream stream, final long timestamp) {
Exceptions.checkNotClosed(closed.get(), this);
Preconditions.checkNotNull(stream, "stream");
long traceId = LoggerHelpers.traceEnter(log, "getSegmentsAtTime", stream, timestamp);
final long requestId = requestIdGenerator.get();
final CompletableFuture<SegmentsAtTime> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<SegmentsAtTime> callback = new RPCAsyncCallback<>(traceId, "getSegmentsAtTime", stream, timestamp);
StreamInfo streamInfo = ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName(), AccessOperation.NONE);
GetSegmentsRequest request = GetSegmentsRequest.newBuilder().setStreamInfo(streamInfo).setTimestamp(timestamp).build();
client.withDeadlineAfter(timeoutMillis, TimeUnit.MILLISECONDS).getSegments(request, callback);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, GET_SEGMENTS, streamInfo.getScope(), streamInfo.getStream()).getSegments(request, callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(segments -> {
log.debug(requestId, "Received the following data from the controller {}", segments.getSegmentsList());
return segments.getSegmentsList().stream().collect(Collectors.toMap(location -> encode(location.getSegmentId()), SegmentsAtTime.SegmentLocation::getOffset));
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "get Segments of {} at time {} failed: ", stream.getStreamName(), timestamp, e);
}
LoggerHelpers.traceLeave(log, "getSegmentsAtTime", traceId);
});
}
Aggregations