Skip to content

Commit

Permalink
add redis cluster common ut
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie committed Oct 10, 2024
1 parent a0ae9ed commit 662e49a
Show file tree
Hide file tree
Showing 2 changed files with 430 additions and 7 deletions.
14 changes: 7 additions & 7 deletions addons/redis/redis-cluster-scripts/redis-cluster-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,18 @@ check_cluster_initialized() {
# all cluster node share the same service port
local cluster_node_service_port="$2"
if is_empty "$cluster_node_list" || is_empty "$cluster_node_service_port"; then
echo "Error: Required environment variable cluster_node_list or cluster_node_service_port is not set."
exit 1
echo "Error: Required environment variable cluster_node_list or cluster_node_service_port is not set." >&2
return 1
fi

for pod_ip in $(echo "$cluster_node_list" | tr ',' ' '); do
cluster_info=$(get_cluster_info "$pod_ip" "$cluster_node_service_port")
status=$?
if [ $status -ne 0 ]; then
echo "Failed to get cluster info in check_cluster_initialized" >&2
exit 1
return 1
fi
cluster_state=$(echo "$cluster_info" | grep -oP '(?<=cluster_state:)[^\s]+')
cluster_state=$(echo "$cluster_info" | awk -F: '/cluster_state/{print $2}' | tr -d '[:space:]')
if is_empty "$cluster_state" || equals "$cluster_state" "ok"; then
echo "Redis Cluster already initialized"
return 0
Expand Down Expand Up @@ -472,13 +472,13 @@ build_rebalance_to_zero_command() {
local node_cluster_id="$2"
unset_xtrace_when_ut_mode_false
if is_empty "$REDIS_DEFAULT_PASSWORD"; then
rebalance_command="redis-cli --cluster rebalance $primary_node --cluster-weight $primary_node_cluster_id=0 --cluster-yes "
rebalance_command="redis-cli --cluster rebalance $node_with_port --cluster-weight $node_cluster_id=0 --cluster-yes "
logging_mask_rebalance_command="$rebalance_command"
else
rebalance_command="redis-cli --cluster rebalance $primary_node --cluster-weight $primary_node_cluster_id=0 --cluster-yes -a $REDIS_DEFAULT_PASSWORD"
rebalance_command="redis-cli --cluster rebalance $node_with_port --cluster-weight $node_cluster_id=0 --cluster-yes -a $REDIS_DEFAULT_PASSWORD"
logging_mask_rebalance_command="${rebalance_command/$REDIS_DEFAULT_PASSWORD/********}"
fi
echo "set current component slot to 0 by rebalance command: $logging_mask_rebalance_command"
echo "set current component slot to 0 by rebalance command: $logging_mask_rebalance_command" >&2
set_xtrace_when_ut_mode_false
echo "$rebalance_command"
}
Expand Down
Loading

0 comments on commit 662e49a

Please sign in to comment.