Search in sources :

Example 11 with Partitions

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

the class TopologyComparatorsUnitTests method isChangedSlotsChanged.

@Test
void isChangedSlotsChanged() {
    String nodes1 = "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
    String nodes2 = "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12001-16383\n";
    Partitions partitions1 = ClusterPartitionParser.parse(nodes1);
    Partitions partitions2 = ClusterPartitionParser.parse(nodes2);
    assertThat(isChanged(partitions1, partitions2)).isTrue();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) Test(org.junit.jupiter.api.Test)

Example 12 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions 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 Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions 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 14 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions 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)

Example 15 with Partitions

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

the class RedisClusterSetupTest method clusterForget.

@Test
public void clusterForget() {
    clusterHelper.clusterReset();
    String result = redis1.clusterMeet(host, ClusterTestSettings.port6);
    assertThat(result).isEqualTo("OK");
    Wait.untilTrue(() -> redis1.clusterNodes().contains(redis2.clusterMyId())).waitOrTimeout();
    Wait.untilTrue(() -> redis2.clusterNodes().contains(redis1.clusterMyId())).waitOrTimeout();
    Wait.untilTrue(() -> {
        Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
        if (partitions.size() != 2) {
            return false;
        }
        for (RedisClusterNode redisClusterNode : partitions) {
            if (redisClusterNode.is(RedisClusterNode.NodeFlag.HANDSHAKE)) {
                return false;
            }
        }
        return true;
    }).waitOrTimeout();
    redis1.clusterForget(redis2.clusterMyId());
    Wait.untilEquals(1, () -> ClusterPartitionParser.parse(redis1.clusterNodes()).size()).waitOrTimeout();
    Partitions partitionsAfterForget = ClusterPartitionParser.parse(redis1.clusterNodes());
    assertThat(partitionsAfterForget.getPartitions()).hasSize(1);
}
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

Partitions (io.lettuce.core.cluster.models.partitions.Partitions)69 Test (org.junit.jupiter.api.Test)50 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)36 RedisURI (io.lettuce.core.RedisURI)20 ArrayList (java.util.ArrayList)13 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)10 PartitionsConsensusTestSupport.createPartitions (io.lettuce.core.cluster.PartitionsConsensusTestSupport.createPartitions)9 RedisCodec (io.lettuce.core.codec.RedisCodec)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Exceptions (io.lettuce.core.internal.Exceptions)6 Futures (io.lettuce.core.internal.Futures)6 InternalLogger (io.netty.util.internal.logging.InternalLogger)6 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)6 List (java.util.List)6 Function (java.util.function.Function)6 LettuceAssert (io.lettuce.core.internal.LettuceAssert)5 Collection (java.util.Collection)5 Iterator (java.util.Iterator)5 Map (java.util.Map)5 CompletionStage (java.util.concurrent.CompletionStage)5