use of io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment in project pravega by pravega.
the class ReaderGroupStateManager method releaseSegment.
/**
* Releases a segment to another reader. This reader should no longer read from the segment.
*
* @param segment The segment to be released
* @param lastOffset The offset from which the new owner should start reading from.
* @param timeLag How far the reader is from the tail of the stream in time.
* @return a boolean indicating if the segment was successfully released.
* @throws ReinitializationRequiredException If the reader has been declared offline.
*/
boolean releaseSegment(Segment segment, long lastOffset, long timeLag) throws ReinitializationRequiredException {
sync.updateState(state -> {
Set<Segment> segments = state.getSegments(readerId);
if (segments == null || !segments.contains(segment) || state.getCheckpointForReader(readerId) != null || !doesReaderOwnTooManySegments(state)) {
return null;
}
List<ReaderGroupStateUpdate> result = new ArrayList<>(2);
result.add(new ReleaseSegment(readerId, segment, lastOffset));
result.add(new UpdateDistanceToTail(readerId, timeLag));
return result;
});
ReaderGroupState state = sync.getState();
releaseTimer.reset(calculateReleaseTime(readerId, state));
acquireTimer.reset(calculateAcquireTime(readerId, state));
if (!state.isReaderOnline(readerId)) {
throw new ReinitializationRequiredException();
}
return !state.getSegments(readerId).contains(segment);
}
Aggregations