From fdff0ffe41b45d0e919eccc683104987898a4faf Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 24 Jun 2021 15:31:15 +0300 Subject: - Add Clear method to the storages Signed-off-by: Valery Piashchynski --- plugins/kv/drivers/boltdb/driver.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'plugins/kv/drivers/boltdb/driver.go') diff --git a/plugins/kv/drivers/boltdb/driver.go b/plugins/kv/drivers/boltdb/driver.go index 4b675271..0b411e5e 100644 --- a/plugins/kv/drivers/boltdb/driver.go +++ b/plugins/kv/drivers/boltdb/driver.go @@ -373,6 +373,31 @@ func (d *Driver) TTL(keys ...string) (map[string]string, error) { return m, nil } +func (d *Driver) Clear() error { + err := d.DB.Update(func(tx *bolt.Tx) error { + err := tx.DeleteBucket(d.bucket) + if err != nil { + d.log.Error("boltdb delete bucket", "error", err) + return err + } + + _, err = tx.CreateBucket(d.bucket) + if err != nil { + d.log.Error("boltdb create bucket", "error", err) + return err + } + + return nil + }) + + if err != nil { + d.log.Error("clear transaction failed", "error", err) + return err + } + + return nil +} + // ========================= PRIVATE ================================= func (d *Driver) startGCLoop() { //nolint:gocognit -- cgit v1.2.3