From 4f73c00776ecdcb01c47579bbb662d563b337b8c Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 6 Sep 2021 17:28:07 +0300 Subject: [PATCH] [#790] blobstor: Log each writing operation Call `storagelog.Write` in all places after the successful writing op. Signed-off-by: Leonard Lyubich --- .../blobstor/blobovnicza.go | 26 +++++++++++-------- .../blobstor/delete_big.go | 5 ++++ pkg/local_object_storage/blobstor/put.go | 10 ++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/pkg/local_object_storage/blobstor/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovnicza.go index 1aec63f2f..e28a3f610 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovnicza.go @@ -12,6 +12,7 @@ import ( 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/local_object_storage/blobovnicza" + storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" "go.uber.org/zap" ) @@ -181,10 +182,7 @@ func (b *blobovniczas) put(addr *objectSDK.Address, data []byte) (*blobovnicza.I id = blobovnicza.NewIDFromBytes([]byte(p)) - b.log.Debug("object successfully saved in active blobovnicza", - zap.String("path", p), - zap.Stringer("addr", addr), - ) + storagelog.Write(b.log, storagelog.AddressField(addr), storagelog.OpField("blobovniczas PUT")) return true, nil } @@ -262,7 +260,7 @@ func (b *blobovniczas) delete(prm *DeleteSmallPrm) (res *DeleteSmallRes, err err return nil, err } - return b.deleteObject(blz, bPrm) + return b.deleteObject(blz, bPrm, prm) } 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 _, ok := activeCache[dirPath] - res, err = b.deleteObjectFromLevel(bPrm, p, !ok) + res, err = b.deleteObjectFromLevel(bPrm, p, !ok, prm) if err != nil { if !errors.Is(err, object.ErrNotFound) { 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. // // 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) log := b.log.With( @@ -363,7 +361,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath v, ok := b.opened.Get(blzPath) b.lruMtx.Unlock() 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 } else if !errors.Is(err, object.ErrNotFound) { log.Debug("could not remove object from opened blobovnicza", @@ -381,7 +379,7 @@ func (b *blobovniczas) deleteObjectFromLevel(prm *blobovnicza.DeletePrm, blzPath b.activeMtx.RUnlock() 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 } else if !errors.Is(err, object.ErrNotFound) { 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 b.deleteObject(blz, prm) + return b.deleteObject(blz, prm, dp) } // 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. -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) if err != nil { 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 } diff --git a/pkg/local_object_storage/blobstor/delete_big.go b/pkg/local_object_storage/blobstor/delete_big.go index 4f7873e47..c7abec665 100644 --- a/pkg/local_object_storage/blobstor/delete_big.go +++ b/pkg/local_object_storage/blobstor/delete_big.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" "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. @@ -27,5 +28,9 @@ func (b *BlobStor) DeleteBig(prm *DeleteBigPrm) (*DeleteBigRes, error) { err = object.ErrNotFound } + if err == nil { + storagelog.Write(b.log, storagelog.AddressField(prm.addr), storagelog.OpField("fstree DELETE")) + } + return nil, err } diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index 8451a9f8a..40d7b149e 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -4,6 +4,7 @@ import ( "fmt" 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. @@ -43,7 +44,14 @@ func (b *BlobStor) PutRaw(addr *objectSDK.Address, data []byte) (*PutRes, error) if big { // 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