我创建了一个包含三个节点的redis集群:
~ redis-3.2.10/src/redis-trib.rb create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
然后我添加了第四个节点并重新分配以进行插槽分配:
~ redis-3.2.10/src/redis-trib.rb add-node 127.0.0.1:7003 127.0.0.1:7000
~ redis-3.2.10/src/redis-trib.rb reshard --timeout 60000 127.0.0.1:7000
...
How many slots do you want to move (from 1 to 16384)? 4096
...
Source node #1:all
...
redis-3.2.10/src/redis-trib.rb check 127.0.0.1:7000
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 29fbb7e5f93eac22a224c14d4070139919bb0a5e 127.0.0.1:7000
slots:1365-5460 (4096 slots) master
0 additional replica(s)
M: c90c9f590bb48d328f3eed2fc96af3a7d9cb0f25 127.0.0.1:7003
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
M: 970b3145574a4f38bbe10548bf6b80f8fdc2854d 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
0 additional replica(s)
M: 2cc0922fcfb3e619b6d733e054dd249a4b6137bf 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
然后,如果缩小比例,将插槽重新从7003节点重新设置为剩下的三个节点,最后会出现类似的内容:
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 29fbb7e5f93eac22a224c14d4070139919bb0a5e 127.0.0.1:7000
slots:1365-5460,12288-13652 (5461 slots) master
0 additional replica(s)
M: 970b3145574a4f38bbe10548bf6b80f8fdc2854d 127.0.0.1:7001
slots:0-1364,5461-6826,10923-12287,13653-15017 (5461 slots) master
0 additional replica(s)
M: 2cc0922fcfb3e619b6d733e054dd249a4b6137bf 127.0.0.1:7002
slots:6827-10922,15018-16383 (5462 slots) master
0 additional replica(s)
M: c90c9f590bb48d328f3eed2fc96af3a7d9cb0f25 127.0.0.1:7003
slots: (0 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
:7001节点分配了4组不同的散列槽。在随后的重新分片之后,哈希插槽的“碎片化”似乎会增加。
它是否会成为一个问题(性能或其他方面)有越来越多的哈希插槽碎片?
答案 0 :(得分:0)
AFAIK no - hash slots'“fragmentation”在任何有意义的开销方面都可以忽略不计。一些直觉:
答案 1 :(得分:0)
首先创建单节点集群。 为此,您需要编辑redis_trib.rb文件以进行最少3个节点的验证。
创建单节点集群后,只需添加其他节点并在新节点中添加连续的插槽。 通过这种方式,你将获得你想要的东西。