From 3a456793784feb13282c5adbf794410ec0125789 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Thu, 12 Sep 2024 15:13:25 +0800 Subject: [PATCH 1/3] fix: lru lock --- pkg/localcache/lru/lru_lazy.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/localcache/lru/lru_lazy.go b/pkg/localcache/lru/lru_lazy.go index e7f7b8bd51..88e75ef850 100644 --- a/pkg/localcache/lru/lru_lazy.go +++ b/pkg/localcache/lru/lru_lazy.go @@ -99,13 +99,12 @@ func (x *LayLRU[K, V]) GetBatch(keys []K, fetch func(keys []K) (map[K]V, error)) queries := make([]K, 0) setVs := make(map[K]*layLruItem[V]) for _, key := range keys { + x.lock.Unlock() v, ok := x.core.Get(key) + x.lock.Unlock() if ok { - x.lock.Unlock() - v.lock.Lock() expires, value, err1 := v.expires, v.value, v.err if expires != 0 && expires > time.Now().UnixMilli() { - v.lock.Unlock() x.target.IncrGetHit() res[key] = value if err1 != nil { @@ -117,7 +116,6 @@ func (x *LayLRU[K, V]) GetBatch(keys []K, fetch func(keys []K) (map[K]V, error)) } } queries = append(queries, key) - x.lock.Unlock() } values, err1 := fetch(queries) if err1 != nil { From de20311c4bfe69951374bfb3cbed184535d5fc30 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Thu, 12 Sep 2024 15:15:24 +0800 Subject: [PATCH 2/3] fix: lru lock --- pkg/localcache/lru/lru_lazy.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/localcache/lru/lru_lazy.go b/pkg/localcache/lru/lru_lazy.go index 88e75ef850..234eda7658 100644 --- a/pkg/localcache/lru/lru_lazy.go +++ b/pkg/localcache/lru/lru_lazy.go @@ -99,7 +99,6 @@ func (x *LayLRU[K, V]) GetBatch(keys []K, fetch func(keys []K) (map[K]V, error)) queries := make([]K, 0) setVs := make(map[K]*layLruItem[V]) for _, key := range keys { - x.lock.Unlock() v, ok := x.core.Get(key) x.lock.Unlock() if ok { From 34ced79c1b0ee61b4b5a218709a069305e0e8a98 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Thu, 12 Sep 2024 15:36:01 +0800 Subject: [PATCH 3/3] fix: lru lock --- pkg/localcache/lru/lru_lazy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/localcache/lru/lru_lazy.go b/pkg/localcache/lru/lru_lazy.go index 234eda7658..84aa980e8a 100644 --- a/pkg/localcache/lru/lru_lazy.go +++ b/pkg/localcache/lru/lru_lazy.go @@ -102,7 +102,9 @@ func (x *LayLRU[K, V]) GetBatch(keys []K, fetch func(keys []K) (map[K]V, error)) v, ok := x.core.Get(key) x.lock.Unlock() if ok { + v.lock.Lock() expires, value, err1 := v.expires, v.value, v.err + v.lock.Unlock() if expires != 0 && expires > time.Now().UnixMilli() { x.target.IncrGetHit() res[key] = value