[#1462] *: Remove log.With invocations

`log.With` is suitable during initialization, but in other places it induces
some overhead, even when branches with logging are not taken.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-02 20:20:27 +03:00 committed by LeL
parent 43e776dfb1
commit 2ae7c94cd6
2 changed files with 22 additions and 34 deletions

View file

@ -363,10 +363,6 @@ func (b *blobovniczas) getRange(prm GetRangeSmallPrm) (res *GetRangeSmallRes, er
func (b *blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath string, tryActive bool, dp DeleteSmallPrm) (*DeleteSmallRes, error) { func (b *blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath string, tryActive bool, dp DeleteSmallPrm) (*DeleteSmallRes, error) {
lvlPath := filepath.Dir(blzPath) lvlPath := filepath.Dir(blzPath)
log := b.log.With(
zap.String("path", blzPath),
)
// try to remove from blobovnicza if it is opened // try to remove from blobovnicza if it is opened
b.lruMtx.Lock() b.lruMtx.Lock()
v, ok := b.opened.Get(blzPath) v, ok := b.opened.Get(blzPath)
@ -375,7 +371,8 @@ func (b *blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath
if res, err := b.deleteObject(v.(*blobovnicza.Blobovnicza), prm, dp); err == nil { if res, err := b.deleteObject(v.(*blobovnicza.Blobovnicza), prm, dp); err == nil {
return res, err return res, err
} else if !blobovnicza.IsErrNotFound(err) { } else if !blobovnicza.IsErrNotFound(err) {
log.Debug("could not remove object from opened blobovnicza", b.log.Debug("could not remove object from opened blobovnicza",
zap.String("path", blzPath),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} }
@ -393,7 +390,8 @@ func (b *blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath
if res, err := b.deleteObject(active.blz, prm, dp); err == nil { if res, err := b.deleteObject(active.blz, prm, dp); err == nil {
return res, err return res, err
} else if !blobovnicza.IsErrNotFound(err) { } else if !blobovnicza.IsErrNotFound(err) {
log.Debug("could not remove object from active blobovnicza", b.log.Debug("could not remove object from active blobovnicza",
zap.String("path", blzPath),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} }
@ -405,7 +403,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath
// (blobovniczas "after" the active one are empty anyway, // (blobovniczas "after" the active one are empty anyway,
// and it's pointless to open them). // and it's pointless to open them).
if u64FromHexString(filepath.Base(blzPath)) > active.ind { if u64FromHexString(filepath.Base(blzPath)) > active.ind {
log.Debug("index is too big") b.log.Debug("index is too big", zap.String("path", blzPath))
var errNotFound apistatus.ObjectNotFound var errNotFound apistatus.ObjectNotFound
return nil, errNotFound return nil, errNotFound
@ -426,10 +424,6 @@ func (b *blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath
func (b *blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string, tryActive bool) (*GetSmallRes, error) { func (b *blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string, tryActive bool) (*GetSmallRes, error) {
lvlPath := filepath.Dir(blzPath) lvlPath := filepath.Dir(blzPath)
log := b.log.With(
zap.String("path", blzPath),
)
// try to read from blobovnicza if it is opened // try to read from blobovnicza if it is opened
b.lruMtx.Lock() b.lruMtx.Lock()
v, ok := b.opened.Get(blzPath) v, ok := b.opened.Get(blzPath)
@ -438,7 +432,8 @@ func (b *blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string
if res, err := b.getObject(v.(*blobovnicza.Blobovnicza), prm); err == nil { if res, err := b.getObject(v.(*blobovnicza.Blobovnicza), prm); err == nil {
return res, err return res, err
} else if !blobovnicza.IsErrNotFound(err) { } else if !blobovnicza.IsErrNotFound(err) {
log.Debug("could not read object from opened blobovnicza", b.log.Debug("could not read object from opened blobovnicza",
zap.String("path", blzPath),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} }
@ -457,7 +452,8 @@ func (b *blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string
if res, err := b.getObject(active.blz, prm); err == nil { if res, err := b.getObject(active.blz, prm); err == nil {
return res, err return res, err
} else if !blobovnicza.IsErrNotFound(err) { } else if !blobovnicza.IsErrNotFound(err) {
log.Debug("could not get object from active blobovnicza", b.log.Debug("could not get object from active blobovnicza",
zap.String("path", blzPath),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} }
@ -469,7 +465,7 @@ func (b *blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string
// (blobovniczas "after" the active one are empty anyway, // (blobovniczas "after" the active one are empty anyway,
// and it's pointless to open them). // and it's pointless to open them).
if u64FromHexString(filepath.Base(blzPath)) > active.ind { if u64FromHexString(filepath.Base(blzPath)) > active.ind {
log.Debug("index is too big") b.log.Debug("index is too big", zap.String("path", blzPath))
var errNotFound apistatus.ObjectNotFound var errNotFound apistatus.ObjectNotFound
return nil, errNotFound return nil, errNotFound
@ -490,10 +486,6 @@ func (b *blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string
func (b *blobovniczas) getRangeFromLevel(prm GetRangeSmallPrm, blzPath string, tryActive bool) (*GetRangeSmallRes, error) { func (b *blobovniczas) getRangeFromLevel(prm GetRangeSmallPrm, blzPath string, tryActive bool) (*GetRangeSmallRes, error) {
lvlPath := filepath.Dir(blzPath) lvlPath := filepath.Dir(blzPath)
log := b.log.With(
zap.String("path", blzPath),
)
// try to read from blobovnicza if it is opened // try to read from blobovnicza if it is opened
b.lruMtx.Lock() b.lruMtx.Lock()
v, ok := b.opened.Get(blzPath) v, ok := b.opened.Get(blzPath)
@ -506,7 +498,8 @@ func (b *blobovniczas) getRangeFromLevel(prm GetRangeSmallPrm, blzPath string, t
return res, err return res, err
default: default:
if !blobovnicza.IsErrNotFound(err) { if !blobovnicza.IsErrNotFound(err) {
log.Debug("could not read payload range from opened blobovnicza", b.log.Debug("could not read payload range from opened blobovnicza",
zap.String("path", blzPath),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} }
@ -530,7 +523,8 @@ func (b *blobovniczas) getRangeFromLevel(prm GetRangeSmallPrm, blzPath string, t
return res, err return res, err
default: default:
if !blobovnicza.IsErrNotFound(err) { if !blobovnicza.IsErrNotFound(err) {
log.Debug("could not read payload range from active blobovnicza", b.log.Debug("could not read payload range from active blobovnicza",
zap.String("path", blzPath),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} }
@ -543,7 +537,7 @@ func (b *blobovniczas) getRangeFromLevel(prm GetRangeSmallPrm, blzPath string, t
// (blobovniczas "after" the active one are empty anyway, // (blobovniczas "after" the active one are empty anyway,
// and it's pointless to open them). // and it's pointless to open them).
if u64FromHexString(filepath.Base(blzPath)) > active.ind { if u64FromHexString(filepath.Base(blzPath)) > active.ind {
log.Debug("index is too big") b.log.Debug("index is too big", zap.String("path", blzPath))
var errNotFound apistatus.ObjectNotFound var errNotFound apistatus.ObjectNotFound
@ -735,13 +729,11 @@ func (b *blobovniczas) getActivated(p string) (blobovniczaWithIndex, error) {
// //
// if current active blobovnicza's index is not old, it remains unchanged. // if current active blobovnicza's index is not old, it remains unchanged.
func (b *blobovniczas) updateActive(p string, old *uint64) error { func (b *blobovniczas) updateActive(p string, old *uint64) error {
log := b.log.With(zap.String("path", p)) b.log.Debug("updating active blobovnicza...", zap.String("path", p))
log.Debug("updating active blobovnicza...")
_, err := b.updateAndGet(p, old) _, err := b.updateAndGet(p, old)
log.Debug("active blobovnicza successfully updated") b.log.Debug("active blobovnicza successfully updated", zap.String("path", p))
return err return err
} }
@ -843,9 +835,7 @@ func (b *blobovniczas) init() error {
return fmt.Errorf("could not initialize blobovnicza structure %s: %w", p, err) return fmt.Errorf("could not initialize blobovnicza structure %s: %w", p, err)
} }
log := b.log.With(zap.String("id", p)) b.log.Debug("blobovnicza successfully initialized, closing...", zap.String("id", p))
log.Debug("blobovnicza successfully initialized, closing...")
return nil return nil
}) })

View file

@ -81,10 +81,6 @@ type processPlacementContext struct {
} }
func (p *Policer) processNodes(ctx *processPlacementContext, addr oid.Address, nodes netmap.Nodes, shortage uint32) { func (p *Policer) processNodes(ctx *processPlacementContext, addr oid.Address, nodes netmap.Nodes, shortage uint32) {
log := p.log.With(
zap.Stringer("object", addr),
)
prm := new(headsvc.RemoteHeadPrm).WithObjectAddress(addr) prm := new(headsvc.RemoteHeadPrm).WithObjectAddress(addr)
for i := 0; shortage > 0 && i < len(nodes); i++ { for i := 0; shortage > 0 && i < len(nodes); i++ {
@ -115,7 +111,8 @@ func (p *Policer) processNodes(ctx *processPlacementContext, addr oid.Address, n
} }
if err != nil { if err != nil {
log.Error("receive object header to check policy compliance", p.log.Error("receive object header to check policy compliance",
zap.Stringer("object", addr),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} else { } else {
@ -128,7 +125,8 @@ func (p *Policer) processNodes(ctx *processPlacementContext, addr oid.Address, n
} }
if shortage > 0 { if shortage > 0 {
log.Debug("shortage of object copies detected", p.log.Debug("shortage of object copies detected",
zap.Stringer("object", addr),
zap.Uint32("shortage", shortage), zap.Uint32("shortage", shortage),
) )