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-01 10:26:53 +00:00
|
|
|
// WithAddress 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-01 10:26:53 +00:00
|
|
|
func (p *DeletePrm) WithAddress(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
|
|
|
|
}
|
|
|
|
|
2020-12-01 10:26:53 +00:00
|
|
|
// Delete removes objects from the shards.
|
2020-11-17 12:26:03 +00:00
|
|
|
func (e *StorageEngine) Delete(prm *DeletePrm) (*DeleteRes, error) {
|
2020-11-19 12:13:42 +00:00
|
|
|
shPrm := new(shard.DeletePrm).
|
2020-12-01 10:26:53 +00:00
|
|
|
WithAddress(prm.addr...)
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2020-12-01 10:26:53 +00:00
|
|
|
e.iterateOverUnsortedShards(func(sh *shard.Shard) (stop bool) {
|
2020-11-17 12:26:03 +00:00
|
|
|
_, err := sh.Delete(shPrm)
|
|
|
|
if err != nil {
|
|
|
|
// TODO: smth wrong with shard, need to be processed
|
2020-12-01 10:26:53 +00:00
|
|
|
e.log.Warn("could not delete object from shard",
|
2020-11-17 12:26:03 +00:00
|
|
|
zap.Stringer("shard", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|