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

asim: fix uniqueness invariant on adding ranges #81144

Merged
merged 1 commit into from
May 17, 2022
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
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/asim/asim.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (rm *RangeMap) AddRange(minKey string) *Range {
rm.ranges.AscendGreaterOrEqual(r, func(i btree.Item) bool {
// The min key already exists in the range map, we cannot return a new
// range. Instead crash here as this is a bug.
if i.Less(r) {
if !r.Less(i) {
panic(fmt.Sprintf("Range with minKey: %s already exists within the range map, unable to add new range", r.MinKey))
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/kv/kvserver/asim/asim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func TestRangeMap(t *testing.T) {
require.Equal(t, r1.MinKey, m.GetRange("c").MinKey)
require.Equal(t, r2.MinKey, m.GetRange("g").MinKey)
require.Equal(t, r3.MinKey, m.GetRange("z").MinKey)

require.Panics(t, func() { m.AddRange("b") }, "Adding a range with the same minKey twice should panic")
require.Panics(t, func() { m.AddRange("f") }, "Adding a range with the same minKey twice should panic")
require.Panics(t, func() { m.AddRange("x") }, "Adding a range with the same minKey twice should panic")
}

func TestAddReplica(t *testing.T) {
Expand Down