2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2020-12-01 07:55:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
2020-11-17 17:39:43 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-06-28 14:05:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
2022-03-17 08:03:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-11-17 17:39:43 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DeletePrm groups the parameters of Delete operation.
|
|
|
|
type DeletePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr []oid.Address
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteRes groups the resulting values of Delete operation.
|
2020-11-17 12:23:15 +00:00
|
|
|
type DeleteRes struct{}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetAddresses is a Delete option to set the addresses of the objects to delete.
|
2020-11-17 12:23:15 +00:00
|
|
|
//
|
|
|
|
// Option is required.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *DeletePrm) SetAddresses(addr ...oid.Address) {
|
|
|
|
p.addr = append(p.addr, addr...)
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 07:55:08 +00:00
|
|
|
// Delete removes data from the shard's writeCache, metaBase and
|
|
|
|
// blobStor.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) Delete(prm DeletePrm) (DeleteRes, error) {
|
2022-06-28 14:05:08 +00:00
|
|
|
if s.GetMode() != mode.ReadWrite {
|
2022-05-31 11:50:39 +00:00
|
|
|
return DeleteRes{}, ErrReadOnlyMode
|
2021-12-27 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 07:55:08 +00:00
|
|
|
ln := len(prm.addr)
|
2022-05-23 14:15:16 +00:00
|
|
|
var delSmallPrm blobstor.DeleteSmallPrm
|
|
|
|
var delBigPrm blobstor.DeleteBigPrm
|
2020-12-01 07:55:08 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
smalls := make(map[oid.Address]*blobovnicza.ID, ln)
|
2020-12-01 07:55:08 +00:00
|
|
|
|
|
|
|
for i := range prm.addr {
|
|
|
|
if s.hasWriteCache() {
|
2021-04-06 10:56:06 +00:00
|
|
|
err := s.writeCache.Delete(prm.addr[i])
|
2022-03-17 08:03:58 +00:00
|
|
|
if err != nil && !writecache.IsErrNotFound(err) {
|
2021-04-06 10:56:06 +00:00
|
|
|
s.log.Error("can't delete object from write cache", zap.String("error", err.Error()))
|
2020-12-01 07:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
var sPrm meta.IsSmallPrm
|
|
|
|
sPrm.WithAddress(prm.addr[i])
|
|
|
|
|
|
|
|
res, err := s.metaBase.IsSmall(sPrm)
|
2020-12-01 07:55:08 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Debug("can't get blobovniczaID from metabase",
|
|
|
|
zap.Stringer("object", prm.addr[i]),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
if res.BlobovniczaID() != nil {
|
|
|
|
smalls[prm.addr[i]] = res.BlobovniczaID()
|
2020-12-01 07:55:08 +00:00
|
|
|
}
|
2020-11-17 17:39:43 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
var delPrm meta.DeletePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
delPrm.SetAddresses(prm.addr...)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
_, err := s.metaBase.Delete(delPrm)
|
2020-12-01 07:55:08 +00:00
|
|
|
if err != nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return DeleteRes{}, err // stop on metabase error ?
|
2020-12-01 07:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range prm.addr { // delete small object
|
|
|
|
if id, ok := smalls[prm.addr[i]]; ok {
|
|
|
|
delSmallPrm.SetAddress(prm.addr[i])
|
|
|
|
delSmallPrm.SetBlobovniczaID(id)
|
|
|
|
|
|
|
|
_, err = s.blobStor.DeleteSmall(delSmallPrm)
|
|
|
|
if err != nil {
|
|
|
|
s.log.Debug("can't remove small object from blobStor",
|
|
|
|
zap.Stringer("object_address", prm.addr[i]),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete big object
|
|
|
|
|
|
|
|
delBigPrm.SetAddress(prm.addr[i])
|
|
|
|
|
|
|
|
_, err = s.blobStor.DeleteBig(delBigPrm)
|
|
|
|
if err != nil {
|
|
|
|
s.log.Debug("can't remove big object from blobStor",
|
|
|
|
zap.Stringer("object_address", prm.addr[i]),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
2020-11-17 17:39:43 +00:00
|
|
|
}
|
2020-11-17 12:23:15 +00:00
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return DeleteRes{}, nil
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|