[#222] Update Delete method in storage engine
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
aa8dd18b07
commit
f3e96f8c19
1 changed files with 8 additions and 11 deletions
|
@ -8,36 +8,33 @@ import (
|
||||||
|
|
||||||
// DeletePrm groups the parameters of Delete operation.
|
// DeletePrm groups the parameters of Delete operation.
|
||||||
type DeletePrm struct {
|
type DeletePrm struct {
|
||||||
addr *objectSDK.Address
|
addr []*objectSDK.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRes groups resulting values of Delete operation.
|
// DeleteRes groups resulting values of Delete operation.
|
||||||
type DeleteRes struct{}
|
type DeleteRes struct{}
|
||||||
|
|
||||||
// WithAddress is a Delete option to set the address of the object to delete.
|
// WithAddress is a Delete option to set the addresses of the objects to delete.
|
||||||
//
|
//
|
||||||
// Option is required.
|
// Option is required.
|
||||||
func (p *DeletePrm) WithAddress(addr *objectSDK.Address) *DeletePrm {
|
func (p *DeletePrm) WithAddress(addr ...*objectSDK.Address) *DeletePrm {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.addr = addr
|
p.addr = append(p.addr, addr...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete marks object to delete from local storage.
|
// Delete removes objects from the shards.
|
||||||
//
|
|
||||||
// Returns any error encountered that did not allow to completely
|
|
||||||
// mark the object to delete.
|
|
||||||
func (e *StorageEngine) Delete(prm *DeletePrm) (*DeleteRes, error) {
|
func (e *StorageEngine) Delete(prm *DeletePrm) (*DeleteRes, error) {
|
||||||
shPrm := new(shard.DeletePrm).
|
shPrm := new(shard.DeletePrm).
|
||||||
WithAddress(prm.addr)
|
WithAddress(prm.addr...)
|
||||||
|
|
||||||
e.iterateOverSortedShards(prm.addr, func(_ int, sh *shard.Shard) (stop bool) {
|
e.iterateOverUnsortedShards(func(sh *shard.Shard) (stop bool) {
|
||||||
_, err := sh.Delete(shPrm)
|
_, err := sh.Delete(shPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: smth wrong with shard, need to be processed
|
// TODO: smth wrong with shard, need to be processed
|
||||||
e.log.Warn("could not get object from shard",
|
e.log.Warn("could not delete object from shard",
|
||||||
zap.Stringer("shard", sh.ID()),
|
zap.Stringer("shard", sh.ID()),
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue