Search in sources :

Example 1 with TruncatedDataException

use of io.pravega.client.stream.TruncatedDataException 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 TruncatedDataException

use of io.pravega.client.stream.TruncatedDataException 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();
}
Also used : TruncatedDataException(io.pravega.client.stream.TruncatedDataException) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) NoSuchSegmentException(io.pravega.client.segment.impl.NoSuchSegmentException)

Example 3 with TruncatedDataException

use of io.pravega.client.stream.TruncatedDataException in project pravega by pravega.

the class StateSynchronizerImpl method fetchUpdates.

@Override
public void fetchUpdates() {
    Revision revision = getRevisionToReadFrom(true);
    log.trace("Fetching updates after {} ", revision);
    try {
        val iter = client.readFrom(revision);
        while (iter.hasNext()) {
            Entry<Revision, UpdateOrInit<StateT>> entry = iter.next();
            log.trace("Found entry {} ", entry.getValue());
            if (entry.getValue().isInit()) {
                InitialUpdate<StateT> init = entry.getValue().getInit();
                if (isNewer(entry.getKey())) {
                    updateCurrentState(init.create(segment.getScopedStreamName(), entry.getKey()));
                }
            } else {
                applyUpdates(entry.getKey().asImpl(), entry.getValue().getUpdates());
            }
        }
    } catch (TruncatedDataException e) {
        log.warn("{} encountered truncation on segment {}", this, segment);
        handleTruncation();
    }
}
Also used : lombok.val(lombok.val) Revision(io.pravega.client.state.Revision) TruncatedDataException(io.pravega.client.stream.TruncatedDataException)

Aggregations

TruncatedDataException (io.pravega.client.stream.TruncatedDataException)3 NoSuchSegmentException (io.pravega.client.segment.impl.NoSuchSegmentException)1 Segment (io.pravega.client.segment.impl.Segment)1 SegmentInfo (io.pravega.client.segment.impl.SegmentInfo)1 SegmentMetadataClient (io.pravega.client.segment.impl.SegmentMetadataClient)1 Revision (io.pravega.client.state.Revision)1 Cleanup (lombok.Cleanup)1 lombok.val (lombok.val)1