summaryrefslogtreecommitdiff
path: root/plugins/kv
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-14 17:32:25 +0300
committerValery Piashchynski <[email protected]>2021-06-14 17:32:25 +0300
commitd8c013c1f1ae58f6e75a6bea0bef90e29124df51 (patch)
tree808dfae72328887cc698fac7290c8469dedf5d2a /plugins/kv
parent9748651763415c417eaa339920cba031d418fda6 (diff)
- Fix boltdb issues
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/kv')
-rw-r--r--plugins/kv/drivers/boltdb/config.go15
-rw-r--r--plugins/kv/drivers/boltdb/driver.go18
2 files changed, 16 insertions, 17 deletions
diff --git a/plugins/kv/drivers/boltdb/config.go b/plugins/kv/drivers/boltdb/config.go
index ebe73c25..0beb209b 100644
--- a/plugins/kv/drivers/boltdb/config.go
+++ b/plugins/kv/drivers/boltdb/config.go
@@ -1,34 +1,27 @@
package boltdb
type Config struct {
- // Dir is a directory to store the DB files
- Dir string
// File is boltDB file. No need to create it by your own,
// boltdb driver is able to create the file, or read existing
File string
// Bucket to store data in boltDB
- Bucket string
+ bucket string
// db file permissions
Permissions int
// timeout
- Interval uint `mapstructure:"interval"`
+ Interval int `mapstructure:"interval"`
}
// InitDefaults initializes default values for the boltdb
func (s *Config) InitDefaults() {
- if s.Dir == "" {
- s.Dir = "." // current dir
- }
- if s.Bucket == "" {
- s.Bucket = "rr" // default bucket name
- }
+ s.bucket = "default"
if s.File == "" {
s.File = "rr.db" // default file name
}
if s.Permissions == 0 {
- s.Permissions = 777 // free for all
+ s.Permissions = 0777 // free for all
}
if s.Interval == 0 {
diff --git a/plugins/kv/drivers/boltdb/driver.go b/plugins/kv/drivers/boltdb/driver.go
index 253b9d33..5f4d98b1 100644
--- a/plugins/kv/drivers/boltdb/driver.go
+++ b/plugins/kv/drivers/boltdb/driver.go
@@ -4,7 +4,6 @@ import (
"bytes"
"encoding/gob"
"os"
- "path"
"strings"
"sync"
"time"
@@ -47,14 +46,21 @@ func NewBoltDBDriver(log logger.Logger, key string, cfgPlugin config.Configurer,
return nil, errors.E(op, err)
}
- d.bucket = []byte(d.cfg.Bucket)
+ // add default values
+ d.cfg.InitDefaults()
+
+ d.bucket = []byte(d.cfg.bucket)
d.timeout = time.Duration(d.cfg.Interval) * time.Second
d.gc = sync.Map{}
- // add default values
- d.cfg.InitDefaults()
+ db, err := bolt.Open(d.cfg.File, os.FileMode(d.cfg.Permissions), &bolt.Options{
+ Timeout: time.Second * 20,
+ NoGrowSync: false,
+ NoFreelistSync: false,
+ ReadOnly: false,
+ NoSync: false,
+ })
- db, err := bolt.Open(path.Join(d.cfg.Dir, d.cfg.File), os.FileMode(d.cfg.Permissions), nil)
if err != nil {
return nil, errors.E(op, err)
}
@@ -65,7 +71,7 @@ func NewBoltDBDriver(log logger.Logger, key string, cfgPlugin config.Configurer,
// tx.Commit invokes via the db.Update
err = db.Update(func(tx *bolt.Tx) error {
const upOp = errors.Op("boltdb_plugin_update")
- _, err = tx.CreateBucketIfNotExists([]byte(d.cfg.Bucket))
+ _, err = tx.CreateBucketIfNotExists([]byte(d.cfg.bucket))
if err != nil {
return errors.E(op, upOp)
}