use of io.pravega.client.segment.impl.SegmentOutputStream in project pravega by pravega.
the class SegmentSelector method createMissingWriters.
private void createMissingWriters(Consumer<Segment> segmentSealedCallBack, String delegationToken) {
for (Segment segment : currentSegments.getSegments()) {
if (!writers.containsKey(segment)) {
SegmentOutputStream out = outputStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallBack, config, delegationToken);
writers.put(segment, out);
}
}
}
use of io.pravega.client.segment.impl.SegmentOutputStream in project pravega by pravega.
the class TransactionalEventStreamWriterImpl method getTxn.
@Override
public Transaction<Type> getTxn(UUID txId) {
// check if the transaction is open.
Status status = Futures.getThrowingException(controller.checkTransactionStatus(stream, txId));
if (status != Status.OPEN) {
return new TransactionImpl<>(writerId, txId, controller, stream);
}
// get the segments corresponding to the transaction.
StreamSegments segments = Futures.getThrowingException(controller.getEpochSegments(stream.getScope(), stream.getStreamName(), getEpoch(txId)));
assert segments != null : "Epoch segments returned is null";
Preconditions.checkState(segments.getSegments().size() > 0, "There should be at least 1 epoch segment");
// Create OutputStream for every segment.
Map<Segment, SegmentTransaction<Type>> transactions = new HashMap<>();
DelegationTokenProvider tokenProvider = null;
for (Segment s : segments.getSegments()) {
if (tokenProvider == null) {
tokenProvider = DelegationTokenProviderFactory.create(controller, s, AccessOperation.WRITE);
}
SegmentOutputStream out = outputStreamFactory.createOutputStreamForTransaction(s, txId, config, tokenProvider);
SegmentTransactionImpl<Type> impl = new SegmentTransactionImpl<>(txId, out, serializer);
transactions.put(s, impl);
}
pinger.startPing(txId);
return new TransactionImpl<Type>(writerId, txId, transactions, segments, controller, stream, pinger);
}
use of io.pravega.client.segment.impl.SegmentOutputStream in project pravega by pravega.
the class SegmentSelector method createMissingWriters.
private void createMissingWriters(Consumer<Segment> segmentSealedCallBack) {
for (Segment segment : currentSegments.getSegments()) {
if (!writers.containsKey(segment)) {
log.debug("Creating writer for segment {}", segment);
SegmentOutputStream out = outputStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallBack, config, tokenProvider);
writers.put(segment, out);
}
}
}
use of io.pravega.client.segment.impl.SegmentOutputStream in project pravega by pravega.
the class SegmentSelector method updateSegments.
@Synchronized
private List<PendingEvent> updateSegments(StreamSegments newStreamSegments, Consumer<Segment> segmentSealedCallBack) {
Preconditions.checkState(newStreamSegments.getNumberOfSegments() > 0, "Writers cannot proceed writing since the stream %s is sealed", stream);
Preconditions.checkState(!isStreamSealed(), "Writers cannot proceed writing since the stream %s is sealed", stream);
currentSegments = newStreamSegments;
createMissingWriters(segmentSealedCallBack);
List<PendingEvent> toResend = new ArrayList<>();
Iterator<Entry<Segment, SegmentOutputStream>> iter = writers.entrySet().iterator();
while (iter.hasNext()) {
Entry<Segment, SegmentOutputStream> entry = iter.next();
if (!currentSegments.getSegments().contains(entry.getKey())) {
SegmentOutputStream writer = entry.getValue();
log.info("Closing writer {} on segment {} during segment refresh", writer, entry.getKey());
iter.remove();
try {
writer.close();
} catch (SegmentSealedException e) {
log.info("Caught segment sealed while refreshing on segment {}", entry.getKey());
}
toResend.addAll(writer.getUnackedEventsOnSeal());
}
}
return toResend;
}
use of io.pravega.client.segment.impl.SegmentOutputStream in project pravega by pravega.
the class EventStreamWriterImpl method writeEventInternal.
private CompletableFuture<Void> writeEventInternal(String routingKey, Type event) {
Preconditions.checkNotNull(event);
Exceptions.checkNotClosed(closed.get(), this);
ByteBuffer data = serializer.serialize(event);
CompletableFuture<Void> ackFuture = new CompletableFuture<Void>();
synchronized (writeFlushLock) {
if (config.isEnableLargeEvents() && data.remaining() > Serializer.MAX_EVENT_SIZE) {
writeLargeEvent(routingKey, Collections.singletonList(data), ackFuture);
} else {
synchronized (writeSealLock) {
SegmentOutputStream segmentWriter = getSegmentWriter(routingKey);
segmentWriter.write(PendingEvent.withHeader(routingKey, data, ackFuture));
}
}
}
return ackFuture;
}
Aggregations