use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ClientFactoryImpl method createRevisionedStreamClient.
@Override
public <T> RevisionedStreamClient<T> createRevisionedStreamClient(String streamName, Serializer<T> serializer, SynchronizerConfig config) {
log.info("Creating revisioned stream client for stream: {} with synchronizer configuration: {}", streamName, config);
Segment segment = new Segment(scope, streamName, 0);
SegmentInputStream in = inFactory.createInputStreamForSegment(segment);
// Segment sealed is not expected for Revisioned Stream Client.
Consumer<Segment> segmentSealedCallBack = s -> {
throw new IllegalStateException("RevisionedClient: Segmentsealed exception observed for segment:" + s);
};
String delegationToken = Futures.getAndHandleExceptions(controller.getOrRefreshDelegationTokenFor(segment.getScope(), segment.getStreamName()), RuntimeException::new);
SegmentOutputStream out = outFactory.createOutputStreamForSegment(segment, segmentSealedCallBack, config.getEventWriterConfig(), delegationToken);
SegmentMetadataClient meta = metaFactory.createSegmentMetadataClient(segment, delegationToken);
return new RevisionedStreamClientImpl<>(segment, in, out, meta, serializer, controller, delegationToken);
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImpl method convert.
private TxnSegments convert(CreateTxnResponse response) {
NavigableMap<Double, Segment> rangeMap = new TreeMap<>();
for (SegmentRange r : response.getActiveSegmentsList()) {
rangeMap.put(r.getMaxKey(), ModelHelper.encode(r.getSegmentId()));
}
StreamSegments segments = new StreamSegments(rangeMap, response.getDelegationToken());
return new TxnSegments(segments, ModelHelper.encode(response.getTxnId()));
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImpl method getKnownSegmentsInRange.
/*
* This method fetches the segments of a stream which definitely reside between the segments represented by
* lowerBound and the upperBound using the invariant that segment numbers monotonically increase.
*
* @param lowerBound StreamCut representing the segments of the starting point.
* @param upperBound Segments representing the ending point.
* @return Segments which reside between fromStreamCut and currentSegments.
*/
private List<Segment> getKnownSegmentsInRange(final StreamCut lowerBound, final Collection<Segment> upperBound) {
int highestCut = lowerBound.asImpl().getPositions().keySet().stream().mapToInt(s -> s.getSegmentNumber()).max().getAsInt();
int lowestCurrent = upperBound.stream().mapToInt(s -> s.getSegmentNumber()).min().getAsInt();
if (highestCut >= lowestCurrent) {
return Collections.emptyList();
}
final List<Segment> result = new ArrayList<>(lowestCurrent - highestCut);
for (int num = highestCut + 1; num < lowestCurrent; num++) {
result.add(new Segment(lowerBound.asImpl().getStream().getScope(), lowerBound.asImpl().getStream().getStreamName(), num));
}
return result;
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ControllerImpl method getSuccessors.
@Override
public CompletableFuture<StreamSegmentSuccessors> getSuccessors(final StreamCut from) {
Exceptions.checkNotClosed(closed.get(), this);
Stream stream = from.asImpl().getStream();
long traceId = LoggerHelpers.traceEnter(log, "getSuccessorsFromCut", stream);
val currentSegments = getAndHandleExceptions(getCurrentSegments(stream.getScope(), stream.getStreamName()), RuntimeException::new);
String delegationToken = currentSegments.getDelegationToken();
final Set<Segment> unread = getSegmentsInRange(from.asImpl(), currentSegments.getSegments());
LoggerHelpers.traceLeave(log, "getSuccessorsFromCut", traceId);
return CompletableFuture.completedFuture(new StreamSegmentSuccessors(unread, delegationToken));
}
use of io.pravega.client.segment.impl.Segment 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 CompletableFuture<SegmentsAtTime> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<SegmentsAtTime> callback = new RPCAsyncCallback<>();
StreamInfo streamInfo = ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName());
GetSegmentsRequest request = GetSegmentsRequest.newBuilder().setStreamInfo(streamInfo).setTimestamp(timestamp).build();
client.getSegments(request, callback);
return callback.getFuture();
}, this.executor);
return result.thenApply(segments -> {
log.debug("Received the following data from the controller {}", segments.getSegmentsList());
return segments.getSegmentsList().stream().collect(Collectors.toMap(location -> ModelHelper.encode(location.getSegmentId()), location -> location.getOffset()));
}).whenComplete((x, e) -> {
if (e != null) {
log.warn("getSegmentsAtTime failed: ", e);
}
LoggerHelpers.traceLeave(log, "getSegmentsAtTime", traceId);
});
}
Aggregations