Search in sources :

Example 1 with SegmentInfo

use of io.pravega.client.segment.impl.SegmentInfo in project pravega by pravega.

the class RevisionedStreamClientImpl method readFrom.

@Override
public Iterator<Entry<Revision, T>> readFrom(Revision start) {
    synchronized (lock) {
        long startOffset = start.asImpl().getOffsetInSegment();
        SegmentInfo segmentInfo = meta.getSegmentInfo();
        long endOffset = segmentInfo.getWriteOffset();
        if (startOffset < segmentInfo.getStartingOffset()) {
            throw new TruncatedDataException("Data at the supplied revision has been truncated.");
        }
        log.trace("Creating iterator from {} until {}", startOffset, endOffset);
        return new StreamIterator(startOffset, endOffset);
    }
}
Also used : TruncatedDataException(io.pravega.client.stream.TruncatedDataException) SegmentInfo(io.pravega.client.segment.impl.SegmentInfo)

Example 2 with SegmentInfo

use of io.pravega.client.segment.impl.SegmentInfo in project pravega by pravega.

the class BatchClientImpl method getSegmentRange.

/*
     * Given a segment, fetch its SegmentRange.
     * - If segment is part of startStreamCut / endStreamCut update startOffset and endOffset accordingly.
     * - If segment is not part of the streamCuts fetch the data using SegmentMetadataClient.
     */
private SegmentRange getSegmentRange(final Segment segment, final StreamCut startStreamCut, final StreamCut endStreamCut) {
    SegmentRangeImpl.SegmentRangeImplBuilder segmentRangeBuilder = SegmentRangeImpl.builder().segment(segment);
    if (startStreamCut.asImpl().getPositions().containsKey(segment) && endStreamCut.asImpl().getPositions().containsKey(segment)) {
        // use the meta data present in startStreamCut and endStreamCuts.
        segmentRangeBuilder.startOffset(startStreamCut.asImpl().getPositions().get(segment)).endOffset(endStreamCut.asImpl().getPositions().get(segment));
    } else {
        // use segment meta data client to fetch the segment offsets.
        SegmentInfo r = segmentToInfo(segment);
        segmentRangeBuilder.startOffset(startStreamCut.asImpl().getPositions().getOrDefault(segment, r.getStartingOffset())).endOffset(endStreamCut.asImpl().getPositions().getOrDefault(segment, r.getWriteOffset()));
    }
    return segmentRangeBuilder.build();
}
Also used : SegmentInfo(io.pravega.client.segment.impl.SegmentInfo)

Aggregations

SegmentInfo (io.pravega.client.segment.impl.SegmentInfo)2 TruncatedDataException (io.pravega.client.stream.TruncatedDataException)1