From 50176f6f6bfa5962dd88095423d2d3d17c73b0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 15 Nov 2024 12:34:38 +0100 Subject: [PATCH] fix node cache ttl updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../unreleased/fix-node-cache-ttl-updates.md | 5 +++++ go.mod | 2 +- go.sum | 4 ++-- .../go-micro.dev/v4/registry/cache/cache.go | 19 ++++++++++++------- vendor/modules.txt | 4 ++-- 5 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 changelog/unreleased/fix-node-cache-ttl-updates.md diff --git a/changelog/unreleased/fix-node-cache-ttl-updates.md b/changelog/unreleased/fix-node-cache-ttl-updates.md new file mode 100644 index 000000000..433e1554d --- /dev/null +++ b/changelog/unreleased/fix-node-cache-ttl-updates.md @@ -0,0 +1,5 @@ +Bugfix: Fix node cache ttl updates + +We now only udpate the TTL of the node that is created or updated. + +https://github.com/owncloud/ocis/pull/10575 diff --git a/go.mod b/go.mod index 9c1dc31a5..5c6df4bd1 100644 --- a/go.mod +++ b/go.mod @@ -350,7 +350,7 @@ replace github.com/unrolled/secure => github.com/DeepDiver1975/secure v0.0.0-202 replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90 -replace go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.1-0.20241028133844-ac2cdce96c71 +replace go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.1-0.20241115112658-b5d4de5ed9b3 // exclude the v2 line of go-sqlite3 which was released accidentally and prevents pulling in newer versions of go-sqlite3 // see https://github.com/mattn/go-sqlite3/issues/965 for more details diff --git a/go.sum b/go.sum index 3686ca1e0..adf033242 100644 --- a/go.sum +++ b/go.sum @@ -194,8 +194,8 @@ github.com/bombsimon/logrusr/v3 v3.1.0/go.mod h1:PksPPgSFEL2I52pla2glgCyyd2OqOHA github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= -github.com/butonic/go-micro/v4 v4.11.1-0.20241028133844-ac2cdce96c71 h1:O26NWIQEs6vT4j/mQBH81D82ix7NE2ks1lekZ+g+C2k= -github.com/butonic/go-micro/v4 v4.11.1-0.20241028133844-ac2cdce96c71/go.mod h1:eE/tD53n3KbVrzrWxKLxdkGw45Fg1qaNLWjpJMvIUF4= +github.com/butonic/go-micro/v4 v4.11.1-0.20241115112658-b5d4de5ed9b3 h1:h8Z0hBv5tg/uZMKu8V47+DKWYVQg0lYP8lXDQq7uRpE= +github.com/butonic/go-micro/v4 v4.11.1-0.20241115112658-b5d4de5ed9b3/go.mod h1:eE/tD53n3KbVrzrWxKLxdkGw45Fg1qaNLWjpJMvIUF4= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 h1:3uZCA/BLTIu+DqCfguByNMJa2HVHpXvjfy0Dy7g6fuA= github.com/bytecodealliance/wasmtime-go/v3 v3.0.2/go.mod h1:RnUjnIXxEJcL6BgCvNyzCCRzZcxCgsZCi+RNlvYor5Q= diff --git a/vendor/go-micro.dev/v4/registry/cache/cache.go b/vendor/go-micro.dev/v4/registry/cache/cache.go index 7990b5a88..1ccc2af28 100644 --- a/vendor/go-micro.dev/v4/registry/cache/cache.go +++ b/vendor/go-micro.dev/v4/registry/cache/cache.go @@ -176,6 +176,9 @@ func (c *cache) get(service string) ([]*registry.Service, error) { // cache results cp := util.Copy(services) c.Lock() + for _, s := range services { + c.updateNodeTTLs(service, s.Nodes) + } c.set(service, services) c.Unlock() @@ -210,13 +213,14 @@ func (c *cache) get(service string) ([]*registry.Service, error) { func (c *cache) set(service string, services []*registry.Service) { c.cache[service] = services c.ttls[service] = time.Now().Add(c.opts.TTL) - for _, s := range services { - for _, n := range s.Nodes { - if c.nttls[s.Name] == nil { - c.nttls[s.Name] = make(map[string]time.Time) - } - c.nttls[s.Name][n.Id] = time.Now().Add(c.opts.TTL) - } +} + +func (c *cache) updateNodeTTLs(name string, nodes []*registry.Node) { + if c.nttls[name] == nil { + c.nttls[name] = make(map[string]time.Time) + } + for _, node := range nodes { + c.nttls[name][node.Id] = time.Now().Add(c.opts.TTL) } } @@ -260,6 +264,7 @@ func (c *cache) update(res *registry.Result) { switch res.Action { case "create", "update": + c.updateNodeTTLs(res.Service.Name, res.Service.Nodes) if service == nil { c.set(res.Service.Name, append(services, res.Service)) return diff --git a/vendor/modules.txt b/vendor/modules.txt index fe589ecce..2be4348e1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1884,7 +1884,7 @@ github.com/xrash/smetrics # github.com/yashtewari/glob-intersection v0.2.0 ## explicit; go 1.17 github.com/yashtewari/glob-intersection -# go-micro.dev/v4 v4.11.0 => github.com/butonic/go-micro/v4 v4.11.1-0.20241028133844-ac2cdce96c71 +# go-micro.dev/v4 v4.11.0 => github.com/butonic/go-micro/v4 v4.11.1-0.20241115112658-b5d4de5ed9b3 ## explicit; go 1.18 go-micro.dev/v4 go-micro.dev/v4/api @@ -2406,4 +2406,4 @@ stash.kopano.io/kgol/rndm # github.com/egirna/icap-client => github.com/fschade/icap-client v0.0.0-20240802074440-aade4a234387 # github.com/unrolled/secure => github.com/DeepDiver1975/secure v0.0.0-20240611112133-abc838fb797c # github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90 -# go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.1-0.20241028133844-ac2cdce96c71 +# go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.1-0.20241115112658-b5d4de5ed9b3