diff options
author | Valery Piashchynski <[email protected]> | 2021-06-24 15:51:10 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-24 15:51:10 +0300 |
commit | fa8d2a5cc234472c06b287147fda15549ca39c05 (patch) | |
tree | 93b1f93d8b15487e9fbd8f039966553f5fd171af | |
parent | eb65f86843d2ef3829593525958a158ff4d0f56b (diff) |
- Clear BOLTDB TTL memory region on Clear RPC call
Signed-off-by: Valery Piashchynski <[email protected]>
-rw-r--r-- | plugins/kv/drivers/boltdb/driver.go | 9 | ||||
-rw-r--r-- | plugins/memory/kv.go | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/plugins/kv/drivers/boltdb/driver.go b/plugins/kv/drivers/boltdb/driver.go index 0b411e5e..47d37cc2 100644 --- a/plugins/kv/drivers/boltdb/driver.go +++ b/plugins/kv/drivers/boltdb/driver.go @@ -18,6 +18,7 @@ import ( ) type Driver struct { + clearMu sync.RWMutex // db instance DB *bolt.DB // name should be UTF-8 @@ -395,6 +396,10 @@ func (d *Driver) Clear() error { return err } + d.clearMu.Lock() + d.gc = sync.Map{} + d.clearMu.Unlock() + return nil } @@ -407,6 +412,8 @@ func (d *Driver) startGCLoop() { //nolint:gocognit for { select { case <-t.C: + d.clearMu.RLock() + // calculate current time before loop started to be fair now := time.Now() d.gc.Range(func(key, value interface{}) bool { @@ -439,6 +446,8 @@ func (d *Driver) startGCLoop() { //nolint:gocognit } return true }) + + d.clearMu.RUnlock() case <-d.stop: err := d.DB.Close() if err != nil { diff --git a/plugins/memory/kv.go b/plugins/memory/kv.go index 83f6630e..c13c2314 100644 --- a/plugins/memory/kv.go +++ b/plugins/memory/kv.go @@ -223,7 +223,7 @@ func (s *Driver) gc() { return case now := <-ticker.C: // mutes needed to clear the map - s.clearMu.Lock() + s.clearMu.RLock() // check every second s.heap.Range(func(key, value interface{}) bool { @@ -244,7 +244,7 @@ func (s *Driver) gc() { return true }) - s.clearMu.Unlock() + s.clearMu.RUnlock() } } } |