forked from TrueCloudLab/frostfs-node
[#1616] engine: Do not use batches in delete
Use a simple loop at the callsite. This way we remove as much as we can. Also, `Delete` metrics is more meaningful now. Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
cda8f9df2e
commit
b064fb24d8
3 changed files with 46 additions and 41 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
// DeletePrm groups the parameters of Delete operation.
|
// DeletePrm groups the parameters of Delete operation.
|
||||||
type DeletePrm struct {
|
type DeletePrm struct {
|
||||||
addr []oid.Address
|
addr oid.Address
|
||||||
|
|
||||||
forceRemoval bool
|
forceRemoval bool
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,12 @@ type DeletePrm struct {
|
||||||
// DeleteRes groups the resulting values of Delete operation.
|
// DeleteRes groups the resulting values of Delete operation.
|
||||||
type DeleteRes struct{}
|
type DeleteRes struct{}
|
||||||
|
|
||||||
// WithAddresses is a Delete option to set the addresses of the objects 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) WithAddresses(addr ...oid.Address) {
|
func (p *DeletePrm) WithAddress(addr oid.Address) {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.addr = append(p.addr, addr...)
|
p.addr = addr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,10 +66,9 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) {
|
||||||
err apistatus.ObjectLocked
|
err apistatus.ObjectLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range prm.addr {
|
e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
|
||||||
e.iterateOverSortedShards(prm.addr[i], func(_ int, sh hashedShard) (stop bool) {
|
|
||||||
var existsPrm shard.ExistsPrm
|
var existsPrm shard.ExistsPrm
|
||||||
existsPrm.SetAddress(prm.addr[i])
|
existsPrm.SetAddress(prm.addr)
|
||||||
|
|
||||||
resExists, err := sh.Exists(existsPrm)
|
resExists, err := sh.Exists(existsPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -86,7 +85,7 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var shPrm shard.InhumePrm
|
var shPrm shard.InhumePrm
|
||||||
shPrm.MarkAsGarbage(prm.addr[i])
|
shPrm.MarkAsGarbage(prm.addr)
|
||||||
if prm.forceRemoval {
|
if prm.forceRemoval {
|
||||||
shPrm.ForceRemoval()
|
shPrm.ForceRemoval()
|
||||||
}
|
}
|
||||||
|
@ -102,7 +101,6 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) {
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
if locked.is {
|
if locked.is {
|
||||||
return DeleteRes{}, locked.err
|
return DeleteRes{}, locked.err
|
||||||
|
|
|
@ -299,7 +299,7 @@ func TestLockForceRemoval(t *testing.T) {
|
||||||
|
|
||||||
// 4.
|
// 4.
|
||||||
var deletePrm DeletePrm
|
var deletePrm DeletePrm
|
||||||
deletePrm.WithAddresses(objectcore.AddressOf(lock))
|
deletePrm.WithAddress(objectcore.AddressOf(lock))
|
||||||
deletePrm.WithForceRemoval()
|
deletePrm.WithForceRemoval()
|
||||||
|
|
||||||
_, err = e.Delete(deletePrm)
|
_, err = e.Delete(deletePrm)
|
||||||
|
|
|
@ -35,13 +35,20 @@ func (s *Server) DropObjects(_ context.Context, req *control.DropObjectsRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var firstErr error
|
||||||
|
for i := range addrList {
|
||||||
var prm engine.DeletePrm
|
var prm engine.DeletePrm
|
||||||
prm.WithAddresses(addrList...)
|
|
||||||
prm.WithForceRemoval()
|
prm.WithForceRemoval()
|
||||||
|
prm.WithAddress(addrList[i])
|
||||||
|
|
||||||
_, err := s.s.Delete(prm)
|
_, err := s.s.Delete(prm)
|
||||||
if err != nil {
|
if err != nil && firstErr == nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
firstErr = err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if firstErr != nil {
|
||||||
|
return nil, status.Error(codes.Internal, firstErr.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// create and fill response
|
// create and fill response
|
||||||
|
|
Loading…
Reference in a new issue