[#645] badgerstore: Add logger

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
Dmitrii Stepanov 2023-10-30 14:07:28 +03:00
parent 234c12580b
commit a94ae026d7
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" RuntimeSoftMemoryDefinedWithGOMEMLIMIT = "soft runtime memory defined with GOMEMLIMIT environment variable, config value skipped"
FailedToCountWritecacheItems = "failed to count writecache items" FailedToCountWritecacheItems = "failed to count writecache items"
AttemtToCloseAlreadyClosedBlobovnicza = "attempt to close an already closed blobovnicza" AttemtToCloseAlreadyClosedBlobovnicza = "attempt to close an already closed blobovnicza"
BadgerStoreGCFailed = "failed to run GC on badgerstore"
FailedToGetContainerCounters = "failed to get container counters values" FailedToGetContainerCounters = "failed to get container counters values"
FailedToRebuildBlobstore = "failed to rebuild blobstore" FailedToRebuildBlobstore = "failed to rebuild blobstore"
BlobstoreRebuildStarted = "blobstore rebuild started" BlobstoreRebuildStarted = "blobstore rebuild started"

View File

@ -6,8 +6,10 @@ import (
"time" "time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression" "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"
"github.com/dgraph-io/badger/v4/options" "github.com/dgraph-io/badger/v4/options"
"go.uber.org/zap"
) )
type cfg struct { type cfg struct {
@ -17,6 +19,7 @@ type cfg struct {
gcTimeout time.Duration gcTimeout time.Duration
gcDiscardRatio float64 gcDiscardRatio float64
metrics Metrics metrics Metrics
logger *logger.Logger
} }
type Option func(*cfg) type Option func(*cfg)
@ -58,6 +61,7 @@ func defaultCfg() *cfg {
gcTimeout: 10 * time.Minute, gcTimeout: 10 * time.Minute,
gcDiscardRatio: 0.2, // for 1GB vLog file GC will perform only if around 200MB could be free gcDiscardRatio: 0.2, // for 1GB vLog file GC will perform only if around 200MB could be free
metrics: &noopMetrics{}, metrics: &noopMetrics{},
logger: &logger.Logger{Logger: zap.L()},
} }
} }
@ -124,3 +128,10 @@ func WithMetrics(m Metrics) Option {
c.metrics = m 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 (
"fmt" "fmt"
"time" "time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
"github.com/dgraph-io/badger/v4" "github.com/dgraph-io/badger/v4"
"go.uber.org/zap"
) )
// Close implements common.Storage. // Close implements common.Storage.
@ -61,6 +63,8 @@ func (s *Store) startGC() {
case <-t.C: case <-t.C:
if err := s.db.RunValueLogGC(s.cfg.gcDiscardRatio); err == nil { 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 _ = 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))
} }
} }
}() }()