[#1953] blobstor: Log any object removal operation

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-10-21 20:51:31 +03:00 committed by fyrchik
parent 942cc38146
commit 41f93dcc1d
3 changed files with 34 additions and 16 deletions

View file

@ -4,9 +4,7 @@ import (
"errors" "errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" "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" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"go.uber.org/zap"
) )
func (b *BlobStor) Delete(prm common.DeletePrm) (common.DeleteRes, error) { 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) res, err := b.storage[i].Storage.Delete(prm)
if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) { if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) {
if err == nil { if err == nil {
storagelog.Write(b.log, logOp(b.log, deleteOp, prm.Address, b.storage[i].Storage.Type(), prm.StorageID)
storagelog.AddressField(prm.Address),
storagelog.OpField("DELETE"),
zap.String("type", b.storage[i].Storage.Type()),
zap.String("storage ID", string(prm.StorageID)))
} }
return res, err return res, err
} }
} }
} }
var st common.Storage
if len(prm.StorageID) == 0 { 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
} }

View file

@ -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),
)
}

View file

@ -6,9 +6,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/common" "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" 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 // 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) { if b.storage[i].Policy == nil || b.storage[i].Policy(prm.Object, prm.RawData) {
res, err := b.storage[i].Storage.Put(prm) res, err := b.storage[i].Storage.Put(prm)
if err == nil { if err == nil {
storagelog.Write(b.log, logOp(b.log, putOp, prm.Address, b.storage[i].Storage.Type(), res.StorageID)
storagelog.AddressField(prm.Address),
storagelog.OpField("PUT"),
zap.String("type", b.storage[i].Storage.Type()),
zap.String("storage ID", string(res.StorageID)))
} }
return res, err return res, err
} }