forked from TrueCloudLab/frostfs-node
39 lines
1 KiB
Go
39 lines
1 KiB
Go
package writecachebadger
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"github.com/dgraph-io/badger/v4"
|
|
badgeroptions "github.com/dgraph-io/badger/v4/options"
|
|
)
|
|
|
|
// OpenDB opens a badger instance for write-cache. Opens in read-only mode if ro is true.
|
|
func OpenDB(p string, ro bool, l *logger.Logger) (*badger.DB, error) {
|
|
return badger.Open(badger.DefaultOptions(p).
|
|
WithReadOnly(ro).
|
|
WithSyncWrites(true).
|
|
WithCompression(badgeroptions.None).
|
|
WithLoggingLevel(badger.ERROR).
|
|
WithLogger(badgerLoggerWrapper{l}))
|
|
}
|
|
|
|
type badgerLoggerWrapper struct {
|
|
l *logger.Logger
|
|
}
|
|
|
|
func (w badgerLoggerWrapper) Errorf(msg string, args ...any) {
|
|
w.l.Error(fmt.Sprintf(msg, args...))
|
|
}
|
|
|
|
func (w badgerLoggerWrapper) Warningf(msg string, args ...any) {
|
|
w.l.Warn(fmt.Sprintf(msg, args...))
|
|
}
|
|
|
|
func (w badgerLoggerWrapper) Infof(msg string, args ...any) {
|
|
w.l.Info(fmt.Sprintf(msg, args...))
|
|
}
|
|
|
|
func (w badgerLoggerWrapper) Debugf(msg string, args ...any) {
|
|
w.l.Debug(fmt.Sprintf(msg, args...))
|
|
}
|