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;
}
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();
}
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();
}
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();
}
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();
}
Aggregations