Search in sources :

Example 1 with ServiceHaltException

use of io.pravega.segmentstore.server.ServiceHaltException in project pravega by pravega.

the class MemoryStateUpdater method addToReadIndex.

/**
 * Registers the given operation in the ReadIndex.
 *
 * @param operation The operation to register.
 * @throws CacheFullException If the operation could not be added to the {@link ReadIndex} due to the cache being
 * full and unable to evict anything to make room for more.
 * @throws ServiceHaltException If any unexpected exception occurred that prevented the operation from being
 * added to the {@link ReadIndex}. Unexpected exceptions are all exceptions other than those declared in this
 * method or that indicate we are shutting down or that the segment has been deleted.
 */
private void addToReadIndex(StorageOperation operation) throws ServiceHaltException, CacheFullException {
    try {
        if (operation instanceof StreamSegmentAppendOperation) {
            // Record a StreamSegmentAppendOperation. Just in case, we also support this type of operation, but we need to
            // log a warning indicating so. This means we do not optimize memory properly, and we end up storing data
            // in two different places.
            StreamSegmentAppendOperation appendOperation = (StreamSegmentAppendOperation) operation;
            this.readIndex.append(appendOperation.getStreamSegmentId(), appendOperation.getStreamSegmentOffset(), appendOperation.getData());
        } else if (operation instanceof MergeSegmentOperation) {
            // Record a MergeSegmentOperation. We call beginMerge here, and the StorageWriter will call completeMerge.
            MergeSegmentOperation mergeOperation = (MergeSegmentOperation) operation;
            this.readIndex.beginMerge(mergeOperation.getStreamSegmentId(), mergeOperation.getStreamSegmentOffset(), mergeOperation.getSourceSegmentId());
        } else {
            assert !(operation instanceof CachedStreamSegmentAppendOperation) : "attempted to add a CachedStreamSegmentAppendOperation to the ReadIndex";
        }
    } catch (ObjectClosedException | StreamSegmentNotExistsException ex) {
        // The Segment is in the process of being deleted. We usually end up in here because a concurrent delete
        // request has updated the metadata while we were executing.
        log.warn("Not adding operation '{}' to ReadIndex because it refers to a deleted StreamSegment.", operation);
    } catch (CacheFullException ex) {
        // Record the operation that we couldn't add and re-throw the exception as we cannot do anything about it here.
        log.warn("Not adding operation '{}' to ReadIndex because the Cache is full.", operation);
        throw ex;
    } catch (Exception ex) {
        throw new ServiceHaltException(String.format("Unable to add operation '%s' to ReadIndex.", operation), ex);
    }
}
Also used : ObjectClosedException(io.pravega.common.ObjectClosedException) ServiceHaltException(io.pravega.segmentstore.server.ServiceHaltException) CacheFullException(io.pravega.segmentstore.storage.cache.CacheFullException) CachedStreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.CachedStreamSegmentAppendOperation) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) MergeSegmentOperation(io.pravega.segmentstore.server.logs.operations.MergeSegmentOperation) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) ObjectClosedException(io.pravega.common.ObjectClosedException) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) ServiceHaltException(io.pravega.segmentstore.server.ServiceHaltException) CacheFullException(io.pravega.segmentstore.storage.cache.CacheFullException) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) CachedStreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.CachedStreamSegmentAppendOperation)

Example 2 with ServiceHaltException

use of io.pravega.segmentstore.server.ServiceHaltException in project pravega by pravega.

the class DurableLog method performRecovery.

@SneakyThrows(Exception.class)
private boolean performRecovery() {
    // Make sure we are in the correct state. We do not want to do recovery while we are in full swing.
    Preconditions.checkState(state() == State.STARTING || (state() == State.RUNNING && isOffline()), "Invalid State for recovery.");
    Timer timer = new Timer();
    try {
        // Initialize the DurableDataLog, which will acquire its lock and ensure we are the only active users of it.
        this.durableDataLog.initialize(DEFAULT_TIMEOUT);
        // Initiate the recovery.
        RecoveryProcessor p = new RecoveryProcessor(this.metadata, this.durableDataLog, this.memoryStateUpdater);
        int recoveredItemCount = p.performRecovery();
        this.operationProcessor.getMetrics().operationsCompleted(recoveredItemCount, timer.getElapsed());
        this.operationProcessor.getMetrics().reportOperationLogSize(recoveredItemCount, this.getId());
        // Verify that the Recovery Processor has left the metadata in a non-recovery mode.
        Preconditions.checkState(!this.metadata.isRecoveryMode(), "Recovery completed but Metadata is still in Recovery Mode.");
        return recoveredItemCount > 0;
    } catch (Exception ex) {
        log.error("{} Recovery FAILED.", this.traceObjectId, ex);
        Throwable cause = Exceptions.unwrap(ex);
        if (cause instanceof ServiceHaltException || cause instanceof DataLogCorruptedException) {
            // debugging information before someone can manually fix the problem).
            try {
                this.durableDataLog.disable();
                log.info("{} Log disabled due to {} during recovery.", this.traceObjectId, cause.getClass().getSimpleName());
            } catch (Exception disableEx) {
                log.warn("{}: Unable to disable log after DataCorruptionException during recovery.", this.traceObjectId, disableEx);
                ex.addSuppressed(disableEx);
            }
        }
        throw ex;
    }
}
Also used : DataLogCorruptedException(io.pravega.segmentstore.storage.DataLogCorruptedException) TimeoutTimer(io.pravega.common.TimeoutTimer) Timer(io.pravega.common.Timer) ServiceHaltException(io.pravega.segmentstore.server.ServiceHaltException) ObjectClosedException(io.pravega.common.ObjectClosedException) IllegalContainerStateException(io.pravega.segmentstore.server.IllegalContainerStateException) StreamingException(io.pravega.segmentstore.contracts.StreamingException) ServiceHaltException(io.pravega.segmentstore.server.ServiceHaltException) DataLogDisabledException(io.pravega.segmentstore.storage.DataLogDisabledException) ContainerOfflineException(io.pravega.segmentstore.server.ContainerOfflineException) CompletionException(java.util.concurrent.CompletionException) DataLogCorruptedException(io.pravega.segmentstore.storage.DataLogCorruptedException) SneakyThrows(lombok.SneakyThrows)

Aggregations

ObjectClosedException (io.pravega.common.ObjectClosedException)2 ServiceHaltException (io.pravega.segmentstore.server.ServiceHaltException)2 TimeoutTimer (io.pravega.common.TimeoutTimer)1 Timer (io.pravega.common.Timer)1 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)1 StreamingException (io.pravega.segmentstore.contracts.StreamingException)1 ContainerOfflineException (io.pravega.segmentstore.server.ContainerOfflineException)1 DataCorruptionException (io.pravega.segmentstore.server.DataCorruptionException)1 IllegalContainerStateException (io.pravega.segmentstore.server.IllegalContainerStateException)1 CachedStreamSegmentAppendOperation (io.pravega.segmentstore.server.logs.operations.CachedStreamSegmentAppendOperation)1 MergeSegmentOperation (io.pravega.segmentstore.server.logs.operations.MergeSegmentOperation)1 StreamSegmentAppendOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation)1 DataLogCorruptedException (io.pravega.segmentstore.storage.DataLogCorruptedException)1 DataLogDisabledException (io.pravega.segmentstore.storage.DataLogDisabledException)1 CacheFullException (io.pravega.segmentstore.storage.cache.CacheFullException)1 CompletionException (java.util.concurrent.CompletionException)1 SneakyThrows (lombok.SneakyThrows)1