@cryptotaxi247 / kubo / commits / 200df850c

badger: add truncate flag

License: MIT Signed-off-by: Lucas Molas <schomatis@gmail.com>

Lucas Molas committed Oct 22, 2018 at 09:17 UTC 200df850ccc2c747f75acf9d06b00230d2f72c98
2 files changed +18 -1
docs/datastores.md
+5 -1
@@ -38,11 +38,15 @@ Uses a leveldb database to store key value pairs.
38 ## badgerds
39 Uses [badger](https://github.com/dgraph-io/badger) as a key value store.
40
41 +* `syncWrites`: Synchronize every write to disk.
42 +* `truncate`: Truncate the DB if a corrupted sector is found (otherwise Badger won't start). This option is always set to `true` in Windows if `syncWrites` is set.
43 +
44 ```json
45 {
46 "type": "badgerds",
47 "path": "<location of badger inside repo",
45 - "syncWrites": true|false
48 + "syncWrites": true|false,
49 + "truncate": true|false,
50 }
51 ```
52
plugin/plugins/badgerds/badgerds.go
+13
@@ -41,6 +41,7 @@ func (*badgerdsPlugin) DatastoreTypeName() string {
41 type datastoreConfig struct {
42 path string
43 syncWrites bool
44 + truncate bool
45
46 vlogFileSize int64
47 }
@@ -68,6 +69,17 @@ func (*badgerdsPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
69 }
70 }
71
72 + truncate, ok := params["truncate"]
73 + if !ok {
74 + c.truncate = true
75 + } else {
76 + if truncate, ok := truncate.(bool); ok {
77 + c.truncate = truncate
78 + } else {
79 + return nil, fmt.Errorf("'truncate' field was not a boolean")
80 + }
81 + }
82 +
83 vls, ok := params["vlogFileSize"]
84 if !ok {
85 // default to 1GiB
@@ -108,6 +120,7 @@ func (c *datastoreConfig) Create(path string) (repo.Datastore, error) {
120
121 defopts := badgerds.DefaultOptions
122 defopts.SyncWrites = c.syncWrites
123 + defopts.Truncate = c.truncate
124 defopts.ValueLogFileSize = c.vlogFileSize
125
126 return badgerds.NewDatastore(p, &defopts)