Skip to content

Commit

Permalink
Fix computation of ShuffleShardExpectedInstancesPerZone for math.MaxI…
Browse files Browse the repository at this point in the history
…nt. (grafana#567)
  • Loading branch information
pstibrany authored Aug 16, 2024
1 parent aa1c6eb commit cbfe0ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ring/shard/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func ShuffleShardSeed(identifier, zone string) int64 {
// zone when zone-aware replication is enabled. The algorithm expects the shard size to be divisible
// by the number of zones, in order to have nodes balanced across zones. If it's not, we do round up.
func ShuffleShardExpectedInstancesPerZone(shardSize, numZones int) int {
if shardSize == math.MaxInt {
return math.MaxInt
}
return int(math.Ceil(float64(shardSize) / float64(numZones)))
}

Expand Down
6 changes: 6 additions & 0 deletions ring/shard/shard_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shard

import (
"math"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -38,6 +39,11 @@ func TestShuffleShardExpectedInstancesPerZone(t *testing.T) {
numZones: 3,
expected: 2,
},
{
shardSize: math.MaxInt,
numZones: 3,
expected: math.MaxInt,
},
}

for _, test := range tests {
Expand Down

0 comments on commit cbfe0ab

Please sign in to comment.