From 4ed68a7e4a03d66f251c82fd932fa61060ba576f Mon Sep 17 00:00:00 2001 From: drivebyer Date: Thu, 27 Oct 2022 01:35:23 -0400 Subject: [PATCH] fix: lost replications when followerReplicas bigger than leaderReplicas Signed-off-by: drivebyer --- .gitignore | 1 + k8sutils/redis.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 402d62a54..3f4669bdb 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,6 @@ testbin/* *.swp *.swo *~ +.vscode docs/build \ No newline at end of file diff --git a/k8sutils/redis.go b/k8sutils/redis.go index e2987ae69..8235b6bc8 100644 --- a/k8sutils/redis.go +++ b/k8sutils/redis.go @@ -158,15 +158,16 @@ func createRedisReplicationCommand(cr *redisv1beta1.RedisCluster, leaderPod Redi func ExecuteRedisReplicationCommand(cr *redisv1beta1.RedisCluster) { var podIP string logger := generateRedisManagerLogger(cr.Namespace, cr.ObjectMeta.Name) - replicas := cr.Spec.GetReplicaCounts("follower") + followerCounts := cr.Spec.GetReplicaCounts("follower") + leaderCounts := cr.Spec.GetReplicaCounts("leader") nodes := checkRedisCluster(cr) - for podCount := 0; podCount <= int(replicas)-1; podCount++ { + for followerIdx := 0; followerIdx <= int(followerCounts)-1; followerIdx++ { followerPod := RedisDetails{ - PodName: cr.ObjectMeta.Name + "-follower-" + strconv.Itoa(podCount), + PodName: cr.ObjectMeta.Name + "-follower-" + strconv.Itoa(followerIdx), Namespace: cr.Namespace, } leaderPod := RedisDetails{ - PodName: cr.ObjectMeta.Name + "-leader-" + strconv.Itoa(podCount), + PodName: cr.ObjectMeta.Name + "-leader-" + strconv.Itoa(int(followerIdx)%int(leaderCounts)), Namespace: cr.Namespace, } podIP = getRedisServerIP(followerPod)