use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class ControllerImpl method sealStream.
@Override
public CompletableFuture<Boolean> sealStream(final String scope, final String streamName) {
Exceptions.checkNotClosed(closed.get(), this);
Exceptions.checkNotNullOrEmpty(scope, "scope");
Exceptions.checkNotNullOrEmpty(streamName, "streamName");
long traceId = LoggerHelpers.traceEnter(log, "sealStream", scope, streamName);
final CompletableFuture<UpdateStreamStatus> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<UpdateStreamStatus> callback = new RPCAsyncCallback<>();
client.sealStream(ModelHelper.createStreamInfo(scope, streamName), callback);
return callback.getFuture();
}, this.executor);
return result.thenApply(x -> {
switch(x.getStatus()) {
case FAILURE:
log.warn("Failed to seal stream: {}", streamName);
throw new ControllerFailureException("Failed to seal stream: " + streamName);
case SCOPE_NOT_FOUND:
log.warn("Scope not found: {}", scope);
throw new InvalidStreamException("Scope does not exist: " + scope);
case STREAM_NOT_FOUND:
log.warn("Stream does not exist: {}", streamName);
throw new InvalidStreamException("Stream does not exist: " + streamName);
case SUCCESS:
log.info("Successfully sealed stream: {}", streamName);
return true;
case UNRECOGNIZED:
default:
throw new ControllerFailureException("Unknown return status scealing stream " + streamName + " " + x.getStatus());
}
}).whenComplete((x, e) -> {
if (e != null) {
log.warn("sealStream failed: ", e);
}
LoggerHelpers.traceLeave(log, "sealStream", traceId);
});
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class ControllerImpl method abortTransaction.
@Override
public CompletableFuture<Void> abortTransaction(final Stream stream, final UUID txId) {
Exceptions.checkNotClosed(closed.get(), this);
Preconditions.checkNotNull(stream, "stream");
Preconditions.checkNotNull(txId, "txId");
long traceId = LoggerHelpers.traceEnter(log, "abortTransaction", stream, txId);
final long requestId = requestIdGenerator.get();
log.info(requestId, "Abort transaction {} invoked on stream {}", txId, stream);
final CompletableFuture<TxnStatus> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<TxnStatus> callback = new RPCAsyncCallback<>(traceId, "abortTransaction", stream, txId);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, ABORT_TRANSACTION, stream.getScope(), stream.getStreamName(), txId.toString()).abortTransaction(TxnRequest.newBuilder().setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())).setTxnId(ModelHelper.decode(txId)).build(), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(txnStatus -> {
LoggerHelpers.traceLeave(log, "abortTransaction", traceId, stream, txId);
if (txnStatus.getStatus().equals(TxnStatus.Status.STREAM_NOT_FOUND)) {
log.warn(requestId, "Stream {} not found while trying to abort transaction {}", stream, txId);
throw new InvalidStreamException("Stream no longer exists: " + stream);
}
if (txnStatus.getStatus().equals(TxnStatus.Status.TRANSACTION_NOT_FOUND)) {
log.warn(requestId, "transaction {} not found on stream {}", txId, stream);
throw Exceptions.sneakyThrow(new TxnFailedException("Transaction was already either committed or aborted"));
}
if (txnStatus.getStatus().equals(TxnStatus.Status.SUCCESS)) {
return null;
}
log.warn(requestId, "Unable to abort transaction {} on stream {}, abort status is {} ", txId, stream, txnStatus.getStatus());
throw new RuntimeException("Error aborting transaction: " + txnStatus.getStatus());
}, this.executor);
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class DeleteScopeTask method deleteScopeContent.
public CompletableFuture<Void> deleteScopeContent(String scopeName, OperationContext context, long requestId) {
Map<String, String> readerGroupMap = new HashMap<>();
Iterator<Stream> iterator = listStreams(scopeName, context).asIterator();
// Seal and delete streams and add entry to RGList
while (iterator.hasNext()) {
Stream stream = iterator.next();
Timer timer = new Timer();
if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
readerGroupMap.put(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()), stream.getStreamName());
}
log.debug("Processing seal and delete stream for Stream {}", stream);
Futures.getThrowingException(Futures.exceptionallyExpecting(streamMetadataTasks.sealStream(scopeName, stream.getStreamName(), requestId), e -> {
Throwable unwrap = Exceptions.unwrap(e);
// ignore failures if the stream doesn't exist or we are unable to seal it.
return unwrap instanceof InvalidStreamException || unwrap instanceof ControllerFailureException;
}, Controller.UpdateStreamStatus.Status.STREAM_NOT_FOUND).thenCompose(sealed -> {
ControllerService.reportSealStreamMetrics(scopeName, stream.getStreamName(), sealed, timer.getElapsed());
return CompletableFuture.completedFuture(null);
}).thenCompose(x -> streamMetadataTasks.deleteStream(stream.getScope(), stream.getStreamName(), requestId).thenCompose(status -> {
ControllerService.reportDeleteStreamMetrics(scopeName, stream.getStreamName(), status, timer.getElapsed());
return CompletableFuture.completedFuture(null);
})));
}
// Delete ReaderGroups
for (Map.Entry<String, String> rgMapEntry : readerGroupMap.entrySet()) {
log.debug("Processing delete ReaderGroup for {}", rgMapEntry.getKey());
Timer timer = new Timer();
Futures.getThrowingException(streamMetadataTasks.getReaderGroupConfig(scopeName, rgMapEntry.getKey(), requestId).thenCompose(conf -> streamMetadataTasks.deleteReaderGroup(scopeName, rgMapEntry.getKey(), conf.getConfig().getReaderGroupId(), requestId).thenCompose(status -> {
ControllerService.reportDeleteReaderGroupMetrics(scopeName, rgMapEntry.getValue(), status, timer.getElapsed());
return CompletableFuture.completedFuture(null);
})));
}
// Delete KVTs
Iterator<KeyValueTableInfo> kvtIterator = listKVTs(scopeName, requestId, context).asIterator();
while (kvtIterator.hasNext()) {
String kvt = kvtIterator.next().getKeyValueTableName();
Timer timer = new Timer();
log.debug("Processing delete kvt for {}", kvt);
Futures.getThrowingException(kvtMetadataTasks.deleteKeyValueTable(scopeName, kvt, context.getRequestId()).thenCompose(status -> {
ControllerService.reportDeleteKVTableMetrics(scopeName, kvt, status, timer.getElapsed());
return CompletableFuture.completedFuture(null);
}));
}
return streamMetadataStore.deleteScopeRecursive(scopeName, context, executor).thenApply(status -> {
log.debug("Recursive Delete Scope returned with a status {}", status);
return null;
});
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class ReaderGroupManagerImplTest method testMissingGetReaderGroup.
@Test(expected = ReaderGroupNotFoundException.class)
public void testMissingGetReaderGroup() {
when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenThrow(new InvalidStreamException("invalid RG stream"));
readerGroupManager.getReaderGroup(GROUP_NAME);
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class ReaderGroupManagerImpl method deleteReaderGroup.
@Override
public void deleteReaderGroup(String groupName) {
UUID readerGroupId = null;
ReaderGroupConfig syncConfig = null;
try {
@Cleanup StateSynchronizer<ReaderGroupState> synchronizer = clientFactory.createStateSynchronizer(NameUtils.getStreamForReaderGroup(groupName), new ReaderGroupStateUpdatesSerializer(), new ReaderGroupStateInitSerializer(), SynchronizerConfig.builder().build());
synchronizer.fetchUpdates();
syncConfig = synchronizer.getState().getConfig();
readerGroupId = syncConfig.getReaderGroupId();
if (ReaderGroupConfig.DEFAULT_UUID.equals(syncConfig.getReaderGroupId()) && ReaderGroupConfig.DEFAULT_GENERATION == syncConfig.getGeneration()) {
// migrate RG case
try {
controller.getReaderGroupConfig(scope, groupName).thenCompose(conf -> controller.deleteReaderGroup(scope, groupName, conf.getReaderGroupId())).join();
} catch (ReaderGroupNotFoundException ex) {
controller.sealStream(scope, getStreamForReaderGroup(groupName)).thenCompose(b -> controller.deleteStream(scope, getStreamForReaderGroup(groupName))).exceptionally(e -> {
log.warn("Failed to delete ReaderGroup Stream {}", getStreamForReaderGroup(groupName), e);
throw Exceptions.sneakyThrow(e);
}).join();
}
return;
}
} catch (InvalidStreamException ex) {
log.warn("State-Synchronizer Stream for ReaderGroup {} was not found.", NameUtils.getScopedReaderGroupName(scope, groupName));
// if the State Synchronizer Stream was deleted, but the RG still exists, get Id from Controller
readerGroupId = getAndHandleExceptions(controller.getReaderGroupConfig(scope, groupName), RuntimeException::new).getReaderGroupId();
}
// normal delete
getAndHandleExceptions(controller.deleteReaderGroup(scope, groupName, readerGroupId), RuntimeException::new);
}
Aggregations