2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2023-06-06 06:05:52 +00:00
|
|
|
"time"
|
2021-05-18 08:12:51 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-04-12 14:01:29 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2020-11-17 16:29:00 +00:00
|
|
|
)
|
|
|
|
|
2022-09-28 08:10:46 +00:00
|
|
|
// ErrNoPlaceFound is returned when object can't be saved to any sub-storage component
|
|
|
|
// because of the policy.
|
2022-10-31 07:02:30 +00:00
|
|
|
var ErrNoPlaceFound = logicerr.New("couldn't find a place to store an object")
|
2022-09-28 08:10:46 +00:00
|
|
|
|
2020-11-17 16:29:00 +00:00
|
|
|
// Put saves the object in BLOB storage.
|
|
|
|
//
|
2020-11-24 14:24:07 +00:00
|
|
|
// If object is "big", BlobStor saves the object in shallow dir.
|
|
|
|
// Otherwise, BlobStor saves the object in blobonicza. In this
|
|
|
|
// case the identifier of blobovnicza is returned.
|
|
|
|
//
|
2020-11-17 16:29:00 +00:00
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely save the object.
|
2023-04-12 14:01:29 +00:00
|
|
|
func (b *BlobStor) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, error) {
|
2023-06-06 06:05:52 +00:00
|
|
|
var (
|
|
|
|
startedAt = time.Now()
|
|
|
|
success = false
|
|
|
|
size = 0
|
|
|
|
)
|
|
|
|
defer func() {
|
|
|
|
b.metrics.Put(time.Since(startedAt), size, success)
|
|
|
|
}()
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "BlobStor.Put",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
|
|
|
attribute.Bool("dont_compress", prm.DontCompress),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-11-15 12:33:48 +00:00
|
|
|
b.modeMtx.RLock()
|
|
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
if prm.Object != nil {
|
|
|
|
prm.Address = object.AddressOf(prm.Object)
|
|
|
|
}
|
2022-07-06 13:41:35 +00:00
|
|
|
if prm.RawData == nil {
|
|
|
|
// marshal object
|
|
|
|
data, err := prm.Object.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return common.PutRes{}, fmt.Errorf("could not marshal the object: %w", err)
|
|
|
|
}
|
|
|
|
prm.RawData = data
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
2023-06-06 06:05:52 +00:00
|
|
|
size = len(prm.RawData)
|
2020-11-17 16:29:00 +00:00
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
for i := range b.storage {
|
2022-07-11 12:34:17 +00:00
|
|
|
if b.storage[i].Policy == nil || b.storage[i].Policy(prm.Object, prm.RawData) {
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := b.storage[i].Storage.Put(ctx, prm)
|
2022-07-08 11:33:49 +00:00
|
|
|
if err == nil {
|
2023-06-06 06:05:52 +00:00
|
|
|
success = true
|
2024-10-21 07:22:54 +00:00
|
|
|
logOp(ctx, b.log, putOp, prm.Address, b.storage[i].Storage.Type(), res.StorageID)
|
2022-07-08 11:33:49 +00:00
|
|
|
}
|
|
|
|
return res, err
|
2021-09-06 14:28:07 +00:00
|
|
|
}
|
2021-01-11 15:21:06 +00:00
|
|
|
}
|
2020-11-26 07:44:34 +00:00
|
|
|
|
2022-09-28 08:10:46 +00:00
|
|
|
return common.PutRes{}, ErrNoPlaceFound
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|