forked from TrueCloudLab/frostfs-node
[#1731] engine: Move single shard PUT to a separate function
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
4208f7c0cf
commit
7377979e12
1 changed files with 66 additions and 58 deletions
|
@ -5,7 +5,9 @@ import (
|
|||
|
||||
"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/util"
|
||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -57,9 +59,6 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
|
|||
return PutRes{}, err
|
||||
}
|
||||
|
||||
var existPrm shard.ExistsPrm
|
||||
existPrm.SetAddress(addr)
|
||||
|
||||
finished := false
|
||||
|
||||
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()]
|
||||
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{})
|
||||
|
||||
if err := pool.Submit(func() {
|
||||
defer close(exitCh)
|
||||
|
||||
var existPrm shard.ExistsPrm
|
||||
existPrm.SetAddress(addr)
|
||||
|
||||
exists, err := sh.Exists(existPrm)
|
||||
if err != nil {
|
||||
if shard.IsErrObjectExpired(err) {
|
||||
|
@ -103,14 +119,13 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
|
|||
}
|
||||
|
||||
var putPrm shard.PutPrm
|
||||
putPrm.SetObject(prm.obj)
|
||||
putPrm.SetObject(obj)
|
||||
|
||||
_, err = sh.Put(putPrm)
|
||||
if err != nil {
|
||||
e.log.Warn("could not put object in shard",
|
||||
zap.Stringer("shard", sh.ID()),
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
zap.String("error", err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -123,13 +138,6 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
|
|||
<-exitCh
|
||||
|
||||
return finished
|
||||
})
|
||||
|
||||
if !finished {
|
||||
err = errPutShard
|
||||
}
|
||||
|
||||
return PutRes{}, err
|
||||
}
|
||||
|
||||
// Put writes provided object to local storage.
|
||||
|
|
Loading…
Reference in a new issue