Skip to content

Commit 036224d

Browse files
authored
Update deps (#224)
- Update cache - Upgrade to go-libipni v0.5.29 - Upgrade to go-libp2p v0.41.0 - Upgrade to pebble v1.1.4 - fix formatting - Calling flush is not needed before calling close
1 parent ba31443 commit 036224d

File tree

5 files changed

+134
-177
lines changed

5 files changed

+134
-177
lines changed

cache/radixcache/radixcache.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ var log = logging.Logger("indexer-core/cache")
2121
// radixCache is a rotatable cache with value deduplication.
2222
type radixCache struct {
2323
// multihash -> indexer.Value
24-
current *radixtree.Tree
25-
previous *radixtree.Tree
24+
current *radixtree.Tree[[]*indexer.Value]
25+
previous *radixtree.Tree[[]*indexer.Value]
2626

2727
// IndexEntery interning
28-
curEnts *radixtree.Tree
29-
prevEnts *radixtree.Tree
28+
curEnts *radixtree.Tree[*indexer.Value]
29+
prevEnts *radixtree.Tree[*indexer.Value]
3030

3131
mutex sync.Mutex
3232
evictions int
@@ -36,8 +36,8 @@ type radixCache struct {
3636
// New creates a new radixCache instance.
3737
func New(maxSize int) *radixCache {
3838
return &radixCache{
39-
current: radixtree.New(),
40-
curEnts: radixtree.New(),
39+
current: radixtree.New[[]*indexer.Value](),
40+
curEnts: radixtree.New[*indexer.Value](),
4141
rotateSize: maxSize >> 1,
4242
}
4343
}
@@ -107,16 +107,15 @@ keysLoop:
107107
if c.curEnts.Len() > (c.rotateSize << 1) {
108108
c.rotate()
109109
// Remove all non-indexed cache entries.
110-
c.previous.Walk("", func(k string, v interface{}) bool {
111-
values := v.([]*indexer.Value)
110+
for _, values := range c.previous.Iter() {
112111
for _, val := range values {
113112
_, _, found := c.findInternValue(val)
114113
if !found {
115114
panic("cannot find interned value for cached index")
116115
}
117116
}
118-
return false
119-
})
117+
}
118+
120119
c.current = c.previous
121120
c.previous = nil
122121
c.prevEnts = nil
@@ -173,10 +172,9 @@ func (c *radixCache) RemoveProvider(providerID peer.ID) int {
173172

174173
var count int
175174
var deletes []string
176-
var tree *radixtree.Tree
175+
var tree *radixtree.Tree[[]*indexer.Value]
177176

178-
walkFunc := func(k string, v interface{}) bool {
179-
values := v.([]*indexer.Value)
177+
walkFunc := func(k string, values []*indexer.Value) {
180178
var vrm int
181179
for i := 0; i < len(values); {
182180
if providerID == values[i].ProviderID {
@@ -198,14 +196,15 @@ func (c *radixCache) RemoveProvider(providerID peer.ID) int {
198196
tree.Put(k, values)
199197
}
200198
count += vrm
201-
return false
202199
}
203200

204201
hasCurValues := removeProviderInterns(c.curEnts, providerID)
205202
if hasCurValues {
206203
// Remove provider values only if there were any provider interns.
207204
tree = c.current
208-
c.current.Walk("", walkFunc)
205+
for k, v := range c.current.Iter() {
206+
walkFunc(k, v)
207+
}
209208
for _, k := range deletes {
210209
c.current.Delete(k)
211210
}
@@ -221,7 +220,9 @@ func (c *radixCache) RemoveProvider(providerID peer.ID) int {
221220
if hasPrevValues || hasCurValues {
222221
deletes = deletes[:0]
223222
tree = c.previous
224-
c.previous.Walk("", walkFunc)
223+
for k, v := range c.previous.Iter() {
224+
walkFunc(k, v)
225+
}
225226
for _, k := range deletes {
226227
c.previous.Delete(k)
227228
}
@@ -245,10 +246,9 @@ func (c *radixCache) RemoveProviderContext(providerID peer.ID, contextID []byte)
245246

246247
var deletes []string
247248
var count int
248-
var tree *radixtree.Tree
249+
var tree *radixtree.Tree[[]*indexer.Value]
249250

250-
walkFunc := func(k string, v interface{}) bool {
251-
values := v.([]*indexer.Value)
251+
walkFunc := func(k string, values []*indexer.Value) {
252252
var vrm int
253253
for i := 0; i < len(values); {
254254
if values[i] == val {
@@ -270,18 +270,21 @@ func (c *radixCache) RemoveProviderContext(providerID peer.ID, contextID []byte)
270270
tree.Put(k, values)
271271
}
272272
count += vrm
273-
return false
274273
}
275274

276275
tree = c.current
277-
c.current.Walk("", walkFunc)
276+
for k, v := range c.current.Iter() {
277+
walkFunc(k, v)
278+
}
278279
for _, k := range deletes {
279280
c.current.Delete(k)
280281
}
281282
if c.previous != nil {
282283
deletes = deletes[:0]
283284
tree = c.previous
284-
c.previous.Walk("", walkFunc)
285+
for k, v := range c.previous.Iter() {
286+
walkFunc(k, v)
287+
}
285288
for _, k := range deletes {
286289
c.previous.Delete(k)
287290
}
@@ -329,22 +332,21 @@ func (c *radixCache) Stats() cache.Stats {
329332

330333
func (c *radixCache) get(k string) ([]*indexer.Value, bool) {
331334
// Search current cache.
332-
v, found := c.current.Get(k)
335+
values, found := c.current.Get(k)
333336
if !found {
334337
if c.previous == nil {
335338
return nil, false
336339
}
337340

338341
// Search previous if not found in current.
339-
v, found = c.previous.Get(k)
342+
values, found = c.previous.Get(k)
340343
if !found {
341344
return nil, false
342345
}
343346

344347
// Pull the interned values for these values forward from the previous
345348
// cache to reuse the interned values instead of allocating them again
346349
// in the current cache.
347-
values := v.([]*indexer.Value)
348350
for i, val := range values {
349351
values[i] = c.internValue(val, false, true)
350352
}
@@ -353,16 +355,16 @@ func (c *radixCache) get(k string) ([]*indexer.Value, bool) {
353355
c.current.Put(k, values)
354356
c.previous.Delete(k)
355357
}
356-
return v.([]*indexer.Value), true
358+
return values, true
357359
}
358360

359361
func (c *radixCache) rotate() {
360362
if c.previous != nil {
361363
c.evictions += c.previous.Len()
362364
log.Infow("Rotating cache", "evictions", c.previous.Len())
363365
}
364-
c.previous, c.current = c.current, radixtree.New()
365-
c.prevEnts, c.curEnts = c.curEnts, radixtree.New()
366+
c.previous, c.current = c.current, radixtree.New[[]*indexer.Value]()
367+
c.prevEnts, c.curEnts = c.curEnts, radixtree.New[*indexer.Value]()
366368
}
367369

368370
// internValue stores a single copy of a Value under a key composed of
@@ -411,7 +413,7 @@ func (c *radixCache) findInternValue(value *indexer.Value) (string, *indexer.Val
411413
v, found := c.curEnts.Get(k)
412414
if found {
413415
// Found existing interned value.
414-
return k, v.(*indexer.Value), true
416+
return k, v, true
415417
}
416418

417419
if c.prevEnts != nil {
@@ -420,21 +422,20 @@ func (c *radixCache) findInternValue(value *indexer.Value) (string, *indexer.Val
420422
// Pull interned value forward from previous cache.
421423
c.curEnts.Put(k, v)
422424
c.prevEnts.Delete(k)
423-
return k, v.(*indexer.Value), true
425+
return k, v, true
424426
}
425427
}
426428

427429
return k, nil, false
428430
}
429431

430-
func removeIndex(tree *radixtree.Tree, k string, value *indexer.Value) bool {
432+
func removeIndex(tree *radixtree.Tree[[]*indexer.Value], k string, value *indexer.Value) bool {
431433
// Get from current cache.
432-
v, found := tree.Get(k)
434+
values, found := tree.Get(k)
433435
if !found {
434436
return false
435437
}
436438

437-
values := v.([]*indexer.Value)
438439
for i, v := range values {
439440
if v == value || v.Match(*value) {
440441
if len(values) == 1 {
@@ -451,12 +452,11 @@ func removeIndex(tree *radixtree.Tree, k string, value *indexer.Value) bool {
451452
return false
452453
}
453454

454-
func removeProviderInterns(tree *radixtree.Tree, providerID peer.ID) bool {
455+
func removeProviderInterns(tree *radixtree.Tree[*indexer.Value], providerID peer.ID) bool {
455456
var deletes []string
456-
tree.Walk(string(providerID), func(k string, v interface{}) bool {
457+
for k := range tree.IterAt(string(providerID)) {
457458
deletes = append(deletes, k)
458-
return false
459-
})
459+
}
460460
for _, k := range deletes {
461461
tree.Delete(k)
462462
}

go.mod

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,63 @@
11
module github.com/ipni/go-indexer-core
22

3-
go 1.22.0
4-
5-
toolchain go1.22.8
3+
go 1.23.6
64

75
require (
8-
// Note, cockroachdb/pebble has no tagged release. Instead, it uses branches.
9-
// The version below is from: https://github.com/cockroachdb/pebble/tree/crl-release-22.1
10-
// To update to latest, run: go get github.com/cockroachdb/[email protected]
11-
github.com/cockroachdb/pebble v0.0.0-20240822181941-1b4021bcfe22
12-
github.com/gammazero/radixtree v0.3.1
13-
github.com/ipfs/go-cid v0.4.1
6+
github.com/cockroachdb/pebble v1.1.4
7+
github.com/gammazero/radixtree v0.4.0
8+
github.com/ipfs/go-cid v0.5.0
149
github.com/ipfs/go-log/v2 v2.5.1
15-
github.com/ipfs/go-test v0.0.4
16-
github.com/ipni/go-libipni v0.5.27
17-
github.com/libp2p/go-libp2p v0.38.1
10+
github.com/ipfs/go-test v0.2.1
11+
github.com/ipni/go-libipni v0.5.29
12+
github.com/libp2p/go-libp2p v0.41.0
1813
github.com/mr-tron/base58 v1.2.0
1914
github.com/multiformats/go-multihash v0.2.3
2015
github.com/multiformats/go-varint v0.0.7
2116
go.opencensus.io v0.24.0
22-
lukechampine.com/blake3 v1.3.0
17+
lukechampine.com/blake3 v1.4.0
2318
)
2419

2520
require (
2621
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
2722
github.com/beorn7/perks v1.0.1 // indirect
2823
github.com/cespare/xxhash/v2 v2.3.0 // indirect
24+
github.com/cockroachdb/datadriven v1.0.3-0.20240530155848-7682d40af056 // indirect
2925
github.com/cockroachdb/errors v1.11.3 // indirect
3026
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
3127
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
3228
github.com/cockroachdb/redact v1.1.5 // indirect
33-
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964 // indirect
3429
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
35-
github.com/davecgh/go-spew v1.1.1 // indirect
36-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
30+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
3731
github.com/getsentry/sentry-go v0.27.0 // indirect
3832
github.com/gogo/protobuf v1.3.2 // indirect
3933
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
40-
github.com/ipfs/go-block-format v0.1.2 // indirect
34+
github.com/ipfs/go-block-format v0.2.0 // indirect
4135
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
42-
github.com/klauspost/compress v1.17.11 // indirect
43-
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
36+
github.com/klauspost/compress v1.18.0 // indirect
37+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
4438
github.com/kr/pretty v0.3.1 // indirect
4539
github.com/kr/text v0.2.0 // indirect
4640
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
4741
github.com/mattn/go-isatty v0.0.20 // indirect
4842
github.com/minio/sha256-simd v1.0.1 // indirect
4943
github.com/multiformats/go-base32 v0.1.0 // indirect
5044
github.com/multiformats/go-base36 v0.2.0 // indirect
51-
github.com/multiformats/go-multiaddr v0.14.0 // indirect
45+
github.com/multiformats/go-multiaddr v0.15.0 // indirect
5246
github.com/multiformats/go-multibase v0.2.0 // indirect
5347
github.com/multiformats/go-multicodec v0.9.0 // indirect
5448
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5549
github.com/pkg/errors v0.9.1 // indirect
56-
github.com/pmezard/go-difflib v1.0.0 // indirect
57-
github.com/prometheus/client_golang v1.20.5 // indirect
50+
github.com/prometheus/client_golang v1.21.0 // indirect
5851
github.com/prometheus/client_model v0.6.1 // indirect
59-
github.com/prometheus/common v0.61.0 // indirect
52+
github.com/prometheus/common v0.62.0 // indirect
6053
github.com/prometheus/procfs v0.15.1 // indirect
6154
github.com/rogpeppe/go-internal v1.10.0 // indirect
6255
github.com/spaolacci/murmur3 v1.1.0 // indirect
63-
github.com/stretchr/testify v1.10.0 // indirect
6456
go.uber.org/multierr v1.11.0 // indirect
6557
go.uber.org/zap v1.27.0 // indirect
66-
golang.org/x/crypto v0.31.0 // indirect
67-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
68-
golang.org/x/sys v0.28.0 // indirect
69-
golang.org/x/text v0.21.0 // indirect
70-
google.golang.org/protobuf v1.36.0 // indirect
71-
gopkg.in/yaml.v3 v3.0.1 // indirect
58+
golang.org/x/crypto v0.36.0 // indirect
59+
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect
60+
golang.org/x/sys v0.31.0 // indirect
61+
golang.org/x/text v0.23.0 // indirect
62+
google.golang.org/protobuf v1.36.5 // indirect
7263
)

0 commit comments

Comments
 (0)