Search in sources :

Example 11 with StreamSegmentExistsException

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

the class RollingStorage method createChunk.

private void createChunk(RollingSegmentHandle handle) throws StreamSegmentException {
    // Create new active SegmentChunk, only after which serialize the handle update and update the handle.
    // We ignore if the SegmentChunk exists and is empty - that's most likely due to a previous failed attempt.
    long segmentLength = handle.length();
    SegmentChunk newSegmentChunk = SegmentChunk.forSegment(handle.getSegmentName(), segmentLength);
    try {
        this.baseStorage.create(newSegmentChunk.getName());
    } catch (StreamSegmentExistsException ex) {
        checkIfEmptyAndNotSealed(ex, newSegmentChunk.getName());
    }
    serializeNewChunk(handle, newSegmentChunk);
    val activeHandle = this.baseStorage.openWrite(newSegmentChunk.getName());
    handle.addChunk(newSegmentChunk, activeHandle);
    log.debug("Created new SegmentChunk '{}' for '{}'.", newSegmentChunk, handle);
}
Also used : lombok.val(lombok.val) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException)

Example 12 with StreamSegmentExistsException

use of io.pravega.segmentstore.contracts.StreamSegmentExistsException 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

StreamSegmentExistsException (io.pravega.segmentstore.contracts.StreamSegmentExistsException)12 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)5 lombok.val (lombok.val)5 CompletionException (java.util.concurrent.CompletionException)4 Test (org.junit.Test)4 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)3 SegmentHandle (io.pravega.segmentstore.storage.SegmentHandle)3 Storage (io.pravega.segmentstore.storage.Storage)3 InMemoryStorage (io.pravega.segmentstore.storage.mocks.InMemoryStorage)3 ArrayList (java.util.ArrayList)3 Cleanup (lombok.Cleanup)3 Service (com.google.common.util.concurrent.Service)2 Exceptions (io.pravega.common.Exceptions)2 MathHelpers (io.pravega.common.MathHelpers)2 Futures (io.pravega.common.concurrent.Futures)2 AsyncMap (io.pravega.common.util.AsyncMap)2 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)2 AttributeUpdateType (io.pravega.segmentstore.contracts.AttributeUpdateType)2 Attributes (io.pravega.segmentstore.contracts.Attributes)2 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)2