Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admission: fix overflow bug in ioLoadListener #69567

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/util/admission/granter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,9 @@ func (io *ioLoadListener) pebbleMetricsTick(m pebble.Metrics) {
// 1s.
func (io *ioLoadListener) allocateTokensTick() {
var toAllocate int64
if io.totalTokens == unlimitedTokens {
// unlimitedTokens==MaxInt64, so avoid overflow in the rounding up
// calculation.
if io.totalTokens >= unlimitedTokens-(adjustmentInterval-1) {
toAllocate = io.totalTokens / adjustmentInterval
} else {
// Round up so that we don't accumulate tokens to give in a burst on the
Expand Down
21 changes: 21 additions & 0 deletions pkg/util/admission/granter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package admission
import (
"context"
"fmt"
"math"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -376,6 +377,26 @@ func TestIOLoadListener(t *testing.T) {
})
}

func TestIOLoadListenerOverflow(t *testing.T) {
req := &testRequesterForIOLL{}
kvGranter := &testGranterWithIOTokens{}
st := cluster.MakeTestingClusterSettings()
ioll := ioLoadListener{
settings: st,
kvRequester: req,
}
ioll.mu.Mutex = &syncutil.Mutex{}
ioll.mu.kvGranter = kvGranter
for i := int64(0); i < adjustmentInterval; i++ {
// Override the totalTokens manually to trigger the overflow bug.
ioll.totalTokens = math.MaxInt64 - i
ioll.tokensAllocated = 0
for j := 0; j < adjustmentInterval; j++ {
ioll.allocateTokensTick()
}
}
}

// TODO(sumeer):
// - Test metrics
// - Test GrantCoordinator with multi-tenant configurations