2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-11-17 17:39:43 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"go.uber.org/zap"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DeletePrm groups the parameters of Delete operation.
|
|
|
|
type DeletePrm struct {
|
|
|
|
addr *objectSDK.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteRes groups resulting values of Delete operation.
|
|
|
|
type DeleteRes struct{}
|
|
|
|
|
|
|
|
// WithAddress is a Delete option to set the address of the object to delete.
|
|
|
|
//
|
|
|
|
// Option is required.
|
|
|
|
func (p *DeletePrm) WithAddress(addr *objectSDK.Address) *DeletePrm {
|
|
|
|
if p != nil {
|
|
|
|
p.addr = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete marks object to delete from shard.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that did not allow to completely
|
|
|
|
// mark the object to delete.
|
|
|
|
func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) {
|
2020-11-17 17:39:43 +00:00
|
|
|
// mark object to delete in metabase
|
|
|
|
if err := s.metaBase.Delete(prm.addr); err != nil {
|
|
|
|
s.log.Warn("could not mark object to delete in metabase",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-24 14:32:21 +00:00
|
|
|
// form DeleteBig parameters
|
|
|
|
delBigPrm := new(blobstor.DeleteBigPrm)
|
|
|
|
delBigPrm.SetAddress(prm.addr)
|
|
|
|
|
|
|
|
if _, err := s.blobStor.DeleteBig(delBigPrm); err != nil {
|
2020-11-17 17:39:43 +00:00
|
|
|
return nil, errors.Wrap(err, "could not remove object from BLOB storage")
|
|
|
|
}
|
2020-11-17 12:23:15 +00:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|