Search in sources :

Example 11 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class TopologyComparatorsUnitTests method createNode.

private RedisClusterNode createNode(Integer... slots) {
    RedisClusterNode node = new RedisClusterNode();
    node.setSlots(Arrays.asList(slots));
    return node;
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode)

Example 12 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class TopologyRefreshIntegrationTests method adaptiveTriggerOnMoveRedirection.

@Test
void adaptiveTriggerOnMoveRedirection() {
    ClusterTopologyRefreshOptions topologyRefreshOptions = // 
    ClusterTopologyRefreshOptions.builder().enableAdaptiveRefreshTrigger(// 
    ClusterTopologyRefreshOptions.RefreshTrigger.MOVED_REDIRECT).build();
    clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(topologyRefreshOptions).build());
    StatefulRedisClusterConnection<String, String> connection = clusterClient.connect();
    RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = connection.async();
    Partitions partitions = connection.getPartitions();
    RedisClusterNode node1 = partitions.getPartitionBySlot(0);
    RedisClusterNode node2 = partitions.getPartitionBySlot(12000);
    List<Integer> slots = node2.getSlots();
    slots.addAll(node1.getSlots());
    node2.setSlots(slots);
    node1.setSlots(Collections.emptyList());
    partitions.updateCache();
    assertThat(clusterClient.getPartitions().getPartitionByNodeId(node1.getNodeId()).getSlots()).hasSize(0);
    assertThat(clusterClient.getPartitions().getPartitionByNodeId(node2.getNodeId()).getSlots()).hasSize(16384);
    // slot 3300
    connection.reactive().set("b", value).toFuture();
    Wait.untilEquals(12000, () -> clusterClient.getPartitions().getPartitionByNodeId(node1.getNodeId()).getSlots().size()).waitOrTimeout();
    assertThat(clusterClient.getPartitions().getPartitionByNodeId(node1.getNodeId()).getSlots()).hasSize(12000);
    assertThat(clusterClient.getPartitions().getPartitionByNodeId(node2.getNodeId()).getSlots()).hasSize(4384);
    clusterConnection.getStatefulConnection().close();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) ClusterTopologyRefreshOptions(io.lettuce.core.cluster.ClusterTopologyRefreshOptions) Test(org.junit.jupiter.api.Test)

Example 13 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class TopologyRefreshIntegrationTests method runReconnectTest.

private void runReconnectTest(BiFunction<RedisAdvancedClusterAsyncCommands<String, String>, RedisClusterNode, BaseRedisAsyncCommands> function) {
    ClusterTopologyRefreshOptions topologyRefreshOptions = // 
    ClusterTopologyRefreshOptions.builder().refreshTriggersReconnectAttempts(// 
    0).enableAllAdaptiveRefreshTriggers().build();
    clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(topologyRefreshOptions).build());
    RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
    RedisClusterNode node = clusterClient.getPartitions().getPartition(0);
    BaseRedisAsyncCommands closeable = function.apply(clusterConnection, node);
    clusterClient.getPartitions().clear();
    closeable.quit();
    Wait.untilTrue(() -> {
        return !clusterClient.getPartitions().isEmpty();
    }).waitOrTimeout();
    if (closeable instanceof RedisAdvancedClusterCommands) {
        ((RedisAdvancedClusterCommands) closeable).getStatefulConnection().close();
    }
    clusterConnection.getStatefulConnection().close();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisAdvancedClusterCommands(io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands) ClusterTopologyRefreshOptions(io.lettuce.core.cluster.ClusterTopologyRefreshOptions) BaseRedisAsyncCommands(io.lettuce.core.api.async.BaseRedisAsyncCommands)

Example 14 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class RedisClusterSetupTest method atLeastOnceForgetNodeFailover.

