use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.
the class BatchClientImpl method segmentToInfo.
private SegmentInfo segmentToInfo(Segment s) {
String delegationToken;
synchronized (this) {
delegationToken = latestDelegationToken.get();
}
@Cleanup SegmentMetadataClient client = segmentMetadataClientFactory.createSegmentMetadataClient(s, delegationToken);
return client.getSegmentInfo();
}
use of io.pravega.client.segment.impl.SegmentMetadataClient 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.SegmentMetadataClient in project pravega by pravega.
the class EventStreamReaderImpl method handleSegmentTruncated.
private void handleSegmentTruncated(SegmentInputStream segmentReader) throws ReinitializationRequiredException, TruncatedDataException {
Segment segmentId = segmentReader.getSegmentId();
log.info("{} encountered truncation for segment {} ", this, segmentId);
String delegationToken = groupState.getLatestDelegationToken();
@Cleanup SegmentMetadataClient metadataClient = metadataClientFactory.createSegmentMetadataClient(segmentId, delegationToken);
try {
long startingOffset = metadataClient.getSegmentInfo().getStartingOffset();
segmentReader.setOffset(startingOffset);
} catch (NoSuchSegmentException e) {
handleEndOfSegment(segmentReader);
}
throw new TruncatedDataException();
}
use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.
the class ReaderGroupImpl method getRemainingBytes.
private long getRemainingBytes(SegmentMetadataClientFactory metaFactory, StreamCut position) {
long totalLength = 0;
CompletableFuture<StreamSegmentSuccessors> unread = controller.getSuccessors(position);
StreamSegmentSuccessors unreadVal = Futures.getAndHandleExceptions(unread, RuntimeException::new);
for (Segment s : unreadVal.getSegments()) {
@Cleanup SegmentMetadataClient metadataClient = metaFactory.createSegmentMetadataClient(s, unreadVal.getDelegationToken());
totalLength += metadataClient.fetchCurrentSegmentLength();
}
for (long bytesRead : position.asImpl().getPositions().values()) {
totalLength -= bytesRead;
}
log.debug("Remaining bytes after position: {} is {}", position, totalLength);
return totalLength;
}
use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.
the class StreamCutHelper method segmentToInfos.
private CompletableFuture<List<SegmentInfo>> segmentToInfos(Collection<Segment> segments, DelegationTokenProvider tokenProvider) {
List<CompletableFuture<SegmentInfo>> results = new ArrayList<>();
for (Segment s : segments) {
SegmentMetadataClient client = segmentMetadataClientFactory.createSegmentMetadataClient(s, tokenProvider);
CompletableFuture<SegmentInfo> info = client.getSegmentInfo();
results.add(info);
info.whenComplete((v, e) -> client.close());
}
return Futures.allOfWithResults(results);
}
Aggregations