Skip to content

Commit

Permalink
update for #68: add node architecture
Browse files Browse the repository at this point in the history
MrYourM committed Feb 11, 2020
1 parent 37e216b commit be5244e
Showing 8 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
getSlavePriority(){
local mySid="{{ getv "/host/sid" }}"
local ourSid="$(echo "{{ range gets "/hosts/*/sid" }}
{{- printf .Value }}
{{ end }}" |sort -n)"
local sid counter=0; for sid in $ourSid;do
counter=$(($counter+1))
[[ "$sid" == "$mySid" ]] && break
done
if [[ $counter -le 3 ]];then echo 100; else echo 0;fi
}
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
flush /opt/app/bin/envs/node-redis-standalone.env << REDIS_ENV_EOF
SERVICES="\$SERVICES $(echo "
redis-server/true/tcp:{{ getv "/env/port" "6379" }}
redis-sentinel/{{ eq (len $allHosts) 3 }}/tcp:26379
redis-sentinel/$(if {{ ge (len $allHosts) 3 }} && [[ $(getSlavePriority) -eq 100 ]];then echo "true";else echo "false";fi)/tcp:26379
" | xargs)"
NODE_CTL="redis-standalone"
MY_NODE_ID="{{ getv "/host/node_id" }}"
Original file line number Diff line number Diff line change
@@ -25,7 +25,9 @@ renameCommands() {
done
}


flush /opt/app/conf/redis-standalone/redis.changed.conf << REDIS_CHANGED_CONF_EOF
slave-priority $(getSlavePriority)
databases {{ getv "/env/databases" "16" }}
activerehashing {{ getv "/env/activerehashing" "yes" }}
appendfsync {{ getv "/env/appendfsync" "everysec" }}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ FIND_MASTER_IP_ERR=210
LEAVING_REDIS_NODES_IS_NONE_ERR=211
LEAVING_REDIS_NODES_INCLUDE_MASTER_ERR=212
MASTER_SALVE_SWITCH_WHEN_DEL_NODE_ERR=213
LEAVING_REDIS_NODES_INCLUDE_SENTINEL_NODE=214
REDIS_COMMAND_EXECUTE_FAIL_ERR=220
RDB_FILE_EXIST_ERR=221
RDB_FILE_CHECK_ERR=222
@@ -93,6 +94,16 @@ checkMasterNotLeaving() {
preScaleIn() {
[ -n "$LEAVING_REDIS_NODES" ] || return $LEAVING_REDIS_NODES_IS_NONE_ERR
checkMasterNotLeaving

# 防止最终计划剩余3个节点的时候,删除了 sentinel 节点
local leavingNodesCount; leavingNodesCount=$(echo "$LEAVING_REDIS_NODES" |wc -w)
local allNodesCount; allNodesCount=$(echo "$REDIS_NODES" |wc -w)
if [[ $(($allNodesCount-$leavingNodesCount)) -ge 3 ]];then
local firstToThirdNode="$(eval echo "$allNodesCount" |xargs -n1| sort -n -t'/' -k1| xargs|cut -d" " -f1-3)"
local node;for node in $firstToThirdNode;do
echo "$LEAVING_REDIS_NODES" |grep -vq "$node" || return $LEAVING_REDIS_NODES_INCLUDE_SENTINEL_NODE
done
fi
}

destroy() {
@@ -410,9 +421,10 @@ check(){
}

getRedisRoles(){
local node nodeIp myRole; for node in $REDIS_NODES; do
local node nodeIp myRole counter=0; for node in $(echo "$REDIS_NODES" |sort -n -t"/" -k1); do
counter=$(($counter+1))
nodeIp="$(echo "$node" |cut -d"/" -f3)"
myRole="$(runRedisCmd --ip "$nodeIp" role | head -n1)"
echo "$nodeIp $myRole"
done | jq -Rc 'split(" ") | [ . ]' | jq -s add | jq -c '{"labels":["ip","role"],"data":.}'
myRole="$(runRedisCmd --ip "$nodeIp" role | head -n1 || echo "unknown")"
echo "$nodeIp $myRole $(if [[ $counter -le 3 ]];then echo "true"; else echo "false";fi)"
done | jq -Rc 'split(" ") | [ . ]' | jq -s add | jq -c '{"labels":["ip","role","disabled_delete"],"data":.}'
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@ rdbchecksum yes
rdbcompression yes
repl-disable-tcp-nodelay no
save ""
slave-priority 100
slave-read-only yes
slave-serve-stale-data yes
slowlog-max-len 128
2 changes: 1 addition & 1 deletion app-standalone/cluster.json.mustache
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
"container": {
"type": "lxc",
"zone": "pek3a",
"image": "img-tb8o5ojo"
"image": "img-x6cv1kyp"
},
"instance_class": {{cluster.node.instance_class}},
"count": {{cluster.node.count}},
5 changes: 4 additions & 1 deletion app-standalone/config.json
Original file line number Diff line number Diff line change
@@ -98,7 +98,10 @@
"default": 1,
"range": [
1,
3
3,
5,
7,
9
],
"required": "yes"
}
2 changes: 2 additions & 0 deletions app-standalone/locale/zh-cn.json
Original file line number Diff line number Diff line change
@@ -122,6 +122,7 @@
"err_code211": "待删除节点为空,禁止删除操作,请通过工单与我们沟通",
"err_code212": "为了避免数据丢失,请选择从节点进行删除,主从关系可以通过监控项获取",
"err_code213": "刚才可能发生了主从切换,导致要删除的节点中包含主节点;为了避免数据丢失,请稍后选择从节点进行删除",
"err_code214": "剩余的节点数大于或等于三个节点时,我们有限制其中三个节点禁止删除,禁止删除的节点可以从「节点实时角色」获取",
"err_code220": "redis 命令执行失败,请通过工单与我们沟通",
"err_code221": "RDB 文件不存在,请您先上传 RDB 文件",
"err_code222": "RDB 文件格式有误,请您上传正确的 RDB 文件",
@@ -149,6 +150,7 @@
"roles": "节点实时角色",
"ip": "节点 IP",
"role": "节点角色",
"disabled_delete": "删除后节点数大于等于3,禁止删除",
"confirm": "确认操作?",
"All existing data will be erased, and please ensure there is only one redis node; choose 'yes' to continue": "该操作仅支持单节点集群,且会清空现有集群的所有数据,数据需要自行备份,yes 表示确认并继续执行,no 表示不执行",
"params": "参数",

0 comments on commit be5244e

Please sign in to comment.