Skip to content

Commit 092c970

Browse files
authored
fix(v2): shard limit overflow (#4125)
1 parent e466442 commit 092c970

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

pkg/experiment/distributor/placement/adaptive_placement/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func (o *PlacementLimits) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet
3434
f.Uint64Var(&o.TenantShards, prefix+"tenant-shards", 0, "Number of shards per tenant. If 0, the limit is not applied.")
3535
f.Uint64Var(&o.DefaultDatasetShards, prefix+"default-dataset-shards", 1, "Default number of shards per dataset.")
3636
f.Uint64Var(&o.MinDatasetShards, prefix+"min-dataset-shards", 1, "Minimum number of shards per dataset.")
37-
f.Uint64Var(&o.MaxDatasetShards, prefix+"max-dataset-shards", 32, "Maximum number of shards per dataset.")
38-
f.Uint64Var(&o.UnitSizeBytes, prefix+"unit-size-bytes", 64<<10, "Shards are allocated based on the utilisation of units per second. The option specifies the unit size in bytes.")
37+
f.Uint64Var(&o.MaxDatasetShards, prefix+"max-dataset-shards", 1<<10, "Maximum number of shards per dataset.")
38+
f.Uint64Var(&o.UnitSizeBytes, prefix+"unit-size-bytes", 128<<10, "Shards are allocated based on the utilisation of units per second. The option specifies the unit size in bytes.")
3939
f.DurationVar(&o.BurstWindow, prefix+"burst-window", 17*time.Minute, "Duration of the burst window. During this time, scale-outs are more aggressive.")
4040
f.DurationVar(&o.DecayWindow, prefix+"decay-window", 19*time.Minute, "Duration of the decay window. During this time, scale-ins are delayed.")
4141
}

pkg/experiment/distributor/placement/adaptive_placement/shard_allocator.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ func (a *shardAllocator) observe(usage uint64, now int64) int {
6969
// Reset multiplier if burst window has passed.
7070
a.multiplier = 1
7171
} else {
72-
// Increase multiplier on consecutive
73-
// scale-outs within burst window.
74-
a.multiplier *= 2
72+
// Increase multiplier on consecutive scale-outs within burst window.
73+
// Limiting the multiplier here allow us to not worry about overflows.
74+
if a.multiplier < 16 {
75+
a.multiplier *= 2
76+
}
7577
scaled := target + int(math.Ceil(float64(delta)*a.multiplier))
7678
target = min(2*target, scaled)
7779
}

pkg/experiment/distributor/placement/adaptive_placement/shard_allocator_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,22 @@ func Test_shard_allocator(t *testing.T) {
3838
require.Equal(t, test.want, a.observe(test.usage, test.now), fmt.Sprint(i))
3939
}
4040
}
41+
42+
func Test_shard_limit(t *testing.T) {
43+
a := &shardAllocator{
44+
unitSize: 128 << 10,
45+
min: 1,
46+
max: 10,
47+
burstWindow: 1e9 * 10,
48+
decayWindow: 1e9 * 10 * 5,
49+
}
50+
51+
var now int64
52+
var hi int
53+
for i := uint64(0); i < 100; i++ {
54+
old := hi
55+
hi = a.observe(2*a.unitSize*i, now)
56+
require.GreaterOrEqual(t, hi, old)
57+
now += 1e9 * 10
58+
}
59+
}

0 commit comments

Comments
 (0)