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);
}
}
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;
}
}
Aggregations