use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class ParseReaderGroupStreamCommand method execute.
@Override
public void execute() throws Exception {
ensureArgCount(4);
final String scope = getArg(0);
final String readerGroup = getArg(1);
final String segmentStoreHost = getArg(2);
final String fileName = getArg(3);
String stream = NameUtils.getStreamForReaderGroup(readerGroup);
@Cleanup ConnectionPool pool = createConnectionPool();
@Cleanup Controller controller = instantiateController(pool);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup SegmentHelper segmentHelper = instantiateSegmentHelper(zkClient, pool);
readRGSegmentToFile(segmentHelper, segmentStoreHost, controller, scope, stream, fileName);
output("The readerGroup stream has been successfully written into %s", fileName);
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class BatchClientFactoryImpl method getStreamSegmentInfo.
private StreamSegmentsIterator getStreamSegmentInfo(final Stream stream, final StreamCut startStreamCut, final StreamCut endStreamCut) {
log.debug("Start stream cut: {}, End stream cut: {}", startStreamCut, endStreamCut);
StreamSegmentsInfoImpl.validateStreamCuts(startStreamCut, endStreamCut);
StreamSegmentSuccessors segments = getAndHandleExceptions(controller.getSegments(startStreamCut, endStreamCut), RuntimeException::new);
final SortedSet<Segment> segmentSet = new TreeSet<>(segments.getSegments());
final DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(controller, stream.getScope(), stream.getStreamName(), AccessOperation.READ);
log.debug("List of Segments between the start and end stream cuts : {}", segmentSet);
val futures = segmentSet.stream().map(s -> getSegmentRange(s, startStreamCut, endStreamCut, tokenProvider)).collect(Collectors.toList());
List<SegmentRange> results = Futures.getThrowingException(Futures.allOfWithResults(futures));
return StreamSegmentsInfoImpl.builder().segmentRangeIterator(results.iterator()).startStreamCut(startStreamCut).endStreamCut(endStreamCut).build();
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class KeyValueTableFactory method withScope.
/**
* Creates a new instance of {@link KeyValueTableFactory}.
*
* @param scope The Key-Value Table scope.
* @param config Configuration for the client.
* @return Instance of {@link KeyValueTableFactory} implementation.
*/
static KeyValueTableFactory withScope(String scope, ClientConfig config) {
ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
ConnectionPool connectionPool = new ConnectionPoolImpl(config, connectionFactory);
Controller controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).build(), connectionFactory.getInternalExecutor());
return new KeyValueTableFactoryImpl(scope, controller, connectionPool);
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class ConditionalOutputStreamImpl method write.
@Override
public boolean write(ByteBuffer data, long expectedOffset) throws SegmentSealedException {
Exceptions.checkNotClosed(closed.get(), this);
synchronized (lock) {
// Used to preserver order.
long appendSequence = requestIdGenerator.get();
return retrySchedule.retryWhen(e -> {
Throwable cause = Exceptions.unwrap(e);
boolean hasTokenExpired = cause instanceof TokenExpiredException;
if (hasTokenExpired) {
this.tokenProvider.signalTokenExpired();
}
return cause instanceof Exception && (hasTokenExpired || cause instanceof ConnectionFailedException);
}).run(() -> {
if (client == null || client.isClosed()) {
client = new RawClient(controller, connectionPool, segmentId);
long requestId = client.getFlow().getNextSequenceNumber();
log.debug("Setting up appends on segment {} for ConditionalOutputStream with writer id {}", segmentId, writerId);
CompletableFuture<Reply> reply = tokenProvider.retrieveToken().thenCompose(token -> {
SetupAppend setup = new SetupAppend(requestId, writerId, segmentId.getScopedName(), token);
return client.sendRequest(requestId, setup);
});
AppendSetup appendSetup = transformAppendSetup(reply.join());
if (appendSetup.getLastEventNumber() >= appendSequence) {
return true;
}
}
long requestId = client.getFlow().getNextSequenceNumber();
val request = new ConditionalAppend(writerId, appendSequence, expectedOffset, new Event(Unpooled.wrappedBuffer(data)), requestId);
val reply = client.sendRequest(requestId, request);
return transformDataAppended(reply.join());
});
}
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class ReaderGroupImpl method resetReaderGroup.
@Override
public void resetReaderGroup(ReaderGroupConfig config) {
log.info("Reset ReaderGroup {} to {}", getGroupName(), config);
synchronizer.fetchUpdates();
while (true) {
val currentConfig = synchronizer.getState().getConfig();
// We only move into the block if the state transition has happened successfully.
if (stateTransition(currentConfig, new UpdatingConfig(true))) {
if (currentConfig.getReaderGroupId() == ReaderGroupConfig.DEFAULT_UUID && currentConfig.getGeneration() == ReaderGroupConfig.DEFAULT_GENERATION) {
// Migration code path, for moving a ReaderGroup from version < 0.9 to 0.9+
final ReaderGroupConfig updateConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
final long nextGen = Futures.getThrowingException(controller.createReaderGroup(scope, getGroupName(), updateConfig).thenCompose(conf -> {
if (!conf.getReaderGroupId().equals(updateConfig.getReaderGroupId())) {
return controller.updateReaderGroup(scope, groupName, ReaderGroupConfig.cloneConfig(updateConfig, conf.getReaderGroupId(), conf.getGeneration()));
} else {
// ReaderGroup IDs matched so our create was updated on Controller
return CompletableFuture.completedFuture(conf.getGeneration());
}
}));
updateConfigInStateSynchronizer(updateConfig, nextGen);
} else {
// normal code path
// Use the latest generation and reader group Id.
ReaderGroupConfig newConfig = ReaderGroupConfig.cloneConfig(config, currentConfig.getReaderGroupId(), currentConfig.getGeneration());
long newGen = Futures.exceptionallyExpecting(controller.updateReaderGroup(scope, groupName, newConfig), e -> Exceptions.unwrap(e) instanceof ReaderGroupConfigRejectedException, -1L).join();
if (newGen == -1) {
log.debug("Synchronize reader group with the one present on controller.");
synchronizeReaderGroupConfig();
continue;
}
updateConfigInStateSynchronizer(newConfig, newGen);
}
return;
}
}
}
Aggregations