Search in sources :

Example 6 with RetriesExhaustedException

use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.

the class BookKeeperLogTests method testAppendPermanentFailures.

/**
 * Tests the ability to retry writes when Bookies fail.
 */
@Test
public void testAppendPermanentFailures() throws Exception {
    try (DurableDataLog log = createDurableDataLog()) {
        log.initialize(TIMEOUT);
        List<CompletableFuture<LogAddress>> appendFutures = new ArrayList<>();
        try {
            // Suspend a bookie (this will trigger write errors).
            stopFirstBookie();
            // Issue appends in parallel.
            int writeCount = getWriteCount();
            for (int i = 0; i < writeCount; i++) {
                appendFutures.add(log.append(new ByteArraySegment(getWriteData()), TIMEOUT));
            }
            // Verify that all writes failed or got cancelled.
            AtomicBoolean cancellationEncountered = new AtomicBoolean(false);
            for (val f : appendFutures) {
                AssertExtensions.assertThrows("Write did not fail correctly.", () -> f.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS), ex -> {
                    cancellationEncountered.set(cancellationEncountered.get() || ex instanceof CancellationException);
                    if (cancellationEncountered.get()) {
                        return ex instanceof CancellationException;
                    } else {
                        return ex instanceof RetriesExhaustedException || ex instanceof DurableDataLogException;
                    }
                });
            }
        } finally {
            // Don't forget to resume the bookie, but only AFTER we are done testing.
            restartFirstBookie();
        }
    }
}
Also used : DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) lombok.val(lombok.val) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ByteArraySegment(io.pravega.common.util.ByteArraySegment) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) CancellationException(java.util.concurrent.CancellationException) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with RetriesExhaustedException

use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.

the class RetryHelperTest method testWithRetriesAsync.

@Test(timeout = 10000)
public void testWithRetriesAsync() {
    try {
        RetryHelper.withRetriesAsync(() -> CompletableFuture.runAsync(() -> {
            throw new TestException();
        }), RetryHelper.RETRYABLE_PREDICATE, 2, executor);
    } catch (Exception e) {
        assertTrue(e instanceof RetriesExhaustedException);
        Throwable ex = Exceptions.unwrap(e.getCause());
        assertTrue(ex instanceof TestException);
    }
    AtomicInteger count = new AtomicInteger(0);
    assertTrue(Futures.getAndHandleExceptions(RetryHelper.withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
        if (count.incrementAndGet() < 2) {
            throw new TestException();
        }
        return count.get();
    }), RetryHelper.RETRYABLE_PREDICATE, 2, executor), RuntimeException::new) == 2);
    assertTrue(Futures.getAndHandleExceptions(RetryHelper.withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
        if (count.incrementAndGet() < 4) {
            throw new RuntimeException();
        }
        return count.get();
    }), RetryHelper.UNCONDITIONAL_PREDICATE, 2, executor), RuntimeException::new) == 4);
}
Also used : RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) RetryableException(io.pravega.controller.retryable.RetryableException) Test(org.junit.Test)

Example 8 with RetriesExhaustedException

use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.

the class RetryHelperTest method testWithRetries.

@Test(timeout = 10000)
public void testWithRetries() {
    try {
        RetryHelper.withRetries(() -> {
            throw new TestException();
        }, RetryHelper.RETRYABLE_PREDICATE, 2);
    } catch (Exception e) {
        assertTrue(e instanceof RetriesExhaustedException);
        Throwable ex = Exceptions.unwrap(e.getCause());
        assertTrue(ex instanceof TestException);
    }
    AtomicInteger count = new AtomicInteger(0);
    assertTrue(RetryHelper.withRetries(() -> {
        if (count.incrementAndGet() < 2) {
            throw new TestException();
        }
        return count.get();
    }, RetryHelper.RETRYABLE_PREDICATE, 2) == 2);
    assertTrue(RetryHelper.withRetries(() -> {
        if (count.incrementAndGet() < 4) {
            throw new RuntimeException();
        }
        return count.get();
    }, RetryHelper.UNCONDITIONAL_PREDICATE, 2) == 4);
}
Also used : RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) RetryableException(io.pravega.controller.retryable.RetryableException) Test(org.junit.Test)

Example 9 with RetriesExhaustedException

use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.

the class BookKeeperDisableCommand method execute.

@Override
public void execute() throws Exception {
    ensureArgCount(1);
    int logId = getIntArg(0);
    @Cleanup val context = createContext();
    @Cleanup val log = context.logFactory.createDebugLogWrapper(logId);
    // Display a summary of the BookKeeperLog.
    val m = log.fetchMetadata();
    outputLogSummary(logId, m);
    if (m == null) {
        // Nothing else to do.
        return;
    } else if (!m.isEnabled()) {
        output("BookKeeperLog '%s' is already disabled.", logId);
        return;
    }
    output("BookKeeperLog '%s' is about to be DISABLED.", logId);
    output("\tIts SegmentContainer will shut down and it will not be able to restart until re-enabled.");
    output("\tNo request on this SegmentContainer can be processed until that time (OUTAGE ALERT).");
    if (!confirmContinue()) {
        output("Not disabling anything at this time.");
        return;
    }
    try {
        AtomicInteger count = new AtomicInteger(0);
        // We may be competing with a rather active Log which updates its metadata quite frequently, so try a few
        // times to acquire the ownership.
        DISABLE_RETRY.run(() -> {
            output("Acquiring ownership (attempt %d/%d) ...", count.incrementAndGet(), MAX_RETRIES);
            log.disable();
            output("BookKeeperLog '%s' has been disabled.", logId);
            return null;
        });
    } catch (Exception ex) {
        Throwable cause = ex;
        if (cause instanceof RetriesExhaustedException && cause.getCause() != null) {
            cause = cause.getCause();
        }
        output("Disable failed: %s.", cause.getMessage());
    }
    output("Current metadata:");
    val m2 = log.fetchMetadata();
    outputLogSummary(logId, m2);
}
Also used : lombok.val(lombok.val) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Cleanup(lombok.Cleanup) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException)

Aggregations

RetriesExhaustedException (io.pravega.common.util.RetriesExhaustedException)9 Test (org.junit.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 lombok.val (lombok.val)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 ByteArraySegment (io.pravega.common.util.ByteArraySegment)2 RetryableException (io.pravega.controller.retryable.RetryableException)2 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)2 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)2 CancellationException (java.util.concurrent.CancellationException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Server (io.grpc.Server)1 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)1 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 Exceptions (io.pravega.common.Exceptions)1 ObjectClosedException (io.pravega.common.ObjectClosedException)1 Retry (io.pravega.common.util.Retry)1 OperationContext (io.pravega.controller.store.stream.OperationContext)1 DataLogNotAvailableException (io.pravega.segmentstore.storage.DataLogNotAvailableException)1 DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)1