use of lombok.SneakyThrows in project pravega by pravega.
the class ReaderGroupImpl method completeCheckpoint.
@SneakyThrows(CheckpointFailedException.class)
private Checkpoint completeCheckpoint(String checkpointName, StateSynchronizer<ReaderGroupState> synchronizer) {
ReaderGroupState state = synchronizer.getState();
Map<Segment, Long> map = state.getPositionsForCompletedCheckpoint(checkpointName);
synchronizer.updateStateUnconditionally(new ClearCheckpoints(checkpointName));
if (map == null) {
throw new CheckpointFailedException("Checkpoint was cleared before results could be read.");
}
return new CheckpointImpl(checkpointName, map);
}
use of lombok.SneakyThrows in project pravega by pravega.
the class DurableLogTests method processOperations.
@SneakyThrows
private List<OperationWithCompletion> processOperations(Collection<Operation> operations, DurableLog durableLog, int waitEvery) {
List<OperationWithCompletion> completionFutures = new ArrayList<>();
int index = 0;
for (Operation o : operations) {
index++;
CompletableFuture<Void> completionFuture;
try {
completionFuture = durableLog.add(o, TIMEOUT);
} catch (Exception ex) {
completionFuture = Futures.failedFuture(ex);
}
completionFutures.add(new OperationWithCompletion(o, completionFuture));
if (index % waitEvery == 0) {
completionFuture.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
}
}
return completionFutures;
}
use of lombok.SneakyThrows in project pravega by pravega.
the class PravegaRequestProcessor method copyData.
/**
* Copy all of the contents provided into a byteBuffer and return it.
*/
@SneakyThrows(IOException.class)
private ByteBuffer copyData(List<ReadResultEntryContents> contents) {
int totalSize = contents.stream().mapToInt(ReadResultEntryContents::getLength).sum();
ByteBuffer data = ByteBuffer.allocate(totalSize);
int bytesCopied = 0;
for (ReadResultEntryContents content : contents) {
int copied = StreamHelpers.readAll(content.getData(), data.array(), bytesCopied, totalSize - bytesCopied);
Preconditions.checkState(copied == content.getLength(), "Read fewer bytes than available.");
bytesCopied += copied;
}
return data;
}
use of lombok.SneakyThrows 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.");
this.operationProcessor.getMetrics().operationLogInit();
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(RECOVERY_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());
// 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);
if (Exceptions.unwrap(ex) instanceof DataCorruptionException) {
// someone can manually fix the problem).
try {
this.durableDataLog.disable();
log.info("{} Log disabled due to DataCorruptionException during recovery.", this.traceObjectId);
} catch (Exception disableEx) {
log.warn("{}: Unable to disable log after DataCorruptionException during recovery.", this.traceObjectId, disableEx);
ex.addSuppressed(disableEx);
}
}
throw ex;
}
}
use of lombok.SneakyThrows in project pravega by pravega.
the class ZKStreamMetadataStore method registerBucketOwnershipListener.
@Override
@SneakyThrows
public void registerBucketOwnershipListener(BucketOwnershipListener listener) {
Preconditions.checkNotNull(listener);
PathChildrenCacheListener bucketListener = (client, event) -> {
switch(event.getType()) {
case CHILD_ADDED:
// no action required
break;
case CHILD_REMOVED:
int bucketId = Integer.parseInt(ZKPaths.getNodeFromPath(event.getData().getPath()));
listener.notify(new BucketNotification(bucketId, BucketNotification.NotificationType.BucketAvailable));
break;
case CONNECTION_LOST:
listener.notify(new BucketNotification(Integer.MIN_VALUE, BucketNotification.NotificationType.ConnectivityError));
break;
default:
log.warn("Received unknown event {}", event.getType());
}
};
bucketOwnershipCacheRef.compareAndSet(null, new PathChildrenCache(storeHelper.getClient(), ZKStoreHelper.BUCKET_OWNERSHIP_PATH, true));
bucketOwnershipCacheRef.get().getListenable().addListener(bucketListener);
bucketOwnershipCacheRef.get().start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
log.info("bucket ownership listener registered");
}
Aggregations