[#1611] shard: Print shard ID in component logs

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-19 14:27:12 +03:00 committed by fyrchik
parent 9f7a22e2aa
commit 11c9df6f00
4 changed files with 27 additions and 0 deletions

View file

@ -91,6 +91,11 @@ func New(opts ...Option) *BlobStor {
} }
} }
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
func (b *BlobStor) SetLogger(l *zap.Logger) {
b.log = l
}
// WithShallowDepth returns option to set the // WithShallowDepth returns option to set the
// depth of the object file subdirectory tree. // depth of the object file subdirectory tree.
// //

View file

@ -251,6 +251,11 @@ func bucketKeyHelper(hdr string, val string) []byte {
} }
} }
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
func (db *DB) SetLogger(l *zap.Logger) {
db.log = l
}
// WithLogger returns option to set logger of DB. // WithLogger returns option to set logger of DB.
func WithLogger(l *logger.Logger) Option { func WithLogger(l *logger.Logger) Option {
return func(c *cfg) { return func(c *cfg) {

View file

@ -2,6 +2,7 @@ package shard
import ( import (
"github.com/mr-tron/base58" "github.com/mr-tron/base58"
"go.uber.org/zap"
) )
// ID represents Shard identifier. // ID represents Shard identifier.
@ -41,6 +42,16 @@ func (s *Shard) UpdateID() (err error) {
} }
if len(id) != 0 { if len(id) != 0 {
s.info.ID = NewIDFromBytes(id) s.info.ID = NewIDFromBytes(id)
}
s.log = s.log.With(zap.String("shard_id", s.info.ID.String()))
s.metaBase.SetLogger(s.log)
s.blobStor.SetLogger(s.log)
if s.hasWriteCache() {
s.writeCache.SetLogger(s.log)
}
if len(id) != 0 {
return nil return nil
} }
return s.metaBase.WriteShardID(*s.info.ID) return s.metaBase.WriteShardID(*s.info.ID)

View file

@ -24,6 +24,7 @@ type Cache interface {
Iterate(IterationPrm) error Iterate(IterationPrm) error
Put(*object.Object) error Put(*object.Object) error
SetMode(Mode) SetMode(Mode)
SetLogger(*zap.Logger)
DumpInfo() Info DumpInfo() Info
Init() error Init() error
@ -111,6 +112,11 @@ func New(opts ...Option) Cache {
return c return c
} }
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
func (c *cache) SetLogger(l *zap.Logger) {
c.log = l
}
func (c *cache) DumpInfo() Info { func (c *cache) DumpInfo() Info {
return Info{ return Info{
Path: c.path, Path: c.path,