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");
final long requestId = requestIdGenerator.get();
long traceId = LoggerHelpers.traceEnter(log, "sealStream", scope, streamName, requestId);
final CompletableFuture<UpdateStreamStatus> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<UpdateStreamStatus> callback = new RPCAsyncCallback<>(requestId, "sealStream", scope, streamName);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, SEAL_STREAM, scope, streamName).sealStream(ModelHelper.createStreamInfo(scope, streamName), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(x -> {
switch(x.getStatus()) {
case FAILURE:
log.warn(requestId, "Failed to seal stream: {}", streamName);
throw new ControllerFailureException("Failed to seal stream: " + streamName);
case SCOPE_NOT_FOUND:
log.warn(requestId, "Scope not found: {}", scope);
throw new InvalidStreamException("Scope does not exist: " + scope);
case STREAM_NOT_FOUND:
log.warn(requestId, "Stream does not exist: {}", streamName);
throw new InvalidStreamException("Stream does not exist: " + streamName);
case SUCCESS:
log.info(requestId, "Successfully sealed stream: {}", streamName);
return true;
case UNRECOGNIZED:
default:
throw new ControllerFailureException("Unknown return status sealing stream " + streamName + " " + x.getStatus());
}
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "sealStream {}/{} failed: ", scope, streamName, e);
}
LoggerHelpers.traceLeave(log, "sealStream", traceId, scope, streamName, requestId);
});
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class ControllerImpl method commitTransaction.
@Override
public CompletableFuture<Void> commitTransaction(final Stream stream, final String writerId, final Long timestamp, final UUID txId) {
Exceptions.checkNotClosed(closed.get(), this);
Preconditions.checkNotNull(stream, "stream");
Preconditions.checkNotNull(txId, "txId");
long traceId = LoggerHelpers.traceEnter(log, "commitTransaction", stream, txId);
final long requestId = requestIdGenerator.get();
log.info(requestId, "Commit transaction {} invoked on Stream {} for writerId {} with timestamp {}", txId, stream, writerId, timestamp);
final CompletableFuture<TxnStatus> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<TxnStatus> callback = new RPCAsyncCallback<>(traceId, "commitTransaction", stream, writerId, timestamp, txId);
TxnRequest.Builder txnRequest = TxnRequest.newBuilder().setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())).setWriterId(writerId).setTxnId(ModelHelper.decode(txId));
if (timestamp != null) {
txnRequest.setTimestamp(timestamp);
} else {
txnRequest.setTimestamp(Long.MIN_VALUE);
}
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, COMMIT_TRANSACTION, stream.getScope(), stream.getStreamName(), txId.toString()).commitTransaction(txnRequest.build(), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(txnStatus -> {
LoggerHelpers.traceLeave(log, "commitTransaction", traceId, stream, txId);
if (txnStatus.getStatus().equals(TxnStatus.Status.STREAM_NOT_FOUND)) {
log.warn(requestId, "Stream {} not found while trying to commit transaction {}", stream.getStreamName(), 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 commit transaction {} on stream {}, commit status is {}", txId, stream, txnStatus.getStatus());
throw Exceptions.sneakyThrow(new TxnFailedException("Commit transaction failed with status: " + txnStatus.getStatus()));
}, this.executor);
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class StreamManagerImpl method deleteScope.
/**
* A new API is created hence this is going to be deprecated.
*
* @deprecated As of Pravega release 0.11.0, replaced by {@link #deleteScopeRecursive(String)}.
*/
@Override
@Deprecated
public boolean deleteScope(String scopeName, boolean forceDelete) throws DeleteScopeFailedException {
NameUtils.validateUserScopeName(scopeName);
if (forceDelete) {
log.info("Deleting scope recursively: {}", scopeName);
List<String> readerGroupList = new ArrayList<>();
Iterator<Stream> iterator = listStreams(scopeName);
while (iterator.hasNext()) {
Stream stream = iterator.next();
if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
readerGroupList.add(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()));
}
try {
Futures.getThrowingException(Futures.exceptionallyExpecting(controller.sealStream(stream.getScope(), stream.getStreamName()), 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;
}, false).thenCompose(sealed -> controller.deleteStream(stream.getScope(), stream.getStreamName())));
} catch (Exception e) {
String message = String.format("Failed to seal and delete stream %s", stream.getStreamName());
throw new DeleteScopeFailedException(message, e);
}
}
Iterator<KeyValueTableInfo> kvtIterator = controller.listKeyValueTables(scopeName).asIterator();
while (kvtIterator.hasNext()) {
KeyValueTableInfo kvt = kvtIterator.next();
try {
Futures.getThrowingException(controller.deleteKeyValueTable(scopeName, kvt.getKeyValueTableName()));
} catch (Exception e) {
String message = String.format("Failed to delete key-value table %s", kvt.getKeyValueTableName());
throw new DeleteScopeFailedException(message, e);
}
}
for (String groupName : readerGroupList) {
try {
Futures.getThrowingException(controller.getReaderGroupConfig(scopeName, groupName).thenCompose(conf -> controller.deleteReaderGroup(scopeName, groupName, conf.getReaderGroupId())));
} catch (Exception e) {
if (Exceptions.unwrap(e) instanceof ReaderGroupNotFoundException) {
continue;
}
String message = String.format("Failed to delete reader group %s", groupName);
throw new DeleteScopeFailedException(message, e);
}
}
}
return Futures.getThrowingException(controller.deleteScope(scopeName));
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class StreamManagerImplTest method testForceDeleteScope.
@Test(timeout = 10000)
public void testForceDeleteScope() throws ConnectionFailedException, DeleteScopeFailedException {
// Setup Mocks
ClientConnection connection = mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.CreateSegment.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.GetStreamSegmentInfo.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.DeleteSegment request = (WireCommands.DeleteSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.DeleteSegment.class));
connectionFactory.provideConnection(location, connection);
MockController mockController = spy(new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true));
ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
@Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
String scope = "scope";
String stream1 = "stream1";
String stream2 = "stream2";
String stream3 = "stream3";
streamManager.createScope(scope);
streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream3, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
Set<Stream> streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(3, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream3)));
// mock controller client to throw exceptions when attempting to seal and delete for stream 1.
doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to seal stream"))).when(mockController).sealStream(scope, stream1);
doAnswer(x -> Futures.failedFuture(new IllegalArgumentException("Stream not sealed"))).when(mockController).deleteStream(scope, stream1);
AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
// reset mock controller
reset(mockController);
// throw invalid stream for stream 2. Delete should happen despite invalid stream exception.
doAnswer(x -> Futures.failedFuture(new InvalidStreamException("Stream does not exist"))).when(mockController).sealStream(scope, stream2);
assertTrue(streamManager.deleteScope(scope, true));
}
use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.
the class ReaderGroupManagerImplTest method testDeleteReaderGroupRGStreamDeleted.
@Test
public void testDeleteReaderGroupRGStreamDeleted() {
ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s1"), createStreamCut("s1", 2)).put(createStream("s2"), createStreamCut("s2", 3)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenThrow(new InvalidStreamException(""));
when(controller.getReaderGroupConfig(SCOPE, GROUP_NAME)).thenReturn(CompletableFuture.completedFuture(config));
when(controller.deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId())).thenReturn(CompletableFuture.completedFuture(true));
// Delete ReaderGroup
readerGroupManager.deleteReaderGroup(GROUP_NAME);
verify(controller, times(1)).getReaderGroupConfig(SCOPE, GROUP_NAME);
verify(controller, times(1)).deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId());
}
Aggregations