use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class EventStreamWriterImpl method beginTxn.
@Override
public Transaction<Type> beginTxn() {
TxnSegments txnSegments = getAndHandleExceptions(controller.createTransaction(stream, config.getTransactionTimeoutTime(), config.getTransactionTimeoutScaleGracePeriod()), RuntimeException::new);
UUID txnId = txnSegments.getTxnId();
Map<Segment, SegmentTransaction<Type>> transactions = new HashMap<>();
for (Segment s : txnSegments.getSteamSegments().getSegments()) {
SegmentOutputStream out = outputStreamFactory.createOutputStreamForTransaction(s, txnId, segmentSealedCallBack, config, txnSegments.getSteamSegments().getDelegationToken());
SegmentTransactionImpl<Type> impl = new SegmentTransactionImpl<>(txnId, out, serializer);
transactions.put(s, impl);
}
pinger.startPing(txnId);
return new TransactionImpl<Type>(txnId, transactions, txnSegments.getSteamSegments(), controller, stream, pinger);
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class EventStreamWriterImpl method getTxn.
@Override
public Transaction<Type> getTxn(UUID txId) {
StreamSegments segments = getAndHandleExceptions(controller.getCurrentSegments(stream.getScope(), stream.getStreamName()), RuntimeException::new);
Status status = getAndHandleExceptions(controller.checkTransactionStatus(stream, txId), RuntimeException::new);
if (status != Status.OPEN) {
return new TransactionImpl<>(txId, controller, stream);
}
Map<Segment, SegmentTransaction<Type>> transactions = new HashMap<>();
for (Segment s : segments.getSegments()) {
SegmentOutputStream out = outputStreamFactory.createOutputStreamForTransaction(s, txId, segmentSealedCallBack, config, segments.getDelegationToken());
SegmentTransactionImpl<Type> impl = new SegmentTransactionImpl<>(txId, out, serializer);
transactions.put(s, impl);
}
return new TransactionImpl<Type>(txId, transactions, segments, controller, stream, pinger);
}
use of io.pravega.client.segment.impl.Segment 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.Segment in project pravega by pravega.
the class ReaderGroupImpl method unreadBytes.
@Override
public long unreadBytes() {
@Cleanup StateSynchronizer<ReaderGroupState> synchronizer = createSynchronizer();
synchronizer.fetchUpdates();
Optional<Map<Stream, Map<Segment, Long>>> checkPointedPositions = synchronizer.getState().getPositionsForLastCompletedCheckpoint();
SegmentMetadataClientFactory metaFactory = new SegmentMetadataClientFactoryImpl(controller, connectionFactory);
if (checkPointedPositions.isPresent()) {
log.debug("Computing unread bytes based on the last checkPoint position");
return getUnreadBytes(checkPointedPositions.get(), metaFactory);
} else {
log.info("No checkpoints found, using the last known offset to compute unread bytes");
return getUnreadBytes(synchronizer.getState().getPositions(), metaFactory);
}
}
use of io.pravega.client.segment.impl.Segment in project pravega by pravega.
the class ReaderGroupImpl method completeCheckpoint.
@SneakyThrows(CheckpointFailedException.class)
private Checkpoint completeCheckpoint(String checkpointName, StateSynchronizer<ReaderGroupState> synchronizer) {
ReaderGroupState state = synchronizer.getState();
Map<Segment, Long> map = state.getPositionsForCompletedCheckpoint(checkpointName);
synchronizer.updateStateUnconditionally(new ClearCheckpoints(checkpointName));
if (map == null) {
throw new CheckpointFailedException("Checkpoint was cleared before results could be read.");
}
return new CheckpointImpl(checkpointName, map);
}
Aggregations