From 41f93dcc1dea5001a5674c37847fdca4d6280ab1 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 21 Oct 2022 20:51:31 +0300 Subject: [PATCH] [#1953] blobstor: Log any object removal operation Signed-off-by: Pavel Karpy --- pkg/local_object_storage/blobstor/delete.go | 23 +++++++++++++-------- pkg/local_object_storage/blobstor/logger.go | 19 +++++++++++++++++ pkg/local_object_storage/blobstor/put.go | 8 +------ 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 pkg/local_object_storage/blobstor/logger.go diff --git a/pkg/local_object_storage/blobstor/delete.go b/pkg/local_object_storage/blobstor/delete.go index faa58933b..f47eeb1ae 100644 --- a/pkg/local_object_storage/blobstor/delete.go +++ b/pkg/local_object_storage/blobstor/delete.go @@ -4,9 +4,7 @@ import ( "errors" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" - storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - "go.uber.org/zap" ) func (b *BlobStor) Delete(prm common.DeletePrm) (common.DeleteRes, error) { @@ -15,18 +13,25 @@ func (b *BlobStor) Delete(prm common.DeletePrm) (common.DeleteRes, error) { res, err := b.storage[i].Storage.Delete(prm) if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) { if err == nil { - storagelog.Write(b.log, - storagelog.AddressField(prm.Address), - storagelog.OpField("DELETE"), - zap.String("type", b.storage[i].Storage.Type()), - zap.String("storage ID", string(prm.StorageID))) + logOp(b.log, deleteOp, prm.Address, b.storage[i].Storage.Type(), prm.StorageID) } return res, err } } } + + var st common.Storage + if len(prm.StorageID) == 0 { - return b.storage[len(b.storage)-1].Storage.Delete(prm) + st = b.storage[len(b.storage)-1].Storage + } else { + st = b.storage[0].Storage } - return b.storage[0].Storage.Delete(prm) + + res, err := st.Delete(prm) + if err == nil { + logOp(b.log, deleteOp, prm.Address, st.Type(), prm.StorageID) + } + + return res, err } diff --git a/pkg/local_object_storage/blobstor/logger.go b/pkg/local_object_storage/blobstor/logger.go new file mode 100644 index 000000000..5b6cb71a3 --- /dev/null +++ b/pkg/local_object_storage/blobstor/logger.go @@ -0,0 +1,19 @@ +package blobstor + +import ( + storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" +) + +const deleteOp = "DELETE" +const putOp = "PUT" + +func logOp(l *logger.Logger, op string, addr oid.Address, typ string, sID []byte) { + storagelog.Write(l, + storagelog.AddressField(addr), + storagelog.OpField(op), + storagelog.StorageTypeField(typ), + storagelog.StorageIDField(sID), + ) +} diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index 22b119f13..32f28abd7 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -6,9 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" - storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - "go.uber.org/zap" ) // ErrNoPlaceFound is returned when object can't be saved to any sub-storage component @@ -40,11 +38,7 @@ func (b *BlobStor) Put(prm common.PutPrm) (common.PutRes, error) { if b.storage[i].Policy == nil || b.storage[i].Policy(prm.Object, prm.RawData) { res, err := b.storage[i].Storage.Put(prm) if err == nil { - storagelog.Write(b.log, - storagelog.AddressField(prm.Address), - storagelog.OpField("PUT"), - zap.String("type", b.storage[i].Storage.Type()), - zap.String("storage ID", string(res.StorageID))) + logOp(b.log, putOp, prm.Address, b.storage[i].Storage.Type(), res.StorageID) } return res, err }