mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
Merge pull request #5625 from schomatis/feat/badger/add-truncate-option
badger: add truncate flag
This commit is contained in:
commit
fffa3ec9d7
@ -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,
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user