summaryrefslogtreecommitdiff
path: root/plugins/memory/kv.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-24 17:40:49 +0300
committerGitHub <[email protected]>2021-06-24 17:40:49 +0300
commite9249c7896331bab97a18a7ee0db17803fdd31fb (patch)
tree99512001f757eb88614acb9b20dada3200008a5d /plugins/memory/kv.go
parentce53a8e149b76f15e8a5dd88ac3b953798d57e8b (diff)
parent60001dbe15b5ff0fec32239ad18b3d308a4150b5 (diff)
#736 feat(kv): `clear` RPC method which completely cleans storagev2.3.1-beta.6
#736 feat(kv): `clear` RPC method which completely cleans storage
Diffstat (limited to 'plugins/memory/kv.go')
-rw-r--r--plugins/memory/kv.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/plugins/memory/kv.go b/plugins/memory/kv.go
index 1cf031d1..c13c2314 100644
--- a/plugins/memory/kv.go
+++ b/plugins/memory/kv.go
@@ -13,7 +13,8 @@ import (
)
type Driver struct {
- heap sync.Map
+ clearMu sync.RWMutex
+ heap sync.Map
// stop is used to stop keys GC and close boltdb connection
stop chan struct{}
log logger.Logger
@@ -203,6 +204,14 @@ func (s *Driver) Delete(keys ...string) error {
return nil
}
+func (s *Driver) Clear() error {
+ s.clearMu.Lock()
+ s.heap = sync.Map{}
+ s.clearMu.Unlock()
+
+ return nil
+}
+
// ================================== PRIVATE ======================================
func (s *Driver) gc() {
@@ -213,6 +222,9 @@ func (s *Driver) gc() {
ticker.Stop()
return
case now := <-ticker.C:
+ // mutes needed to clear the map
+ s.clearMu.RLock()
+
// check every second
s.heap.Range(func(key, value interface{}) bool {
v := value.(*kvv1.Item)
@@ -231,6 +243,8 @@ func (s *Driver) gc() {
}
return true
})
+
+ s.clearMu.RUnlock()
}
}
}