From 0becb61b2cfd4e649aca044cce43ef8e6b9ff500 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:07:01 +0000 Subject: [PATCH] build(deps): bump github.com/dgraph-io/badger/v4 from 4.5.0 to 4.5.1 Bumps [github.com/dgraph-io/badger/v4](https://github.com/dgraph-io/badger) from 4.5.0 to 4.5.1. - [Release notes](https://github.com/dgraph-io/badger/releases) - [Changelog](https://github.com/dgraph-io/badger/blob/main/CHANGELOG.md) - [Commits](https://github.com/dgraph-io/badger/compare/v4.5.0...v4.5.1) --- updated-dependencies: - dependency-name: github.com/dgraph-io/badger/v4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 6 +- go.sum | 12 +- .../dgraph-io/badger/v4/CHANGELOG.md | 29 +++++ .../dgraph-io/badger/v4/dir_other.go | 109 ++++++++++++++++++ .../dgraph-io/badger/v4/dir_unix.go | 4 +- .../dgraph-io/badger/v4/y/file_dsync.go | 4 +- .../dgraph-io/ristretto/v2/CHANGELOG.md | 12 ++ .../dgraph-io/ristretto/v2/README.md | 17 +++ .../dgraph-io/ristretto/v2/cache.go | 17 +++ .../dgraph-io/ristretto/v2/policy.go | 5 + .../dgraph-io/ristretto/v2/store.go | 37 ++++-- .../github.com/dgraph-io/ristretto/v2/ttl.go | 13 ++- vendor/modules.txt | 6 +- 13 files changed, 243 insertions(+), 28 deletions(-) create mode 100644 vendor/github.com/dgraph-io/badger/v4/dir_other.go diff --git a/go.mod b/go.mod index 71179f8f51..4001bf3029 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 github.com/containerd/containerd v1.7.25 github.com/containerd/errdefs v1.0.0 - github.com/dgraph-io/badger/v4 v4.5.0 + github.com/dgraph-io/badger/v4 v4.5.1 github.com/fortytw2/leaktest v1.3.0 github.com/foxcpp/go-mockdns v1.1.0 github.com/fsnotify/fsnotify v1.8.0 @@ -61,12 +61,12 @@ require ( github.com/containerd/log v0.1.0 // indirect github.com/containerd/platforms v0.2.1 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect - github.com/dgraph-io/ristretto/v2 v2.0.0 // indirect + github.com/dgraph-io/ristretto/v2 v2.1.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/google/flatbuffers v24.3.25+incompatible // indirect + github.com/google/flatbuffers v24.12.23+incompatible // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/go.sum b/go.sum index 4ecebf19ff..a206f26ade 100644 --- a/go.sum +++ b/go.sum @@ -44,10 +44,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgraph-io/badger/v4 v4.5.0 h1:TeJE3I1pIWLBjYhIYCA1+uxrjWEoJXImFBMEBVSm16g= -github.com/dgraph-io/badger/v4 v4.5.0/go.mod h1:ysgYmIeG8dS/E8kwxT7xHyc7MkmwNYLRoYnFbr7387A= -github.com/dgraph-io/ristretto/v2 v2.0.0 h1:l0yiSOtlJvc0otkqyMaDNysg8E9/F/TYZwMbxscNOAQ= -github.com/dgraph-io/ristretto/v2 v2.0.0/go.mod h1:FVFokF2dRqXyPyeMnK1YDy8Fc6aTe0IKgbcd03CYeEk= +github.com/dgraph-io/badger/v4 v4.5.1 h1:7DCIXrQjo1LKmM96YD+hLVJ2EEsyyoWxJfpdd56HLps= +github.com/dgraph-io/badger/v4 v4.5.1/go.mod h1:qn3Be0j3TfV4kPbVoK0arXCD1/nr1ftth6sbL5jxdoA= +github.com/dgraph-io/ristretto/v2 v2.1.0 h1:59LjpOJLNDULHh8MC4UaegN52lC4JnO2dITsie/Pa8I= +github.com/dgraph-io/ristretto/v2 v2.1.0/go.mod h1:uejeqfYXpUomfse0+lO+13ATz4TypQYLJZzBSAemuB4= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo= @@ -95,8 +95,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI= -github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= +github.com/google/flatbuffers v24.12.23+incompatible h1:ubBKR94NR4pXUCY/MUsRVzd9umNW7ht7EG9hHfS9FX8= +github.com/google/flatbuffers v24.12.23+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= diff --git a/vendor/github.com/dgraph-io/badger/v4/CHANGELOG.md b/vendor/github.com/dgraph-io/badger/v4/CHANGELOG.md index 7fefac60df..2d1aadcc4f 100644 --- a/vendor/github.com/dgraph-io/badger/v4/CHANGELOG.md +++ b/vendor/github.com/dgraph-io/badger/v4/CHANGELOG.md @@ -3,6 +3,35 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [4.5.1] - 2025-01-21 + +- chore(deps): bump google.golang.org/protobuf from 1.36.2 to 1.36.3 in the patch group (#2150) +- bump github.com/dgraph-io/ristretto/v2 from 2.0.1 to 2.1.0 in the minor group (#2151) +- feat(info): print total size of listed keys (#2149) +- chore(deps): bump google.golang.org/protobuf from 1.36.1 to 1.36.2 in the patch group (#2146) +- chore(deps): bump the minor group with 2 updates (#2147) +- fix(info): print Total BloomFilter Size with totalBloomFilter instead of totalIndex (#2145) +- chore(deps): bump the minor group with 2 updates (#2141) +- chore(deps): bump google.golang.org/protobuf from 1.36.0 to 1.36.1 in the patch group (#2140) +- chore(deps): bump google.golang.org/protobuf from 1.35.2 to 1.36.0 in the minor group (#2139) +- chore(deps): bump github.com/dgraph-io/ristretto/v2 from 2.0.0 to 2.0.1 in the patch group (#2136) +- chore(deps): bump golang.org/x/net from 0.31.0 to 0.32.0 in the minor group (#2137) +- chore(deps): bump the minor group with 2 updates (#2135) +- docs: Add pagination explanation to docs (#2134) +- Fix build for GOARCH=wasm with GOOS=js or GOOS=wasip1 (#2048) + +**Full Changelog**: https://github.com/dgraph-io/badger/compare/v4.5.0...v4.5.1 + +## [4.5.0] - 2024-11-29 + +- fix the cd pipeline by @mangalaman93 in https://github.com/dgraph-io/badger/pull/2127 +- chore(deps): bump the minor group with 2 updates by @dependabot in https://github.com/dgraph-io/badger/pull/2128 +- chore(deps): bump github.com/stretchr/testify from 1.9.0 to 1.10.0 in the minor group by @dependabot in https://github.com/dgraph-io/badger/pull/2130 +- upgrade protobuf library by @shivaji-kharse in https://github.com/dgraph-io/badger/pull/2131 + +**Full Changelog**: https://github.com/dgraph-io/badger/compare/v4.4.0...v4.5.0 + + ## [4.4.0] - 2024-10-26 - retract v4.3.0 due to #2121 and #2113, upgrade to Go v1.23, use ristretto v2 in https://github.com/dgraph-io/badger/pull/2122 diff --git a/vendor/github.com/dgraph-io/badger/v4/dir_other.go b/vendor/github.com/dgraph-io/badger/v4/dir_other.go new file mode 100644 index 0000000000..d80490327b --- /dev/null +++ b/vendor/github.com/dgraph-io/badger/v4/dir_other.go @@ -0,0 +1,109 @@ +//go:build js || wasip1 +// +build js wasip1 + +/* + * Copyright 2017 Dgraph Labs, Inc. and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package badger + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/dgraph-io/badger/v4/y" +) + +// directoryLockGuard holds a lock on a directory and a pid file inside. The pid file isn't part +// of the locking mechanism, it's just advisory. +type directoryLockGuard struct { + // File handle on the directory, which we've flocked. + f *os.File + // The absolute path to our pid file. + path string + // Was this a shared lock for a read-only database? + readOnly bool +} + +// acquireDirectoryLock gets a lock on the directory (using flock). If +// this is not read-only, it will also write our pid to +// dirPath/pidFileName for convenience. +func acquireDirectoryLock(dirPath string, pidFileName string, readOnly bool) ( + *directoryLockGuard, error) { + // Convert to absolute path so that Release still works even if we do an unbalanced + // chdir in the meantime. + absPidFilePath, err := filepath.Abs(filepath.Join(dirPath, pidFileName)) + if err != nil { + return nil, y.Wrapf(err, "cannot get absolute path for pid lock file") + } + f, err := os.Open(dirPath) + if err != nil { + return nil, y.Wrapf(err, "cannot open directory %q", dirPath) + } + + // NOTE: Here is where we would normally call flock. + // This is not supported in js / wasm, so skip it. + + if !readOnly { + // Yes, we happily overwrite a pre-existing pid file. We're the + // only read-write badger process using this directory. + err = os.WriteFile(absPidFilePath, []byte(fmt.Sprintf("%d\n", os.Getpid())), 0666) + if err != nil { + f.Close() + return nil, y.Wrapf(err, + "Cannot write pid file %q", absPidFilePath) + } + } + + return &directoryLockGuard{f, absPidFilePath, readOnly}, nil +} + +// Release deletes the pid file and releases our lock on the directory. +func (guard *directoryLockGuard) release() error { + var err error + if !guard.readOnly { + // It's important that we remove the pid file first. + err = os.Remove(guard.path) + } + + if closeErr := guard.f.Close(); err == nil { + err = closeErr + } + guard.path = "" + guard.f = nil + + return err +} + +// openDir opens a directory for syncing. +func openDir(path string) (*os.File, error) { return os.Open(path) } + +// When you create or delete a file, you have to ensure the directory entry for the file is synced +// in order to guarantee the file is visible (if the system crashes). (See the man page for fsync, +// or see https://github.com/coreos/etcd/issues/6368 for an example.) +func syncDir(dir string) error { + f, err := openDir(dir) + if err != nil { + return y.Wrapf(err, "While opening directory: %s.", dir) + } + + err = f.Sync() + closeErr := f.Close() + if err != nil { + return y.Wrapf(err, "While syncing directory: %s.", dir) + } + return y.Wrapf(closeErr, "While closing directory: %s.", dir) +} diff --git a/vendor/github.com/dgraph-io/badger/v4/dir_unix.go b/vendor/github.com/dgraph-io/badger/v4/dir_unix.go index ecaa5ced78..d7a7199e9e 100644 --- a/vendor/github.com/dgraph-io/badger/v4/dir_unix.go +++ b/vendor/github.com/dgraph-io/badger/v4/dir_unix.go @@ -1,5 +1,5 @@ -//go:build !windows && !plan9 -// +build !windows,!plan9 +//go:build !windows && !plan9 && !js && !wasip1 +// +build !windows,!plan9,!js,!wasip1 /* * Copyright 2017 Dgraph Labs, Inc. and Contributors diff --git a/vendor/github.com/dgraph-io/badger/v4/y/file_dsync.go b/vendor/github.com/dgraph-io/badger/v4/y/file_dsync.go index 1e171733eb..3fb6537caa 100644 --- a/vendor/github.com/dgraph-io/badger/v4/y/file_dsync.go +++ b/vendor/github.com/dgraph-io/badger/v4/y/file_dsync.go @@ -1,5 +1,5 @@ -//go:build !dragonfly && !freebsd && !windows && !plan9 -// +build !dragonfly,!freebsd,!windows,!plan9 +//go:build !dragonfly && !freebsd && !windows && !plan9 && !js && !wasip1 +// +build !dragonfly,!freebsd,!windows,!plan9,!js,!wasip1 /* * Copyright 2017 Dgraph Labs, Inc. and Contributors diff --git a/vendor/github.com/dgraph-io/ristretto/v2/CHANGELOG.md b/vendor/github.com/dgraph-io/ristretto/v2/CHANGELOG.md index d004b9bb4c..57357ecd9c 100644 --- a/vendor/github.com/dgraph-io/ristretto/v2/CHANGELOG.md +++ b/vendor/github.com/dgraph-io/ristretto/v2/CHANGELOG.md @@ -5,6 +5,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project will adhere to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) starting v1.0.0. +## [v2.0.1] - 2024-12-11 + +### Fixed + +- Wait for goroutines to finish (#423) +- Bump golang.org/x/sys from 0.27.0 to 0.28.0 in the minor group (#421) +- Bump github.com/stretchr/testify from 1.9.0 to 1.10.0 in the minor group (#420) +- Bump golang.org/x/sys from 0.26.0 to 0.27.0 in the minor group (#419) + +**Full Changelog**: https://github.com/dgraph-io/ristretto/compare/v2.0.0...v2.0.1 + + ## [v2.0.0] - 2024-11-11 ### Breaking diff --git a/vendor/github.com/dgraph-io/ristretto/v2/README.md b/vendor/github.com/dgraph-io/ristretto/v2/README.md index 9b7b72d7e9..9edd967b31 100644 --- a/vendor/github.com/dgraph-io/ristretto/v2/README.md +++ b/vendor/github.com/dgraph-io/ristretto/v2/README.md @@ -28,6 +28,23 @@ The motivation to build Ristretto comes from the need for a contention-free cach Ristretto is production-ready. See [Projects using Ristretto](#projects-using-ristretto). +## Getting Started + +### Installing +To start using Ristretto, install Go 1.21 or above. Ristretto needs go modules. From your project, run the following command + +```sh +$ go get github.com/dgraph-io/ristretto/v2 +``` +This will retrieve the library. + +#### Choosing a version + +Following these rules: + +- v1.x.x is the first version used in most programs with Ristretto dependencies. +- v2.x.x is the new version with support for generics, for which it has a slightly different interface. +This version is designed to solve compatibility problems of programs using the old version of Ristretto. If you start writing a new program, it is recommended to use this version. ## Usage diff --git a/vendor/github.com/dgraph-io/ristretto/v2/cache.go b/vendor/github.com/dgraph-io/ristretto/v2/cache.go index 0f6d416335..e02c969909 100644 --- a/vendor/github.com/dgraph-io/ristretto/v2/cache.go +++ b/vendor/github.com/dgraph-io/ristretto/v2/cache.go @@ -72,6 +72,7 @@ type Cache[K Key, V any] struct { keyToHash func(K) (uint64, uint64) // stop is used to stop the processItems goroutine. stop chan struct{} + done chan struct{} // indicates whether cache is closed. isClosed atomic.Bool // cost calculates cost from a value. @@ -147,6 +148,16 @@ type Config[K Key, V any] struct { // as well as on rejection of the value. OnExit func(val V) + // ShouldUpdate is called when a value already exists in cache and is being updated. + // If ShouldUpdate returns true, the cache continues with the update (Set). If the + // function returns false, no changes are made in the cache. If the value doesn't + // already exist, the cache continue with setting that value for the given key. + // + // In this function, you can check whether the new value is valid. For example, if + // your value has timestamp assosicated with it, you could check whether the new + // value has the latest timestamp, preventing you from setting an older value. + ShouldUpdate func(cur, prev V) bool + // KeyToHash function is used to customize the key hashing algorithm. // Each key will be hashed using the provided function. If keyToHash value // is not set, the default keyToHash function is used. @@ -227,10 +238,12 @@ func NewCache[K Key, V any](config *Config[K, V]) (*Cache[K, V], error) { setBuf: make(chan *Item[V], setBufSize), keyToHash: config.KeyToHash, stop: make(chan struct{}), + done: make(chan struct{}), cost: config.Cost, ignoreInternalCost: config.IgnoreInternalCost, cleanupTicker: time.NewTicker(time.Duration(config.TtlTickerDurationInSec) * time.Second / 2), } + cache.storedItems.SetShouldUpdateFn(config.ShouldUpdate) cache.onExit = func(val V) { if config.OnExit != nil { config.OnExit(val) @@ -422,7 +435,9 @@ func (c *Cache[K, V]) Close() { // Block until processItems goroutine is returned. c.stop <- struct{}{} + <-c.done close(c.stop) + close(c.done) close(c.setBuf) c.cachePolicy.Close() c.cleanupTicker.Stop() @@ -438,6 +453,7 @@ func (c *Cache[K, V]) Clear() { } // Block until processItems goroutine is returned. c.stop <- struct{}{} + <-c.done // Clear out the setBuf channel. loop: @@ -556,6 +572,7 @@ func (c *Cache[K, V]) processItems() { case <-c.cleanupTicker.C: c.storedItems.Cleanup(c.cachePolicy, onEvict) case <-c.stop: + c.done <- struct{}{} return } } diff --git a/vendor/github.com/dgraph-io/ristretto/v2/policy.go b/vendor/github.com/dgraph-io/ristretto/v2/policy.go index d4e340ad42..33ca3f2d04 100644 --- a/vendor/github.com/dgraph-io/ristretto/v2/policy.go +++ b/vendor/github.com/dgraph-io/ristretto/v2/policy.go @@ -40,6 +40,7 @@ type defaultPolicy[V any] struct { evict *sampledLFU itemsCh chan []uint64 stop chan struct{} + done chan struct{} isClosed bool metrics *Metrics } @@ -50,6 +51,7 @@ func newDefaultPolicy[V any](numCounters, maxCost int64) *defaultPolicy[V] { evict: newSampledLFU(maxCost), itemsCh: make(chan []uint64, 3), stop: make(chan struct{}), + done: make(chan struct{}), } go p.processItems() return p @@ -73,6 +75,7 @@ func (p *defaultPolicy[V]) processItems() { p.admit.Push(items) p.Unlock() case <-p.stop: + p.done <- struct{}{} return } } @@ -226,7 +229,9 @@ func (p *defaultPolicy[V]) Close() { // Block until the p.processItems goroutine returns. p.stop <- struct{}{} + <-p.done close(p.stop) + close(p.done) close(p.itemsCh) p.isClosed = true } diff --git a/vendor/github.com/dgraph-io/ristretto/v2/store.go b/vendor/github.com/dgraph-io/ristretto/v2/store.go index dfcfaa8db3..1af7b3ed99 100644 --- a/vendor/github.com/dgraph-io/ristretto/v2/store.go +++ b/vendor/github.com/dgraph-io/ristretto/v2/store.go @@ -21,6 +21,8 @@ import ( "time" ) +type updateFn[V any] func(cur, prev V) bool + // TODO: Do we need this to be a separate struct from Item? type storeItem[V any] struct { key uint64 @@ -53,6 +55,7 @@ type store[V any] interface { Cleanup(policy *defaultPolicy[V], onEvict func(item *Item[V])) // Clear clears all contents of the store. Clear(onEvict func(item *Item[V])) + SetShouldUpdateFn(f updateFn[V]) } // newStore returns the default store implementation. @@ -78,6 +81,12 @@ func newShardedMap[V any]() *shardedMap[V] { return sm } +func (m *shardedMap[V]) SetShouldUpdateFn(f updateFn[V]) { + for i := range m.shards { + m.shards[i].setShouldUpdateFn(f) + } +} + func (sm *shardedMap[V]) Get(key, conflict uint64) (V, bool) { return sm.shards[key%numShards].get(key, conflict) } @@ -116,17 +125,25 @@ func (sm *shardedMap[V]) Clear(onEvict func(item *Item[V])) { type lockedMap[V any] struct { sync.RWMutex - data map[uint64]storeItem[V] - em *expirationMap[V] + data map[uint64]storeItem[V] + em *expirationMap[V] + shouldUpdate updateFn[V] } func newLockedMap[V any](em *expirationMap[V]) *lockedMap[V] { return &lockedMap[V]{ data: make(map[uint64]storeItem[V]), em: em, + shouldUpdate: func(cur, prev V) bool { + return true + }, } } +func (m *lockedMap[V]) setShouldUpdateFn(f updateFn[V]) { + m.shouldUpdate = f +} + func (m *lockedMap[V]) get(key, conflict uint64) (V, bool) { m.RLock() item, ok := m.data[key] @@ -167,6 +184,9 @@ func (m *lockedMap[V]) Set(i *Item[V]) { if i.Conflict != 0 && (i.Conflict != item.conflict) { return } + if m.shouldUpdate != nil && !m.shouldUpdate(i.Value, item.value) { + return + } m.em.update(i.Key, i.Conflict, item.expiration, i.Expiration) } else { // The value is not in the map already. There's no need to return anything. @@ -184,13 +204,12 @@ func (m *lockedMap[V]) Set(i *Item[V]) { func (m *lockedMap[V]) Del(key, conflict uint64) (uint64, V) { m.Lock() + defer m.Unlock() item, ok := m.data[key] if !ok { - m.Unlock() return 0, zeroValue[V]() } if conflict != 0 && (conflict != item.conflict) { - m.Unlock() return 0, zeroValue[V]() } @@ -199,21 +218,22 @@ func (m *lockedMap[V]) Del(key, conflict uint64) (uint64, V) { } delete(m.data, key) - m.Unlock() return item.conflict, item.value } func (m *lockedMap[V]) Update(newItem *Item[V]) (V, bool) { m.Lock() + defer m.Unlock() item, ok := m.data[newItem.Key] if !ok { - m.Unlock() return zeroValue[V](), false } if newItem.Conflict != 0 && (newItem.Conflict != item.conflict) { - m.Unlock() return zeroValue[V](), false } + if m.shouldUpdate != nil && !m.shouldUpdate(newItem.Value, item.value) { + return item.value, false + } m.em.update(newItem.Key, newItem.Conflict, item.expiration, newItem.Expiration) m.data[newItem.Key] = storeItem[V]{ @@ -223,12 +243,12 @@ func (m *lockedMap[V]) Update(newItem *Item[V]) (V, bool) { expiration: newItem.Expiration, } - m.Unlock() return item.value, true } func (m *lockedMap[V]) Clear(onEvict func(item *Item[V])) { m.Lock() + defer m.Unlock() i := &Item[V]{} if onEvict != nil { for _, si := range m.data { @@ -239,5 +259,4 @@ func (m *lockedMap[V]) Clear(onEvict func(item *Item[V])) { } } m.data = make(map[uint64]storeItem[V]) - m.Unlock() } diff --git a/vendor/github.com/dgraph-io/ristretto/v2/ttl.go b/vendor/github.com/dgraph-io/ristretto/v2/ttl.go index ccb0d7cb51..350f706d8a 100644 --- a/vendor/github.com/dgraph-io/ristretto/v2/ttl.go +++ b/vendor/github.com/dgraph-io/ristretto/v2/ttl.go @@ -121,9 +121,9 @@ func (m *expirationMap[_]) del(key uint64, expiration time.Time) { // cleanup removes all the items in the bucket that was just completed. It deletes // those items from the store, and calls the onEvict function on those items. // This function is meant to be called periodically. -func (m *expirationMap[V]) cleanup(store store[V], policy *defaultPolicy[V], onEvict func(item *Item[V])) { +func (m *expirationMap[V]) cleanup(store store[V], policy *defaultPolicy[V], onEvict func(item *Item[V])) int { if m == nil { - return + return 0 } m.Lock() @@ -133,7 +133,10 @@ func (m *expirationMap[V]) cleanup(store store[V], policy *defaultPolicy[V], onE // (but not including) the last one that was cleaned up var buckets []bucket for bucketNum := m.lastCleanedBucketNum + 1; bucketNum <= currentBucketNum; bucketNum++ { - buckets = append(buckets, m.buckets[bucketNum]) + // With an empty bucket, we don't need to add it to the Clean list + if b := m.buckets[bucketNum]; b != nil { + buckets = append(buckets, b) + } delete(m.buckets, bucketNum) } m.lastCleanedBucketNum = currentBucketNum @@ -161,6 +164,10 @@ func (m *expirationMap[V]) cleanup(store store[V], policy *defaultPolicy[V], onE } } } + + cleanedBucketsCount := len(buckets) + + return cleanedBucketsCount } // clear clears the expirationMap, the caller is responsible for properly diff --git a/vendor/modules.txt b/vendor/modules.txt index f159209271..423970bb85 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -59,7 +59,7 @@ github.com/containerd/platforms # github.com/cpuguy83/go-md2man/v2 v2.0.4 ## explicit; go 1.11 github.com/cpuguy83/go-md2man/v2/md2man -# github.com/dgraph-io/badger/v4 v4.5.0 +# github.com/dgraph-io/badger/v4 v4.5.1 ## explicit; go 1.21 github.com/dgraph-io/badger/v4 github.com/dgraph-io/badger/v4/fb @@ -69,7 +69,7 @@ github.com/dgraph-io/badger/v4/skl github.com/dgraph-io/badger/v4/table github.com/dgraph-io/badger/v4/trie github.com/dgraph-io/badger/v4/y -# github.com/dgraph-io/ristretto/v2 v2.0.0 +# github.com/dgraph-io/ristretto/v2 v2.1.0 ## explicit; go 1.21 github.com/dgraph-io/ristretto/v2 github.com/dgraph-io/ristretto/v2/z @@ -117,7 +117,7 @@ github.com/golang/groupcache/lru ## explicit; go 1.17 github.com/golang/protobuf/jsonpb github.com/golang/protobuf/proto -# github.com/google/flatbuffers v24.3.25+incompatible +# github.com/google/flatbuffers v24.12.23+incompatible ## explicit github.com/google/flatbuffers/go # github.com/google/go-cmp v0.6.0