[#790] blobstor: Log each writing operation

Call `storagelog.Write` in all places after the successful writing op.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-09-06 17:28:07 +03:00 committed by Leonard Lyubich
parent 3cfb58aabd
commit 4f73c00776
3 changed files with 29 additions and 12 deletions

View file

@ -12,6 +12,7 @@ import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -181,10 +182,7 @@ func (b *blobovniczas) put(addr *objectSDK.Address, data []byte) (*blobovnicza.I
id = blobovnicza.NewIDFromBytes([]byte(p)) id = blobovnicza.NewIDFromBytes([]byte(p))
b.log.Debug("object successfully saved in active blobovnicza", storagelog.Write(b.log, storagelog.AddressField(addr), storagelog.OpField("blobovniczas PUT"))
zap.String("path", p),
zap.Stringer("addr", addr),
)
return true, nil return true, nil
} }
@ -262,7 +260,7 @@ func (b *blobovniczas) delete(prm *DeleteSmallPrm) (res *DeleteSmallRes, err err
return nil, err return nil, err
} }
return b.deleteObject(blz, bPrm) return b.deleteObject(blz, bPrm, prm)
} }
activeCache := make(map[string]struct{}) activeCache := make(map[string]struct{})
@ -273,7 +271,7 @@ func (b *blobovniczas) delete(prm *DeleteSmallPrm) (res *DeleteSmallRes, err err
// don't process active blobovnicza of the level twice // don't process active blobovnicza of the level twice
_, ok := activeCache[dirPath] _, ok := activeCache[dirPath]
res, err = b.deleteObjectFromLevel(bPrm, p, !ok) res, err = b.deleteObjectFromLevel(bPrm, p, !ok, prm)
if err != nil { if err != nil {
if !errors.Is(err, object.ErrNotFound) { if !errors.Is(err, object.ErrNotFound) {
b.log.Debug("could not remove object from level", b.log.Debug("could not remove object from level",
@ -351,7 +349,7 @@ func (b *blobovniczas) getRange(prm *GetRangeSmallPrm) (res *GetRangeSmallRes, e
// tries to delete object from particular blobovnicza. // tries to delete object from particular blobovnicza.
// //
// returns no error if object was removed from some blobovnicza of the same level. // returns no error if object was removed from some blobovnicza of the same level.
func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath string, tryActive bool) (*DeleteSmallRes, error) { func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath string, tryActive bool, dp *DeleteSmallPrm) (*DeleteSmallRes, error) {
lvlPath := path.Dir(blzPath) lvlPath := path.Dir(blzPath)
log := b.log.With( log := b.log.With(
@ -363,7 +361,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath
v, ok := b.opened.Get(blzPath) v, ok := b.opened.Get(blzPath)
b.lruMtx.Unlock() b.lruMtx.Unlock()
if ok { if ok {
if res, err := b.deleteObject(v.(*blobovnicza.Blobovnicza), prm); err == nil { if res, err := b.deleteObject(v.(*blobovnicza.Blobovnicza), prm, dp); err == nil {
return res, err return res, err
} else if !errors.Is(err, object.ErrNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not remove object from opened blobovnicza", log.Debug("could not remove object from opened blobovnicza",
@ -381,7 +379,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath
b.activeMtx.RUnlock() b.activeMtx.RUnlock()
if ok && tryActive { if ok && tryActive {
if res, err := b.deleteObject(active.blz, prm); err == nil { if res, err := b.deleteObject(active.blz, prm, dp); err == nil {
return res, err return res, err
} else if !errors.Is(err, object.ErrNotFound) { } else if !errors.Is(err, object.ErrNotFound) {
log.Debug("could not remove object from active blobovnicza", log.Debug("could not remove object from active blobovnicza",
@ -406,7 +404,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath
return nil, err return nil, err
} }
return b.deleteObject(blz, prm) return b.deleteObject(blz, prm, dp)
} }
// tries to read object from particular blobovnicza. // tries to read object from particular blobovnicza.
@ -544,12 +542,18 @@ func (b *blobovniczas) getRangeFromLevel(prm *GetRangeSmallPrm, blzPath string,
} }
// removes object from blobovnicza and returns DeleteSmallRes. // removes object from blobovnicza and returns DeleteSmallRes.
func (b *blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.DeletePrm) (*DeleteSmallRes, error) { func (b *blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.DeletePrm, dp *DeleteSmallPrm) (*DeleteSmallRes, error) {
_, err := blz.Delete(prm) _, err := blz.Delete(prm)
if err != nil { if err != nil {
return nil, err return nil, err
} }
storagelog.Write(b.log,
storagelog.AddressField(dp.addr),
storagelog.OpField("blobovniczas DELETE"),
zap.Stringer("blobovnicza ID", dp.blobovniczaID),
)
return new(DeleteSmallRes), nil return new(DeleteSmallRes), nil
} }

View file

@ -5,6 +5,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
) )
// DeleteBigPrm groups the parameters of DeleteBig operation. // DeleteBigPrm groups the parameters of DeleteBig operation.
@ -27,5 +28,9 @@ func (b *BlobStor) DeleteBig(prm *DeleteBigPrm) (*DeleteBigRes, error) {
err = object.ErrNotFound err = object.ErrNotFound
} }
if err == nil {
storagelog.Write(b.log, storagelog.AddressField(prm.addr), storagelog.OpField("fstree DELETE"))
}
return nil, err return nil, err
} }

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
) )
// PutPrm groups the parameters of Put operation. // PutPrm groups the parameters of Put operation.
@ -43,7 +44,14 @@ func (b *BlobStor) PutRaw(addr *objectSDK.Address, data []byte) (*PutRes, error)
if big { if big {
// save object in shallow dir // save object in shallow dir
return new(PutRes), b.fsTree.Put(addr, data) err := b.fsTree.Put(addr, data)
if err != nil {
return nil, err
}
storagelog.Write(b.log, storagelog.AddressField(addr), storagelog.OpField("fstree PUT"))
return new(PutRes), nil
} }
// save object in blobovnicza // save object in blobovnicza