@Test
public void atLeastOnceForgetNodeFailover() throws Exception {
    clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(PERIODIC_REFRESH_ENABLED).build());
    RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
    clusterClient.setOptions(ClusterClientOptions.create());
    ClusterSetup.setup2Masters(clusterHelper);
    assertRoutedExecution(clusterConnection);
    RedisClusterNode partition1 = getOwnPartition(redis1);
    RedisClusterNode partition2 = getOwnPartition(redis2);
    RedisClusterAsyncCommands<String, String> node1Connection = clusterConnection.getConnection(partition1.getUri().getHost(), partition1.getUri().getPort());
    RedisClusterAsyncCommands<String, String> node2Connection = clusterConnection.getConnection(partition2.getUri().getHost(), partition2.getUri().getPort());
    shiftAllSlotsToNode1();
    suspendConnection(node2Connection);
    List<RedisFuture<String>> futures = new ArrayList<>();
    // 15891
    futures.add(clusterConnection.set("t", "value"));
    // 16023
    futures.add(clusterConnection.set("p", "value"));
    // 6373
    clusterConnection.set("A", "value").get(1, TimeUnit.SECONDS);
    for (RedisFuture<String> future : futures) {
        assertThat(future.isDone()).isFalse();
        assertThat(future.isCancelled()).isFalse();
    }
    redis1.clusterForget(partition2.getNodeId());
    redis2.clusterForget(partition1.getNodeId());
    Partitions partitions = clusterClient.getPartitions();
    partitions.remove(partition2);
    partitions.getPartition(0).setSlots(Arrays.stream(createSlots(0, 16384)).boxed().collect(Collectors.toList()));
    partitions.updateCache();
    clusterClient.updatePartitionsInConnections();
    Wait.untilTrue(() -> TestFutures.areAllDone(futures)).waitOrTimeout();
    assertRoutedExecution(clusterConnection);
    clusterConnection.getStatefulConnection().close();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisFuture(io.lettuce.core.RedisFuture) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 15 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class RedisClusterSetupTest method expireStaleNodeIdConnections.

@Test
public void expireStaleNodeIdConnections() {
    clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(PERIODIC_REFRESH_ENABLED).build());
    RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
    ClusterSetup.setup2Masters(clusterHelper);
    PooledClusterConnectionProvider<String, String> clusterConnectionProvider = getPooledClusterConnectionProvider(clusterConnection);
    assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(0);
    assertRoutedExecution(clusterConnection);
    assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(2);
    Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
    for (RedisClusterNode redisClusterNode : partitions.getPartitions()) {
        if (!redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
            redis1.clusterForget(redisClusterNode.getNodeId());
        }
    }
    partitions = ClusterPartitionParser.parse(redis2.clusterNodes());
    for (RedisClusterNode redisClusterNode : partitions.getPartitions()) {
        if (!redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
            redis2.clusterForget(redisClusterNode.getNodeId());
        }
    }
    Wait.untilEquals(1, () -> clusterClient.getPartitions().size()).waitOrTimeout();
    Wait.untilEquals(1, () -> clusterConnectionProvider.getConnectionCount()).waitOrTimeout();
    clusterConnection.getStatefulConnection().close();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Aggregations

RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)94 Test (org.junit.jupiter.api.Test)60 Partitions (io.lettuce.core.cluster.models.partitions.Partitions)36 ArrayList (java.util.ArrayList)18 RedisURI (io.lettuce.core.RedisURI)13 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)12 RedisNodeDescription (io.lettuce.core.models.role.RedisNodeDescription)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 ReadFrom (io.lettuce.core.ReadFrom)9 RedisCodec (io.lettuce.core.codec.RedisCodec)9 List (java.util.List)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Function (java.util.function.Function)6 CompletionStage (java.util.concurrent.CompletionStage)5 RedisException (io.lettuce.core.RedisException)4 RedisFuture (io.lettuce.core.RedisFuture)4 Exceptions (io.lettuce.core.internal.Exceptions)4 Futures (io.lettuce.core.internal.Futures)4 InternalLogger (io.netty.util.internal.logging.InternalLogger)4