summaryrefslogtreecommitdiff
path: root/plugins/memory
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-25 11:47:24 +0300
committerValery Piashchynski <[email protected]>2021-06-25 11:47:24 +0300
commit09041fe7499be1929aaffaa113f93f6853564c09 (patch)
treea608df4250439cf9a1511f9e00ff7af6a033579d /plugins/memory
parent64d41f6d87bb8002e700cdcddb5a3a241e4a2a7d (diff)
parente9249c7896331bab97a18a7ee0db17803fdd31fb (diff)
Merge remote-tracking branch 'origin/master' into feature/jobs_plugin
Diffstat (limited to 'plugins/memory')
-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 1906e4fd..3cec1f97 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()
}
}
}