From ed9e9e85903047cefe52ef28e40cd5d0c217b1da Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 24 Feb 2020 17:51:50 +0300 Subject: [PATCH] storage: add locking into (*MemoryStore).Seek It was missing there. --- pkg/core/storage/memcached_store.go | 2 +- pkg/core/storage/memory_store.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/core/storage/memcached_store.go b/pkg/core/storage/memcached_store.go index fc5daba3b..1958bab5e 100644 --- a/pkg/core/storage/memcached_store.go +++ b/pkg/core/storage/memcached_store.go @@ -75,7 +75,7 @@ func (s *MemCachedStore) GetBatch() *MemBatch { func (s *MemCachedStore) Seek(key []byte, f func(k, v []byte)) { s.mut.RLock() defer s.mut.RUnlock() - s.MemoryStore.Seek(key, f) + s.MemoryStore.seek(key, f) s.ps.Seek(key, func(k, v []byte) { elem := string(k) // If it's in mem, we already called f() for it in MemoryStore.Seek(). diff --git a/pkg/core/storage/memory_store.go b/pkg/core/storage/memory_store.go index 30ba21e26..7238e0a42 100644 --- a/pkg/core/storage/memory_store.go +++ b/pkg/core/storage/memory_store.go @@ -97,6 +97,13 @@ func (s *MemoryStore) PutBatch(batch Batch) error { // Seek implements the Store interface. func (s *MemoryStore) Seek(key []byte, f func(k, v []byte)) { + s.mut.RLock() + s.seek(key, f) + s.mut.RUnlock() +} + +// seek is an internal unlocked implementation of Seek. +func (s *MemoryStore) seek(key []byte, f func(k, v []byte)) { for k, v := range s.mem { if strings.HasPrefix(k, string(key)) { f([]byte(k), v)