Skip to content

Commit 439c35a

Browse files
committed
sqlproxyccl/acl: use newer btree
Use `BtreeG` in the acl watcher code. Informs: #144504 Release note: None
1 parent b6ae107 commit 439c35a

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
github.com/golang/mock v1.6.0
3535
github.com/golang/protobuf v1.5.4
3636
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e
37-
github.com/google/btree v1.1.3 // indirect
37+
github.com/google/btree v1.1.3
3838
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7
3939
github.com/google/uuid v1.6.0 // indirect
4040
google.golang.org/api v0.114.0

pkg/ccl/sqlproxyccl/acl/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ go_library(
2121
"//pkg/util/syncutil",
2222
"//pkg/util/timeutil",
2323
"@com_github_cockroachdb_errors//:errors",
24+
"@com_github_google_btree//:btree",
2425
"@com_github_pires_go_proxyproto//:go-proxyproto",
2526
"@com_github_pires_go_proxyproto//tlvparse",
26-
"@com_github_raduberinde_btree//:btree",
2727
"@in_gopkg_yaml_v2//:yaml_v2",
2828
],
2929
)
@@ -50,7 +50,6 @@ go_test(
5050
"@com_github_cockroachdb_errors//:errors",
5151
"@com_github_pires_go_proxyproto//:go-proxyproto",
5252
"@com_github_pires_go_proxyproto//tlvparse",
53-
"@com_github_raduberinde_btree//:btree",
5453
"@com_github_stretchr_testify//require",
5554
"@in_gopkg_yaml_v2//:yaml_v2",
5655
],

pkg/ccl/sqlproxyccl/acl/watcher.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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(
235235
func (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()

pkg/ccl/sqlproxyccl/acl/watcher_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/RaduBerinde/btree" // TODO(#144504): switch to the newer btree
1514
"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/tenant"
1615
"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/tenantdirsvr"
1716
"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
@@ -403,8 +402,8 @@ func TestACLWatcher(t *testing.T) {
403402
require.Nil(t, err)
404403

405404
var l *listener
406-
watcher.listeners.Ascend(func(i btree.Item) bool {
407-
l = i.(*listener)
405+
watcher.listeners.Ascend(func(lst *listener) bool {
406+
l = lst
408407
return false
409408
})
410409
require.NotNil(t, l)

0 commit comments

Comments
 (0)