Search in sources :

Example 1 with ClusterTopologyChangedEvent

use of io.lettuce.core.cluster.event.ClusterTopologyChangedEvent in project lettuce-core by lettuce-io.

the class RedisClusterClient method refreshPartitionsAsync.

/**
 * Asynchronously reload partitions and re-initialize the distribution table.
 *
 * @return a {@link CompletionStage} that signals completion.
 * @since 6.0
 */
public CompletionStage<Void> refreshPartitionsAsync() {
    List<RedisURI> sources = new ArrayList<>();
    Iterable<RedisURI> topologyRefreshSource = getTopologyRefreshSource();
    for (RedisURI redisURI : topologyRefreshSource) {
        sources.add(redisURI);
    }
    EventRecorder.RecordableEvent event = EventRecorder.getInstance().start(new TopologyRefreshEvent(sources));
    if (partitions == null) {
        return initializePartitions().thenAccept(Partitions::updateCache).whenComplete((unused, throwable) -> event.record());
    }
    return loadPartitionsAsync().thenAccept(loadedPartitions -> {
        if (TopologyComparators.isChanged(getPartitions(), loadedPartitions)) {
            logger.debug("Using a new cluster topology");
            List<RedisClusterNode> before = new ArrayList<>(getPartitions());
            List<RedisClusterNode> after = new ArrayList<>(loadedPartitions);
            getResources().eventBus().publish(new ClusterTopologyChangedEvent(before, after));
        }
        this.partitions.reload(loadedPartitions.getPartitions());
        updatePartitionsInConnections();
    }).whenComplete((unused, throwable) -> event.record());
}
Also used : StatefulRedisClusterPubSubConnection(io.lettuce.core.cluster.pubsub.StatefulRedisClusterPubSubConnection) SocketAddress(java.net.SocketAddress) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) Futures(io.lettuce.core.internal.Futures) LettuceAssert(io.lettuce.core.internal.LettuceAssert) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Duration(java.time.Duration) Map(java.util.Map) PubSubEndpoint(io.lettuce.core.pubsub.PubSubEndpoint) URI(java.net.URI) CommandHandler(io.lettuce.core.protocol.CommandHandler) LettuceLists(io.lettuce.core.internal.LettuceLists) Exceptions(io.lettuce.core.internal.Exceptions) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RedisCodec(io.lettuce.core.codec.RedisCodec) StatefulRedisClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection) TopologyRefreshEvent(io.lettuce.core.cluster.event.TopologyRefreshEvent) StatefulRedisPubSubConnectionImpl(io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl) ClusterTopologyChangedEvent(io.lettuce.core.cluster.event.ClusterTopologyChangedEvent) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) InternalLogger(io.netty.util.internal.logging.InternalLogger) KeyValueStreamingChannel(io.lettuce.core.output.KeyValueStreamingChannel) io.lettuce.core(io.lettuce.core) NodeSelectionSupport(io.lettuce.core.cluster.api.NodeSelectionSupport) ClusterTopologyRefresh(io.lettuce.core.cluster.topology.ClusterTopologyRefresh) ClientResources(io.lettuce.core.resource.ClientResources) TopologyComparators(io.lettuce.core.cluster.topology.TopologyComparators) StringCodec(io.lettuce.core.codec.StringCodec) PushHandler(io.lettuce.core.protocol.PushHandler) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RedisAdvancedClusterAsyncCommands(io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) NodeConnectionFactory(io.lettuce.core.cluster.topology.NodeConnectionFactory) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisAdvancedClusterCommands(io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands) StatefulRedisPubSubConnection(io.lettuce.core.pubsub.StatefulRedisPubSubConnection) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) Mono(reactor.core.publisher.Mono) EventRecorder(io.lettuce.core.event.jfr.EventRecorder) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Closeable(java.io.Closeable) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) Collections(java.util.Collections) ClusterTopologyChangedEvent(io.lettuce.core.cluster.event.ClusterTopologyChangedEvent) TopologyRefreshEvent(io.lettuce.core.cluster.event.TopologyRefreshEvent) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) EventRecorder(io.lettuce.core.event.jfr.EventRecorder)

Aggregations

io.lettuce.core (io.lettuce.core)1 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 NodeSelectionSupport (io.lettuce.core.cluster.api.NodeSelectionSupport)1 StatefulRedisClusterConnection (io.lettuce.core.cluster.api.StatefulRedisClusterConnection)1 RedisAdvancedClusterAsyncCommands (io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands)1 RedisAdvancedClusterCommands (io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands)1 ClusterTopologyChangedEvent (io.lettuce.core.cluster.event.ClusterTopologyChangedEvent)1 TopologyRefreshEvent (io.lettuce.core.cluster.event.TopologyRefreshEvent)1 Partitions (io.lettuce.core.cluster.models.partitions.Partitions)1 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)1 StatefulRedisClusterPubSubConnection (io.lettuce.core.cluster.pubsub.StatefulRedisClusterPubSubConnection)1 ClusterTopologyRefresh (io.lettuce.core.cluster.topology.ClusterTopologyRefresh)1 NodeConnectionFactory (io.lettuce.core.cluster.topology.NodeConnectionFactory)1 TopologyComparators (io.lettuce.core.cluster.topology.TopologyComparators)1 RedisCodec (io.lettuce.core.codec.RedisCodec)1 StringCodec (io.lettuce.core.codec.StringCodec)1 EventRecorder (io.lettuce.core.event.jfr.EventRecorder)1 Exceptions (io.lettuce.core.internal.Exceptions)1 Futures (io.lettuce.core.internal.Futures)1 LettuceAssert (io.lettuce.core.internal.LettuceAssert)1