[#1731] engine: Move single shard PUT to a separate function

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-12 14:48:06 +03:00 committed by fyrchik
parent 4208f7c0cf
commit 7377979e12

View file

@ -5,7 +5,9 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"github.com/nspcc-dev/neofs-node/pkg/util"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -57,9 +59,6 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
return PutRes{}, err return PutRes{}, err
} }
var existPrm shard.ExistsPrm
existPrm.SetAddress(addr)
finished := false finished := false
e.iterateOverSortedShards(addr, func(ind int, sh hashedShard) (stop bool) { e.iterateOverSortedShards(addr, func(ind int, sh hashedShard) (stop bool) {
@ -67,11 +66,28 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
pool := e.shardPools[sh.ID().String()] pool := e.shardPools[sh.ID().String()]
e.mtx.RUnlock() e.mtx.RUnlock()
finished = e.putToShard(sh.Shard, ind, pool, addr, prm.obj)
return finished
})
if !finished {
err = errPutShard
}
return PutRes{}, err
}
func (e *StorageEngine) putToShard(sh *shard.Shard, ind int, pool util.WorkerPool, addr oid.Address, obj *objectSDK.Object) bool {
var finished bool
exitCh := make(chan struct{}) exitCh := make(chan struct{})
if err := pool.Submit(func() { if err := pool.Submit(func() {
defer close(exitCh) defer close(exitCh)
var existPrm shard.ExistsPrm
existPrm.SetAddress(addr)
exists, err := sh.Exists(existPrm) exists, err := sh.Exists(existPrm)
if err != nil { if err != nil {
if shard.IsErrObjectExpired(err) { if shard.IsErrObjectExpired(err) {
@ -103,14 +119,13 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
} }
var putPrm shard.PutPrm var putPrm shard.PutPrm
putPrm.SetObject(prm.obj) putPrm.SetObject(obj)
_, err = sh.Put(putPrm) _, err = sh.Put(putPrm)
if err != nil { if err != nil {
e.log.Warn("could not put object in shard", e.log.Warn("could not put object in shard",
zap.Stringer("shard", sh.ID()), zap.Stringer("shard", sh.ID()),
zap.String("error", err.Error()), zap.String("error", err.Error()))
)
return return
} }
@ -123,13 +138,6 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
<-exitCh <-exitCh
return finished return finished
})
if !finished {
err = errPutShard
}
return PutRes{}, err
} }
// Put writes provided object to local storage. // Put writes provided object to local storage.