forked from TrueCloudLab/frostfs-node
f037022a7a
Make it store its internal `zap.Logger`'s level. Also, make all the components to accept internal `logger.Logger` instead of `zap.Logger`; it will simplify future refactor. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package shard
|
|
|
|
import (
|
|
"github.com/mr-tron/base58"
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// ID represents Shard identifier.
|
|
//
|
|
// Each shard should have the unique ID within
|
|
// a single instance of local storage.
|
|
type ID []byte
|
|
|
|
// NewIDFromBytes constructs ID from byte slice.
|
|
func NewIDFromBytes(v []byte) *ID {
|
|
return (*ID)(&v)
|
|
}
|
|
|
|
func (id ID) String() string {
|
|
return base58.Encode(id)
|
|
}
|
|
|
|
// ID returns Shard identifier.
|
|
func (s *Shard) ID() *ID {
|
|
return s.info.ID
|
|
}
|
|
|
|
// UpdateID reads shard ID saved in the metabase and updates it if it is missing.
|
|
func (s *Shard) UpdateID() (err error) {
|
|
if err = s.metaBase.Open(false); err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
cErr := s.metaBase.Close()
|
|
if err == nil {
|
|
err = cErr
|
|
}
|
|
}()
|
|
id, err := s.metaBase.ReadShardID()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(id) != 0 {
|
|
s.info.ID = NewIDFromBytes(id)
|
|
}
|
|
|
|
s.log = &logger.Logger{Logger: 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)
|
|
}
|