Search in sources :

Example 6 with ContainerNotFoundException

use of io.pravega.segmentstore.contracts.ContainerNotFoundException in project pravega by pravega.

the class StreamSegmentContainerRegistryTests method testContainerFailureOnStartup.

/**
 * Tests the ability to detect a container failure and unregister the container in case the container fails on startup.
 */
@Test
public void testContainerFailureOnStartup() throws Exception {
    final int containerId = 123;
    // We insert a ReusableLatch that will allow us to manually delay the TestContainer's shutdown/closing process
    // so that we have enough time to verify that calling getContainer() on a currently shutting down container will
    // throw the appropriate exception.
    ReusableLatch closeReleaseSignal = new ReusableLatch();
    TestContainerFactory factory = new TestContainerFactory(new IntentionalException(), closeReleaseSignal);
    @Cleanup StreamSegmentContainerRegistry registry = new StreamSegmentContainerRegistry(factory, executorService());
    AssertExtensions.assertThrows("Unexpected exception thrown upon failed container startup.", registry.startContainer(containerId, TIMEOUT)::join, ex -> ex instanceof IntentionalException || (ex instanceof IllegalStateException && ex.getCause() instanceof IntentionalException));
    AssertExtensions.assertThrows("Container is registered even if it failed to start (and is currently shut down).", () -> registry.getContainer(containerId), ex -> ex instanceof ContainerNotFoundException);
    // Unblock container closing, which will, in turn, unblock its de-registration.
    closeReleaseSignal.release();
    AssertExtensions.assertThrows("Container is registered even if it failed to start (and has been unregistered).", () -> registry.getContainer(containerId), ex -> ex instanceof ContainerNotFoundException);
}
Also used : ReusableLatch(io.pravega.common.util.ReusableLatch) Cleanup(lombok.Cleanup) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) IntentionalException(io.pravega.test.common.IntentionalException) Test(org.junit.Test)

Example 7 with ContainerNotFoundException

use of io.pravega.segmentstore.contracts.ContainerNotFoundException in project pravega by pravega.

the class PravegaRequestProcessor method handleException.

private Void handleException(long requestId, String segment, String operation, Throwable u) {
    if (u == null) {
        IllegalStateException exception = new IllegalStateException("No exception to handle.");
        log.error("Error (Segment = '{}', Operation = '{}')", segment, operation, exception);
        throw exception;
    }
    u = Exceptions.unwrap(u);
    if (u instanceof StreamSegmentExistsException) {
        log.info("Segment '{}' already exists and cannot perform operation '{}'.", segment, operation);
        connection.send(new SegmentAlreadyExists(requestId, segment));
    } else if (u instanceof StreamSegmentNotExistsException) {
        log.warn("Segment '{}' does not exist and cannot perform operation '{}'.", segment, operation);
        connection.send(new NoSuchSegment(requestId, segment));
    } else if (u instanceof StreamSegmentSealedException) {
        log.info("Segment '{}' is sealed and cannot perform operation '{}'.", segment, operation);
        connection.send(new SegmentIsSealed(requestId, segment));
    } else if (u instanceof ContainerNotFoundException) {
        int containerId = ((ContainerNotFoundException) u).getContainerId();
        log.warn("Wrong host. Segment = '{}' (Container {}) is not owned. Operation = '{}').", segment, containerId, operation);
        connection.send(new WrongHost(requestId, segment, ""));
    } else if (u instanceof CancellationException) {
        log.info("Closing connection {} while performing {} due to {}.", connection, operation, u.getMessage());
        connection.close();
    } else if (u instanceof AuthenticationException) {
        log.warn("Authentication error during '{}'.", operation);
        connection.send(new WireCommands.AuthTokenCheckFailed(requestId));
        connection.close();
    } else if (u instanceof UnsupportedOperationException) {
        log.warn("Unsupported Operation '{}'.", operation, u);
        connection.send(new OperationUnsupported(requestId, operation));
    } else if (u instanceof BadOffsetException) {
        BadOffsetException badOffset = (BadOffsetException) u;
        connection.send(new SegmentIsTruncated(requestId, segment, badOffset.getExpectedOffset()));
    } else {
        log.error("Error (Segment = '{}', Operation = '{}')", segment, operation, u);
        // Closing connection should reinitialize things, and hopefully fix the problem
        connection.close();
        throw new IllegalStateException("Unknown exception.", u);
    }
    return null;
}
Also used : OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) AuthenticationException(io.pravega.common.auth.AuthenticationException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) SegmentAlreadyExists(io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) CancellationException(java.util.concurrent.CancellationException) SegmentIsTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentIsTruncated) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException)

Aggregations

ContainerNotFoundException (io.pravega.segmentstore.contracts.ContainerNotFoundException)7 Cleanup (lombok.Cleanup)4 Test (org.junit.Test)4 ContainerHandle (io.pravega.segmentstore.server.ContainerHandle)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 AuthenticationException (io.pravega.common.auth.AuthenticationException)2 StreamSegmentExistsException (io.pravega.segmentstore.contracts.StreamSegmentExistsException)2 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)2 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)2 SegmentContainer (io.pravega.segmentstore.server.SegmentContainer)2 NoSuchSegment (io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment)2 OperationUnsupported (io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported)2 SegmentAlreadyExists (io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists)2 SegmentIsSealed (io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed)2 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)2 IntentionalException (io.pravega.test.common.IntentionalException)2 ReusableLatch (io.pravega.common.util.ReusableLatch)1 BadAttributeUpdateException (io.pravega.segmentstore.contracts.BadAttributeUpdateException)1 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)1 TooManyAttributesException (io.pravega.segmentstore.contracts.TooManyAttributesException)1