use of io.pravega.client.segment.impl.NoSuchSegmentException in project pravega by pravega.
the class EventStreamWriterImpl method writeLargeEvent.
@GuardedBy("writeFlushLock")
private void writeLargeEvent(String routingKey, List<ByteBuffer> events, CompletableFuture<Void> ackFuture) {
flush();
boolean success = false;
LargeEventWriter writer = new LargeEventWriter(UUID.randomUUID(), controller, connectionPool);
while (!success) {
Segment segment = selector.getSegmentForEvent(routingKey);
try {
writer.writeLargeEvent(segment, events, tokenProvider, config);
success = true;
ackFuture.complete(null);
} catch (SegmentSealedException | NoSuchSegmentException e) {
log.warn("Write large event on segment {} failed due to {}, it will be retried.", segment, e.getMessage());
handleLogSealed(segment);
tryWaitForSuccessors();
// Make sure that the successors are not sealed themselves.
if (selector.isStreamSealed()) {
ackFuture.completeExceptionally(new SegmentSealedException(segment.toString()));
break;
}
handleMissingLog();
} catch (AuthenticationException e) {
ackFuture.completeExceptionally(e);
break;
}
}
}
use of io.pravega.client.segment.impl.NoSuchSegmentException in project pravega by pravega.
the class SegmentSelector method refreshSegmentEventWritersUponSealed.
/**
* Refresh segment writers corresponding to the successors of the sealed segment and return inflight event list of the sealed segment.
* The segment writer for sealed segment is not removed.
* @param sealedSegment The sealed segment.
* @param segmentSealedCallback Sealed segment callback.
* @return List of pending events.
*/
public List<PendingEvent> refreshSegmentEventWritersUponSealed(Segment sealedSegment, Consumer<Segment> segmentSealedCallback) {
StreamSegmentsWithPredecessors successors = Futures.getAndHandleExceptions(controller.getSuccessors(sealedSegment), t -> {
log.error("Error while fetching successors for segment: {}", sealedSegment, t);
// Remove all writers and fail all pending writes
Exception e = (t instanceof RetriesExhaustedException) ? new ControllerFailureException(t) : new NoSuchSegmentException(sealedSegment.toString(), t);
removeAllWriters().forEach(event -> event.getAckFuture().completeExceptionally(e));
return null;
});
if (successors == null) {
return Collections.emptyList();
} else if (successors.getSegmentToPredecessor().isEmpty()) {
log.warn("Stream {} is sealed since no successor segments found for segment {} ", sealedSegment.getStream(), sealedSegment);
Exception e = new IllegalStateException("Writes cannot proceed since the stream is sealed");
removeAllWriters().forEach(pendingEvent -> pendingEvent.getAckFuture().completeExceptionally(e));
sealed.set(true);
return Collections.emptyList();
} else {
return updateSegmentsUponSealed(successors, sealedSegment, segmentSealedCallback);
}
}
use of io.pravega.client.segment.impl.NoSuchSegmentException in project pravega by pravega.
the class PeriodicWatermarking method watermark.
/**
* This method computes and emits a new watermark for the given stream.
* It collects all the known writers for the given stream and includes only writers that are active (have reported
* their marks recently). If all active writers have reported marks greater than the previously emitted watermark,
* then new watermark is computed and emitted. If not, the window for considering writers as active is progressed.
* @param stream stream for which watermark should be computed.
* @return Returns a completableFuture which when completed will have completed another iteration of periodic watermark
* computation.
*/
public CompletableFuture<Void> watermark(Stream stream) {
String scope = stream.getScope();
String streamName = stream.getStreamName();
long requestId = requestIdGenerator.get();
String requestDescriptor = RequestTracker.buildRequestDescriptor("watermark", stream.getScope(), stream.getStreamName());
requestTracker.trackRequest(requestDescriptor, requestId);
OperationContext context = streamMetadataStore.createStreamContext(scope, streamName, requestId);
if (scope.equals(NameUtils.INTERNAL_SCOPE_NAME)) {
return CompletableFuture.completedFuture(null);
}
log.debug(requestId, "Periodic background processing for watermarking called for stream {}/{}", scope, streamName);
CompletableFuture<Map<String, WriterMark>> allWriterMarks = Futures.exceptionallyExpecting(streamMetadataStore.getAllWriterMarks(scope, streamName, context, executor), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException, Collections.emptyMap());
return allWriterMarks.thenCompose(writers -> {
WatermarkClient watermarkClient = watermarkClientCache.getUnchecked(stream);
try {
watermarkClient.reinitialize();
} catch (Exception e) {
log.warn(requestId, "Watermarking client for stream {} threw exception {} during reinitialize.", stream, Exceptions.unwrap(e).getClass());
if (Exceptions.unwrap(e) instanceof NoSuchSegmentException) {
log.info(requestId, "Invalidating the watermark client in cache for stream {}.", stream);
watermarkClientCache.invalidate(stream);
}
throw e;
}
return streamMetadataStore.getConfiguration(scope, streamName, context, executor).thenCompose(config -> filterWritersAndComputeWatermark(scope, streamName, context, watermarkClient, writers, config));
}).exceptionally(e -> {
log.warn(requestId, "Exception thrown while trying to perform periodic watermark computation. Logging and ignoring.", e);
return null;
});
}
use of io.pravega.client.segment.impl.NoSuchSegmentException in project pravega by pravega.
the class EventStreamReaderImpl method fetchEvent.
@Override
public Type fetchEvent(EventPointer pointer) throws NoSuchEventException {
Preconditions.checkNotNull(pointer);
// Create SegmentInputStream
@Cleanup EventSegmentReader inputStream = inputStreamFactory.createEventReaderForSegment(pointer.asImpl().getSegment(), pointer.asImpl().getEventLength());
inputStream.setOffset(pointer.asImpl().getEventStartOffset());
// Read event
try {
ByteBuffer buffer = inputStream.read();
return deserializer.deserialize(buffer);
} catch (EndOfSegmentException e) {
throw new NoSuchEventException(e.getMessage());
} catch (NoSuchSegmentException | SegmentTruncatedException e) {
throw new NoSuchEventException("Event no longer exists.");
}
}
use of io.pravega.client.segment.impl.NoSuchSegmentException in project pravega by pravega.
the class SegmentTransactionTest method testSegmentDoesNotExist.
@Test(timeout = 5000)
public void testSegmentDoesNotExist() {
UUID uuid = UUID.randomUUID();
SegmentOutputStream outputStream = Mockito.mock(SegmentOutputStream.class);
@SuppressWarnings("resource") SegmentTransactionImpl<String> txn = new SegmentTransactionImpl<>(uuid, outputStream, new JavaSerializer<String>());
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
PendingEvent event = (PendingEvent) invocation.getArgument(0);
event.getAckFuture().completeExceptionally(new NoSuchSegmentException("segment"));
return null;
}
}).when(outputStream).write(Mockito.any(PendingEvent.class));
AssertExtensions.assertThrows(TxnFailedException.class, () -> txn.writeEvent("hi"));
verify(outputStream).write(Mockito.any(PendingEvent.class));
AssertExtensions.assertThrows(TxnFailedException.class, () -> txn.flush());
Mockito.verifyNoMoreInteractions(outputStream);
}
Aggregations