Skip to content

Commit

Permalink
fix(controller): Fix add-slots-range algorithm in initCluster (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolik authored Jan 10, 2025
1 parent f53cfc0 commit ecdb459
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/controller/valkey_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ func (r *ValkeyReconciler) initCluster(ctx context.Context, valkey *hyperv1.Valk

// set cluster slotrange
slotRange := 16384 / int(valkey.Spec.Shards)
prevEnd := 0
for i := 0; i < int(valkey.Spec.Shards); i++ {
logger.Info("setting slotrange", "shard", i)
r.Recorder.Event(valkey, "Normal", "Setting",
Expand All @@ -573,15 +574,19 @@ func (r *ValkeyReconciler) initCluster(ctx context.Context, valkey *hyperv1.Valk
if cont {
continue
}
start := slotRange * i
end := slotRange*(i+1) - 1
start := prevEnd + 1
if i == 0 {
start = 0
}
end := start + slotRange
if i == int(valkey.Spec.Shards)-1 {
end = end + 1
end = 16383
}
if err := clients[podNames[i]].Do(ctx, clients[podNames[i]].B().ClusterAddslotsrange().StartSlotEndSlot().StartSlotEndSlot(int64(start), int64(end)).Build()).Error(); err != nil {
logger.Error(err, "failed to set slotrange")
return err
}
prevEnd = end
}

// set cluster meet
Expand Down

0 comments on commit ecdb459

Please sign in to comment.