mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
Merge pull request #693 from nspcc-dev/memorystore-seek-lock
storage: add locking into (*MemoryStore).Seek
This commit is contained in:
commit
2f2a4afe21
2 changed files with 8 additions and 1 deletions
|
@ -75,7 +75,7 @@ func (s *MemCachedStore) GetBatch() *MemBatch {
|
||||||
func (s *MemCachedStore) Seek(key []byte, f func(k, v []byte)) {
|
func (s *MemCachedStore) Seek(key []byte, f func(k, v []byte)) {
|
||||||
s.mut.RLock()
|
s.mut.RLock()
|
||||||
defer s.mut.RUnlock()
|
defer s.mut.RUnlock()
|
||||||
s.MemoryStore.Seek(key, f)
|
s.MemoryStore.seek(key, f)
|
||||||
s.ps.Seek(key, func(k, v []byte) {
|
s.ps.Seek(key, func(k, v []byte) {
|
||||||
elem := string(k)
|
elem := string(k)
|
||||||
// If it's in mem, we already called f() for it in MemoryStore.Seek().
|
// If it's in mem, we already called f() for it in MemoryStore.Seek().
|
||||||
|
|
|
@ -97,6 +97,13 @@ func (s *MemoryStore) PutBatch(batch Batch) error {
|
||||||
|
|
||||||
// Seek implements the Store interface.
|
// Seek implements the Store interface.
|
||||||
func (s *MemoryStore) Seek(key []byte, f func(k, v []byte)) {
|
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 {
|
for k, v := range s.mem {
|
||||||
if strings.HasPrefix(k, string(key)) {
|
if strings.HasPrefix(k, string(key)) {
|
||||||
f([]byte(k), v)
|
f([]byte(k), v)
|
||||||
|
|
Loading…
Reference in a new issue