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-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{}
|
|
|
|
|
2020-12-03 09:53:08 +00:00
|
|
|
// WithAddresses 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-05-20 18:08:59 +00:00
|
|
|
func (p *DeletePrm) WithAddresses(addr ...oid.Address) {
|
2020-11-17 12:23:15 +00:00
|
|
|
if p != nil {
|
2020-12-01 07:55:08 +00:00
|
|
|
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-20 18:08:59 +00:00
|
|
|
func (s *Shard) Delete(prm DeletePrm) (*DeleteRes, error) {
|
2022-03-17 11:55:25 +00:00
|
|
|
if s.GetMode() != ModeReadWrite {
|
2021-12-27 11:04:07 +00:00
|
|
|
return nil, ErrReadOnlyMode
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
blobovniczaID, err := meta.IsSmall(s.metaBase, prm.addr[i])
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
if blobovniczaID != nil {
|
|
|
|
smalls[prm.addr[i]] = blobovniczaID
|
|
|
|
}
|
2020-11-17 17:39:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
err := meta.Delete(s.metaBase, prm.addr...)
|
2020-12-01 07:55:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err // stop on metabase error ?
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|