From 18682f240993633bdd05ac1e2b6cfcc6eeb1bf53 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 11 Aug 2021 18:53:18 +0300 Subject: [PATCH] storage: don't use locks for memory batches They're inherently single-threaded, so locking makes no sense for them. --- pkg/core/storage/memory_store.go | 4 ++-- pkg/core/storage/store.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/core/storage/memory_store.go b/pkg/core/storage/memory_store.go index 21ded2220..5fe843b19 100644 --- a/pkg/core/storage/memory_store.go +++ b/pkg/core/storage/memory_store.go @@ -23,12 +23,12 @@ type MemoryBatch struct { // Put implements the Batch interface. func (b *MemoryBatch) Put(k, v []byte) { - _ = b.MemoryStore.Put(k, v) + b.MemoryStore.put(string(k), slice.Copy(v)) } // Delete implements Batch interface. func (b *MemoryBatch) Delete(k []byte) { - _ = b.MemoryStore.Delete(k) + b.MemoryStore.drop(string(k)) } // NewMemoryStore creates a new MemoryStore object. diff --git a/pkg/core/storage/store.go b/pkg/core/storage/store.go index 540fdcc39..a90466a02 100644 --- a/pkg/core/storage/store.go +++ b/pkg/core/storage/store.go @@ -52,7 +52,8 @@ type ( // Batch represents an abstraction on top of batch operations. // Each Store implementation is responsible of casting a Batch - // to its appropriate type. + // to its appropriate type. Batches can only be used in a single + // thread. Batch interface { Delete(k []byte) Put(k, v []byte)