@Override protected void doStart() { log.info("{}: Starting.", this.traceObjectId); this.delayedStartRetry .runAsync(() -> tryStartOnce() .whenComplete((v, ex) -> { if (ex == null) { // We are done. log.info("{}: Online.", this.traceObjectId); notifyDelayedStartComplete(null); } else { if (Exceptions.unwrap(ex) instanceof DataLogDisabledException) { // Place the DurableLog in a Started State, but keep trying to restart. notifyStartComplete(null); } throw new CompletionException(ex); } }), this.executor) .exceptionally(this::notifyDelayedStartComplete); }
@Override public CompletableFuture<SegmentRead> read(long offset, int length) { Exceptions.checkNotClosed(closed.get(), this); WireCommands.ReadSegment request = new WireCommands.ReadSegment(segmentId.getScopedName(), offset, length, this.delegationToken); return backoffSchedule.retryWhen(t -> { Throwable ex = Exceptions.unwrap(t); if (closed.get()) { log.debug("Exception while reading from Segment : {}", segmentId, ex); } else { log.warn("Exception while reading from Segment : {}", segmentId, ex); } return ex instanceof Exception && !(ex instanceof ConnectionClosedException) && !(ex instanceof SegmentTruncatedException); }).runAsync(() -> { return getConnection() .whenComplete((connection, ex) -> { if (ex != null) { log.warn("Exception while establishing connection with Pravega " + "node", ex); closeConnection(new ConnectionFailedException(ex)); } }).thenCompose(c -> sendRequestOverConnection(request, c)); }, connectionFactory.getInternalExecutor()); }
/** * Executes the given request on the given FencingTextContext.. We retry all expected exceptions, and when we do, we * make sure to execute them on the current (active) Segment Store instance (since the previous one may be unusable). */ private CompletableFuture<Void> executeWithFencing(StoreRequest request, int index, FencingTestContext context) { log.debug("Initiating Operation #{} on iteration {}.", index, context.getIteration()); AtomicReference<StreamSegmentStore> requestStore = new AtomicReference<>(context.getActiveStore()); return Retry.withExpBackoff(50, 2, 10, TIMEOUT.toMillis() / 10) .retryWhen(ex -> { requestStore.getAndSet(context.getActiveStore()); ex = Exceptions.unwrap(ex); log.info("Operation #{} (Iteration = {}) failed due to {}.", index, context.getIteration(), ex.toString()); return isExpectedFencingException(ex); }) .runAsync(() -> request.apply(requestStore.get()), executorService()); }
@Override public CompletableFuture<Void> processEvent(TestBase event) { receivedForProcessing.add(event); CompletableFuture<Void> result = new CompletableFuture<>(); Retry.withExpBackoff(100, 1, 5, 100) .retryWhen(RetryableException::isRetryable) .runAsync(() -> event.process(null), executor) .whenCompleteAsync((r, e) -> { if (e != null) { Throwable cause = Exceptions.unwrap(e); if (cause instanceof OperationDisallowedException) { Retry.indefinitelyWithExpBackoff("Error writing event back into requeststream") .runAsync(() -> writer.write(event), executor) .thenAccept(v -> result.completeExceptionally(cause)); } else { result.completeExceptionally(cause); } } else { result.complete(r); } }, executor); return result; } }
public static <U> CompletableFuture<U> withRetries(Supplier<CompletableFuture<U>> futureSupplier, ScheduledExecutorService executor) { return RETRY.runAsync(futureSupplier, executor); }
static <U> CompletableFuture<U> withRetries(Supplier<CompletableFuture<U>> futureSupplier, ScheduledExecutorService executor) { return RETRY.runAsync(futureSupplier, executor); } }
private CompletableFuture<Map<UUID, Long>> getAttributesForSegment(long segmentId, Collection<UUID> attributeIds, boolean cache, TimeoutTimer timer) { SegmentMetadata metadata = this.metadata.getStreamSegmentMetadata(segmentId); if (cache) { return CACHE_ATTRIBUTES_RETRY.runAsync(() -> getAndCacheAttributes(metadata, attributeIds, cache, timer), StreamSegmentContainer.this.executor); } else { return getAndCacheAttributes(metadata, attributeIds, cache, timer); } }
public static <U> CompletableFuture<U> withRetriesAsync(Supplier<CompletableFuture<U>> futureSupplier, Predicate<Throwable> predicate, int numOfTries, ScheduledExecutorService executor) { return Retry .withExpBackoff(100, 2, numOfTries, 10000) .retryWhen(predicate) .runAsync(futureSupplier, executor); }