Skip to content

Commit

Permalink
[#1611] shard: Print shard ID in component logs
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
  • Loading branch information
fyrchik committed Jul 19, 2022
1 parent 9f7a22e commit 11c9df6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/local_object_storage/blobstor/blobstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// depth of the object file subdirectory tree.
//
Expand Down
5 changes: 5 additions & 0 deletions pkg/local_object_storage/metabase/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/local_object_storage/shard/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package shard

import (
"github.com/mr-tron/base58"
"go.uber.org/zap"
)

// ID represents Shard identifier.
Expand Down Expand Up @@ -41,6 +42,16 @@ func (s *Shard) UpdateID() (err error) {
}
if len(id) != 0 {
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 s.metaBase.WriteShardID(*s.info.ID)
Expand Down
6 changes: 6 additions & 0 deletions pkg/local_object_storage/writecache/writecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Cache interface {
Iterate(IterationPrm) error
Put(*object.Object) error
SetMode(Mode)
SetLogger(*zap.Logger)
DumpInfo() Info

Init() error
Expand Down Expand Up @@ -111,6 +112,11 @@ func New(opts ...Option) Cache {
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 {
return Info{
Path: c.path,
Expand Down

0 comments on commit 11c9df6

Please sign in to comment.