forked from TrueCloudLab/frostfs-node
[#1584] blobovniczatree: move public methods to different files
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
26b4a258e0
commit
0042c1d4a6
7 changed files with 712 additions and 660 deletions
80
pkg/local_object_storage/blobstor/blobovniczatree/put.go
Normal file
80
pkg/local_object_storage/blobstor/blobovniczatree/put.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package blobovniczatree
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Put saves object in the maximum weight blobobnicza.
|
||||
//
|
||||
// returns error if could not save object in any blobovnicza.
|
||||
func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) {
|
||||
if !prm.DontCompress {
|
||||
prm.RawData = b.CConfig.Compress(prm.RawData)
|
||||
}
|
||||
|
||||
var putPrm blobovnicza.PutPrm
|
||||
putPrm.SetAddress(prm.Address)
|
||||
putPrm.SetMarshaledObject(prm.RawData)
|
||||
|
||||
var (
|
||||
fn func(string) (bool, error)
|
||||
id *blobovnicza.ID
|
||||
)
|
||||
|
||||
fn = func(p string) (bool, error) {
|
||||
active, err := b.getActivated(p)
|
||||
if err != nil {
|
||||
b.log.Debug("could not get active blobovnicza",
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if _, err := active.blz.Put(putPrm); err != nil {
|
||||
// check if blobovnicza is full
|
||||
if errors.Is(err, blobovnicza.ErrFull) {
|
||||
b.log.Debug("blobovnicza overflowed",
|
||||
zap.String("path", filepath.Join(p, u64ToHexString(active.ind))),
|
||||
)
|
||||
|
||||
if err := b.updateActive(p, &active.ind); err != nil {
|
||||
b.log.Debug("could not update active blobovnicza",
|
||||
zap.String("level", p),
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return fn(p)
|
||||
}
|
||||
|
||||
b.log.Debug("could not put object to active blobovnicza",
|
||||
zap.String("path", filepath.Join(p, u64ToHexString(active.ind))),
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
p = filepath.Join(p, u64ToHexString(active.ind))
|
||||
|
||||
id = blobovnicza.NewIDFromBytes([]byte(p))
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if err := b.iterateDeepest(prm.Address, fn); err != nil {
|
||||
return common.PutRes{}, err
|
||||
} else if id == nil {
|
||||
return common.PutRes{}, errPutFailed
|
||||
}
|
||||
|
||||
return common.PutRes{StorageID: id.Bytes()}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue