add Compact to badger blockstore

This commit is contained in:
vyzo 2021-03-11 11:45:05 +02:00
parent 4f82421c7c
commit 01ce9b5c44

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"runtime"
"sync/atomic"
"github.com/dgraph-io/badger/v2"
@ -150,6 +151,20 @@ func (b *Blockstore) CollectGarbage() error {
return err
}
// Compact runs a synchronous compaction
func (b *Blockstore) Compact() error {
if atomic.LoadInt64(&b.state) != stateOpen {
return ErrBlockstoreClosed
}
nworkers := runtime.NumCPU() / 2
if nworkers < 2 {
nworkers = 2
}
return b.DB.Flatten(nworkers)
}
// View implements blockstore.Viewer, which leverages zero-copy read-only
// access to values.
func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error {