Alejandro Lopez
ae322e9f73
Some checks failed
Build / Build Components (1.19) (pull_request) Failing after 3s
Build / Build Components (1.20) (pull_request) Failing after 2s
Tests and linters / Tests (1.19) (pull_request) Failing after 3s
Tests and linters / Tests with -race (pull_request) Failing after 3s
Tests and linters / Lint (pull_request) Failing after 12s
Tests and linters / Staticcheck (pull_request) Failing after 3s
Vulncheck / Vulncheck (pull_request) Successful in 5m46s
Tests and linters / Tests (1.20) (pull_request) Successful in 11m37s
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
37 lines
937 B
Go
37 lines
937 B
Go
package writecachebadger
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"github.com/dgraph-io/badger/v4"
|
|
)
|
|
|
|
// 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).
|
|
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...))
|
|
}
|