Merge pull request #5625 from schomatis/feat/badger/add-truncate-option

badger: add truncate flag
This commit is contained in:
Steven Allen 2018-11-27 20:40:22 -08:00 committed by GitHub
commit fffa3ec9d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -38,11 +38,15 @@ Uses a leveldb database to store key value pairs.
## badgerds
Uses [badger](https://github.com/dgraph-io/badger) as a key value store.
* `syncWrites`: Synchronize every write to disk.
* `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.
```json
{
"type": "badgerds",
"path": "<location of badger inside repo",
"syncWrites": true|false
"syncWrites": true|false,
"truncate": true|false,
}
```

View File

@ -41,6 +41,7 @@ func (*badgerdsPlugin) DatastoreTypeName() string {
type datastoreConfig struct {
path string
syncWrites bool
truncate bool
vlogFileSize int64
}
@ -68,6 +69,17 @@ func (*badgerdsPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
}
}
truncate, ok := params["truncate"]
if !ok {
c.truncate = true
} else {
if truncate, ok := truncate.(bool); ok {
c.truncate = truncate
} else {
return nil, fmt.Errorf("'truncate' field was not a boolean")
}
}
vls, ok := params["vlogFileSize"]
if !ok {
// default to 1GiB
@ -108,6 +120,7 @@ func (c *datastoreConfig) Create(path string) (repo.Datastore, error) {
defopts := badgerds.DefaultOptions
defopts.SyncWrites = c.syncWrites
defopts.Truncate = c.truncate
defopts.ValueLogFileSize = c.vlogFileSize
return badgerds.NewDatastore(p, &defopts)