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

Fix: interval tree complete implemention based on red-black tree #10881

Closed
wants to merge 8 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ vendor/**/*
vendor/**/*_test.go

*.bak
.vscode/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

4 changes: 2 additions & 2 deletions auth/range_perm_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func getMergedPerms(lg *zap.Logger, tx backend.BatchTx, userName string) *unifie
return nil
}

readPerms := &adt.IntervalTree{}
writePerms := &adt.IntervalTree{}
readPerms := adt.NewIntervalTree()
writePerms := adt.NewIntervalTree()

for _, roleName := range user.Roles {
role := getRole(tx, roleName)
Expand Down
4 changes: 2 additions & 2 deletions auth/range_perm_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestRangePermission(t *testing.T) {
}

for i, tt := range tests {
readPerms := &adt.IntervalTree{}
readPerms := adt.NewIntervalTree()
for _, p := range tt.perms {
readPerms.Insert(p, struct{}{})
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestKeyPermission(t *testing.T) {
}

for i, tt := range tests {
readPerms := &adt.IntervalTree{}
readPerms := adt.NewIntervalTree()
for _, p := range tt.perms {
readPerms.Insert(p, struct{}{})
}
Expand Down
4 changes: 2 additions & 2 deletions etcdserver/api/v3rpc/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ func checkTxnRequest(r *pb.TxnRequest, maxTxnOps int) error {
// checkIntervals tests whether puts and deletes overlap for a list of ops. If
// there is an overlap, returns an error. If no overlap, return put and delete
// sets for recursive evaluation.
func checkIntervals(reqs []*pb.RequestOp) (map[string]struct{}, adt.IntervalTree, error) {
var dels adt.IntervalTree
func checkIntervals(reqs []*pb.RequestOp) (map[string]struct{}, *adt.IntervalTree, error) {
dels := adt.NewIntervalTree()

// collect deletes from this level; build first to check lower level overlapped puts
for _, req := range reqs {
Expand Down
3 changes: 2 additions & 1 deletion mvcc/watcher_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,15 @@ type watcherGroup struct {
// keyWatchers has the watchers that watch on a single key
keyWatchers watcherSetByKey
// ranges has the watchers that watch a range; it is sorted by interval
ranges adt.IntervalTree
ranges *adt.IntervalTree
// watchers is the set of all watchers
watchers watcherSet
}

func newWatcherGroup() watcherGroup {
return watcherGroup{
keyWatchers: make(watcherSetByKey),
ranges: adt.NewIntervalTree(),
watchers: make(watcherSet),
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/adt/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func Example() {
ivt := &adt.IntervalTree{}
ivt := adt.NewIntervalTree()

ivt.Insert(adt.NewInt64Interval(1, 3), 123)
ivt.Insert(adt.NewInt64Interval(9, 13), 456)
Expand Down
Loading