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;
}
use of io.pravega.client.segment.impl.SegmentOutputStream in project pravega by pravega.
the class EventStreamWriterImpl method resend.
@GuardedBy("writeSealLock")
private void resend(List<PendingEvent> toResend) {
while (!toResend.isEmpty()) {
List<PendingEvent> unsent = new ArrayList<>();
boolean sendFailed = false;
log.info("Resending {} events", toResend.size());
for (PendingEvent event : toResend) {
if (sendFailed) {
unsent.add(event);
} else {
SegmentOutputStream segmentWriter = selector.getSegmentOutputStreamForKey(event.getRoutingKey());
if (segmentWriter == null) {
log.info("No writer for segment during resend.");
unsent.addAll(selector.refreshSegmentEventWriters(segmentSealedCallBack));
sendFailed = true;
} else {
segmentWriter.write(event);
}
}
}
toResend = unsent;
}
}
use of io.pravega.client.segment.impl.SegmentOutputStream in project pravega by pravega.
the class EventStreamWriterImpl method getSegmentWriter.
private SegmentOutputStream getSegmentWriter(String routingKey) {
SegmentOutputStream segmentWriter = selector.getSegmentOutputStreamForKey(routingKey);
while (segmentWriter == null) {
log.info("Don't have a writer for segment: {}", selector.getSegmentForEvent(routingKey));
handleMissingLog();
segmentWriter = selector.getSegmentOutputStreamForKey(routingKey);
}
return segmentWriter;
}
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;
}
Aggregations