Skip to content

Commit

Permalink
feat(redis): RedisCluster部署方案 #3482
Browse files Browse the repository at this point in the history
  • Loading branch information
xiepaup authored and iSecloud committed Mar 21, 2024
1 parent 6e4d329 commit bc55bf9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dbm-ui/backend/db_services/dbresource/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from backend.db_meta.enums import ClusterType
from backend.db_services.dbresource.handlers import (
MongoDBShardSpecFilter,
RedisClusterSpecFilter,
TenDBClusterSpecFilter,
TendisCacheSpecFilter,
TendisPlusSpecFilter,
Expand All @@ -32,6 +33,7 @@
# 集群对应的规格筛选类
CLUSTER_TYPE__SPEC_FILTER = {
ClusterType.TenDBCluster: TenDBClusterSpecFilter,
ClusterType.TendisPredixyRedisCluster: RedisClusterSpecFilter,
ClusterType.TendisPredixyTendisplusCluster: TendisPlusSpecFilter,
ClusterType.TendisTwemproxyRedisInstance: TendisCacheSpecFilter,
ClusterType.TwemproxyTendisSSDInstance: TendisSSDSpecFilter,
Expand Down
63 changes: 63 additions & 0 deletions dbm-ui/backend/db_services/dbresource/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,69 @@ def custom_filter(self):
super().custom_filter()


class RedisClusterSpecFilter(RedisSpecFilter):
"""官方RedisCluster集群规格过滤器"""

# 最小机器组数
MIN_MACHINE_PAIR = 3
# 单个实例建议的容量规格
BASE_SINGLE_CAPCITY = 6
# 支持简单阔缩容倍数(非DTS方式/Slot迁移扩容方式)
SCALE_MULITPLE = 4

def calc_cluster_shard_num(self):
self.future_capacity = int(self.future_capacity)
self.capacity = int(self.capacity)
valid_specs: List[Dict[str, Any]] = []
max_capcity = self.capacity
if self.future_capacity > self.capacity:
max_capcity = min(self.future_capacity, int(self.capacity) * int(self.SCALE_MULITPLE) / 2)
# 先进行排序
self.specs.sort(key=lambda x: (x["capacity"]))

print(self.specs)

# 选取合适的规格
spec_idx, instance_cap, spec_cnt, avaiable_specs = 0, self.BASE_SINGLE_CAPCITY, len(self.specs), []
for spec in self.specs:
if self.capacity <= spec["capacity"] * self.MIN_MACHINE_PAIR:
avaiable_specs.append(spec)
if spec_idx >= 1:
avaiable_specs.append(self.specs[spec_idx - 1])
if spec_idx >= 3:
avaiable_specs.append(self.specs[spec_idx - 2])
break
spec_idx += 1

if self.capacity > self.specs[spec_cnt - 1]["capacity"] * self.SCALE_MULITPLE:
instance_cap = self.BASE_SINGLE_CAPCITY * self.SCALE_MULITPLE

if self.capacity > self.specs[spec_cnt - 1]["capacity"]:
avaiable_specs.append(self.specs[spec_cnt - 1])
if spec_cnt > 2:
avaiable_specs.append(self.specs[spec_cnt - 2])

for spec_new in avaiable_specs:
# 至少是三组机器
spec_new["machine_pair"] = max(math.ceil(self.capacity / spec["capacity"]), self.MIN_MACHINE_PAIR)

# 一定要保证集群总分片数是机器组数的整数倍,
cluster_shard_num = math.ceil(max_capcity / instance_cap)
single_machine_shard_num = math.ceil(cluster_shard_num / spec_new["machine_pair"])
# 并且单机分片数需要取整,取偶
single_machine_shard_num = max(single_machine_shard_num + (single_machine_shard_num & 1), 2)
# 保证3分片打底
spec_new["cluster_shard_num"] = max(
single_machine_shard_num * spec_new["machine_pair"], self.MIN_MACHINE_PAIR
)
valid_specs.append(spec_new)

self.specs = valid_specs

def custom_filter(self):
super().custom_filter()


class TendisSSDSpecFilter(RedisSpecFilter):
"""TendisSSD集群规格过滤器"""

Expand Down

0 comments on commit bc55bf9

Please sign in to comment.