[#645] badgerstore: Add logger

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-10-30 14:07:28 +03:00
parent 9c10844eb0
commit 597a8cb5d1
3 changed files with 16 additions and 0 deletions

View file

@ -526,6 +526,7 @@ const (
RuntimeSoftMemoryDefinedWithGOMEMLIMIT = "soft runtime memory defined with GOMEMLIMIT environment variable, config value skipped"
FailedToCountWritecacheItems = "failed to count writecache items"
AttemtToCloseAlreadyClosedBlobovnicza = "attempt to close an already closed blobovnicza"
BadgerStoreGCFailed = "failed to run GC on badgerstore"
FailedToGetContainerCounters = "failed to get container counters values"
FailedToRebuildBlobstore = "failed to rebuild blobstore"
BlobstoreRebuildStarted = "blobstore rebuild started"

View file

@ -6,8 +6,10 @@ import (
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"github.com/dgraph-io/badger/v4"
"github.com/dgraph-io/badger/v4/options"
"go.uber.org/zap"
)
type cfg struct {
@ -17,6 +19,7 @@ type cfg struct {
gcTimeout time.Duration
gcDiscardRatio float64
metrics Metrics
logger *logger.Logger
}
type Option func(*cfg)
@ -58,6 +61,7 @@ func defaultCfg() *cfg {
gcTimeout: 10 * time.Minute,
gcDiscardRatio: 0.2, // for 1GB vLog file GC will perform only if around 200MB could be free
metrics: &noopMetrics{},
logger: &logger.Logger{Logger: zap.L()},
}
}
@ -124,3 +128,10 @@ func WithMetrics(m Metrics) Option {
c.metrics = m
}
}
// WithLogger sets logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.logger = l
}
}

View file

@ -5,8 +5,10 @@ import (
"errors"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
"github.com/dgraph-io/badger/v4"
"go.uber.org/zap"
)
var errStoreMustBeOpenedBeforeInit = errors.New("store must be opened before initialization")
@ -63,6 +65,8 @@ func (s *Store) startGC() {
case <-t.C:
if err := s.db.RunValueLogGC(s.cfg.gcDiscardRatio); err == nil {
_ = s.db.RunValueLogGC(s.cfg.gcDiscardRatio) // see https://dgraph.io/docs/badger/get-started/#garbage-collection
} else {
s.cfg.logger.Error(logs.BadgerStoreGCFailed, zap.Error(err), zap.String("path", s.cfg.db.Dir))
}
}
}()