2022-07-18 06:16:36 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"path/filepath"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-01-12 13:29:39 +00:00
|
|
|
"go.etcd.io/bbolt"
|
2022-07-18 06:16:36 +00:00
|
|
|
"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) {
|
2022-08-23 13:04:01 +00:00
|
|
|
if b.readOnly {
|
|
|
|
return common.PutRes{}, common.ErrReadOnly
|
|
|
|
}
|
|
|
|
|
2022-07-18 06:16:36 +00:00
|
|
|
if !prm.DontCompress {
|
2022-08-19 14:29:53 +00:00
|
|
|
prm.RawData = b.compression.Compress(prm.RawData)
|
2022-07-18 06:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var putPrm blobovnicza.PutPrm
|
|
|
|
putPrm.SetAddress(prm.Address)
|
|
|
|
putPrm.SetMarshaledObject(prm.RawData)
|
|
|
|
|
|
|
|
var (
|
2022-09-28 08:10:27 +00:00
|
|
|
fn func(string) (bool, error)
|
|
|
|
id *blobovnicza.ID
|
|
|
|
allFull = true
|
2022-07-18 06:16:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fn = func(p string) (bool, error) {
|
|
|
|
active, err := b.getActivated(p)
|
|
|
|
if err != nil {
|
2022-11-09 10:59:24 +00:00
|
|
|
if !isLogical(err) {
|
|
|
|
b.reportError("could not get active blobovnicza", err)
|
|
|
|
} else {
|
|
|
|
b.log.Debug("could not get active blobovnicza",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := active.blz.Put(putPrm); err != nil {
|
2023-01-12 13:29:39 +00:00
|
|
|
// Check if blobovnicza is full. We could either receive `blobovnicza.ErrFull` error
|
|
|
|
// or update active blobovnicza in other thread. In the latter case the database will be closed
|
|
|
|
// and `updateActive` takes care of not updating the active blobovnicza twice.
|
|
|
|
if isFull := errors.Is(err, blobovnicza.ErrFull); isFull || errors.Is(err, bbolt.ErrDatabaseNotOpen) {
|
|
|
|
if isFull {
|
|
|
|
b.log.Debug("blobovnicza overflowed",
|
|
|
|
zap.String("path", filepath.Join(p, u64ToHexString(active.ind))))
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
|
|
|
if err := b.updateActive(p, &active.ind); err != nil {
|
2022-11-09 10:59:24 +00:00
|
|
|
if !isLogical(err) {
|
|
|
|
b.reportError("could not update active blobovnicza", err)
|
|
|
|
} else {
|
|
|
|
b.log.Debug("could not update active blobovnicza",
|
|
|
|
zap.String("level", p),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return fn(p)
|
|
|
|
}
|
|
|
|
|
2022-09-28 08:10:27 +00:00
|
|
|
allFull = false
|
2022-11-09 10:59:24 +00:00
|
|
|
if !isLogical(err) {
|
|
|
|
b.reportError("could not put object to active blobovnicza", err)
|
|
|
|
} else {
|
|
|
|
b.log.Debug("could not put object to active blobovnicza",
|
|
|
|
zap.String("path", filepath.Join(p, u64ToHexString(active.ind))),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
|
|
|
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 {
|
2022-09-28 08:10:27 +00:00
|
|
|
if allFull {
|
|
|
|
return common.PutRes{}, common.ErrNoSpace
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
return common.PutRes{}, errPutFailed
|
|
|
|
}
|
|
|
|
|
|
|
|
return common.PutRes{StorageID: id.Bytes()}, nil
|
|
|
|
}
|