2020-11-17 12:26:03 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DeletePrm groups the parameters of Delete operation.
|
|
|
|
type DeletePrm struct {
|
2020-12-01 10:26:53 +00:00
|
|
|
addr []*objectSDK.Address
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteRes groups resulting values of Delete operation.
|
|
|
|
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:26:03 +00:00
|
|
|
//
|
|
|
|
// Option is required.
|
2020-12-03 09:53:08 +00:00
|
|
|
func (p *DeletePrm) WithAddresses(addr ...*objectSDK.Address) *DeletePrm {
|
2020-11-17 12:26:03 +00:00
|
|
|
if p != nil {
|
2020-12-01 10:26:53 +00:00
|
|
|
p.addr = append(p.addr, addr...)
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-02-15 11:42:54 +00:00
|
|
|
// Delete marks the objects to be removed.
|
2021-11-09 15:46:12 +00:00
|
|
|
//
|
|
|
|
// Returns an error if executions are blocked (see BlockExecution).
|
|
|
|
func (e *StorageEngine) Delete(prm *DeletePrm) (res *DeleteRes, err error) {
|
|
|
|
err = e.exec(func() error {
|
|
|
|
res, err = e.delete(prm)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *StorageEngine) delete(prm *DeletePrm) (*DeleteRes, error) {
|
2021-03-16 08:14:56 +00:00
|
|
|
if e.metrics != nil {
|
|
|
|
defer elapsed(e.metrics.AddDeleteDuration)()
|
2021-03-15 13:09:27 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 11:42:54 +00:00
|
|
|
shPrm := new(shard.InhumePrm)
|
|
|
|
existsPrm := new(shard.ExistsPrm)
|
|
|
|
|
|
|
|
for i := range prm.addr {
|
|
|
|
e.iterateOverSortedShards(prm.addr[i], func(_ int, sh *shard.Shard) (stop bool) {
|
|
|
|
resExists, err := sh.Exists(existsPrm.WithAddress(prm.addr[i]))
|
|
|
|
if err != nil {
|
|
|
|
// TODO: smth wrong with shard, need to be processed
|
|
|
|
e.log.Warn("could not check object existence",
|
|
|
|
zap.Stringer("shard", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
} else if !resExists.Exists() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sh.Inhume(shPrm.MarkAsGarbage(prm.addr[i]))
|
|
|
|
if err != nil {
|
|
|
|
// TODO: smth wrong with shard, need to be processed
|
|
|
|
e.log.Warn("could not inhume object in shard",
|
|
|
|
zap.Stringer("shard", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err == nil
|
|
|
|
})
|
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|