@@ -9,11 +9,11 @@ import (
99 "context"
1010 "time"
1111
12- "github.com/RaduBerinde/btree" // TODO(#144504): switch to the newer btree
1312 "github.com/cockroachdb/cockroach/pkg/util/log"
1413 "github.com/cockroachdb/cockroach/pkg/util/metric"
1514 "github.com/cockroachdb/cockroach/pkg/util/syncutil"
1615 "github.com/cockroachdb/cockroach/pkg/util/timeutil"
16+ "github.com/google/btree"
1717)
1818
1919// Watcher maintains a list of connections waiting for changes to the
@@ -33,7 +33,7 @@ type Watcher struct {
3333 options * aclOptions
3434
3535 // All of the listeners waiting for changes to the access control list.
36- listeners * btree.BTree
36+ listeners * btree.BTreeG [ * listener ]
3737
3838 // These control whether or not a connection is allowd based on it's
3939 // ConnectionTags.
@@ -128,7 +128,7 @@ func NewWatcher(ctx context.Context, opts ...Option) (*Watcher, error) {
128128 opt (options )
129129 }
130130 w := & Watcher {
131- listeners : btree .New ( 8 ),
131+ listeners : btree .NewG [ * listener ]( 8 , func ( a , b * listener ) bool { return a . id < b . id } ),
132132 options : options ,
133133 controllers : make ([]AccessController , 0 ),
134134 }
@@ -235,7 +235,7 @@ func (w *Watcher) addAccessController(
235235func (w * Watcher ) updateAccessController (
236236 ctx context.Context , index int , controller AccessController ,
237237) {
238- var copy * btree.BTree
238+ var copy * btree.BTreeG [ * listener ]
239239 var controllers []AccessController
240240 func () {
241241 w .mu .Lock ()
@@ -304,14 +304,10 @@ func (w *Watcher) removeListener(l *listener) {
304304 w .listeners .Delete (l )
305305}
306306
307- // Less implements the btree.Item interface for listener.
308- func (l * listener ) Less (than btree.Item ) bool {
309- return l .id < than .(* listener ).id
310- }
311-
312- func checkListeners (ctx context.Context , listeners * btree.BTree , controllers []AccessController ) {
313- listeners .Ascend (func (i btree.Item ) bool {
314- lst := i .(* listener )
307+ func checkListeners (
308+ ctx context.Context , listeners * btree.BTreeG [* listener ], controllers []AccessController ,
309+ ) {
310+ listeners .Ascend (func (lst * listener ) bool {
315311 if err := checkConnection (ctx , lst .connection , controllers ); err != nil {
316312 lst .mu .Lock ()
317313 defer lst .mu .Unlock ()
0 commit comments