[#377] storage engine: Change the implementation of Delete operation

Make `StorageEngine.Delete` to execute `Inhume` operation with
`MarkAsGarbage` parameter on the `Shard` that holds the object. Searching of
the particular shard is performed through iterating over HRW-sorted shards.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-15 14:42:54 +03:00 committed by Alex Vanin
parent d3a0079d1d
commit 6ec7433e14

View file

@ -25,23 +25,38 @@ func (p *DeletePrm) WithAddresses(addr ...*objectSDK.Address) *DeletePrm {
return p return p
} }
// Delete removes objects from the shards. // Delete marks the objects to be removed.
func (e *StorageEngine) Delete(prm *DeletePrm) (*DeleteRes, error) { func (e *StorageEngine) Delete(prm *DeletePrm) (*DeleteRes, error) {
shPrm := new(shard.DeletePrm). shPrm := new(shard.InhumePrm)
WithAddresses(prm.addr...) existsPrm := new(shard.ExistsPrm)
e.iterateOverUnsortedShards(func(sh *shard.Shard) (stop bool) { for i := range prm.addr {
_, err := sh.Delete(shPrm) e.iterateOverSortedShards(prm.addr[i], func(_ int, sh *shard.Shard) (stop bool) {
if err != nil { resExists, err := sh.Exists(existsPrm.WithAddress(prm.addr[i]))
// TODO: smth wrong with shard, need to be processed if err != nil {
e.log.Warn("could not delete object from shard", // TODO: smth wrong with shard, need to be processed
zap.Stringer("shard", sh.ID()), e.log.Warn("could not check object existence",
zap.String("error", err.Error()), zap.Stringer("shard", sh.ID()),
) zap.String("error", err.Error()),
} )
return false 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
})
}
return nil, nil return nil, nil
} }