dictht[1]:扩容缩容分片集群
dictht[0]:待回收分片集群(回收机器前的过渡集群)
shard*: redis分片机器(分片机器:哨兵+主从模式)
1.扩容前
dictht[1]:[shard1,shard2,shard3]
dictht[0]:[]
2.扩容
dictht[1]:[shard4,shard5,shard6,shard7,shard8,shard9]
dictht[0]:[shard1,shard2,shard3]
3.缩容
dictht[1]:[shard1,shard2,shard3]
dictht[0]:[shard4,shard5,shard6,shard7,shard8,shard9]
4.回收机器
dictht[1]:[shard1,shard2,shard3]
dictht[0]:[]
查询操作: 先从dictht[1]查询,查询不到就查询dictht[0]
新增修改删除操作:新增修改删除dictht[1],删除dictht[0] (只要数据命中dictht[1]的分片与dictht[0]的分片不一样,就干掉dictht[0]数据,因为dictht[0]是一个待回收的分片集群,等dictht[0]里面的数据删完了就回收机器)
渐进式扩容需注意事项
1.dictht[1]与dictht[0]的分片机器不要一样,不然回收机器的时候,dictht[1]与dictht[0]有一样的分片,但是dictht[0]数据没有删除干净,dictht[1]该分片就产生了垃圾数据
2.回收的时候应尽可能让dictht[0]数据清完回收,不然就会丢失redis数据(根据具体应用场景及成本考虑调整回收时间点)