2022-07-18 06:16:36 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2024-06-06 16:01:25 +00:00
|
|
|
"errors"
|
2022-07-18 06:16:36 +00:00
|
|
|
"path/filepath"
|
2023-06-05 07:25:25 +00:00
|
|
|
"time"
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
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"
|
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.
|
2023-04-12 14:01:29 +00:00
|
|
|
func (b *Blobovniczas) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, error) {
|
2023-06-05 07:25:25 +00:00
|
|
|
var (
|
|
|
|
success bool
|
|
|
|
size int
|
|
|
|
startedAt = time.Now()
|
|
|
|
)
|
|
|
|
defer func() {
|
|
|
|
b.metrics.Put(time.Since(startedAt), size, success)
|
|
|
|
}()
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, span := tracing.StartSpanFromContext(ctx, "Blobovniczas.Put",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
|
|
|
attribute.Bool("dont_compress", prm.DontCompress),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
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
|
|
|
}
|
2023-06-05 07:25:25 +00:00
|
|
|
size = len(prm.RawData)
|
2022-07-18 06:16:36 +00:00
|
|
|
|
|
|
|
var putPrm blobovnicza.PutPrm
|
|
|
|
putPrm.SetAddress(prm.Address)
|
|
|
|
putPrm.SetMarshaledObject(prm.RawData)
|
|
|
|
|
2023-03-30 09:31:29 +00:00
|
|
|
it := &putIterator{
|
|
|
|
B: b,
|
|
|
|
ID: nil,
|
|
|
|
AllFull: true,
|
|
|
|
PutPrm: putPrm,
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-06-20 08:24:14 +00:00
|
|
|
if err := b.iterateDeepest(ctx, prm.Address, func(s string) (bool, error) { return it.iterate(ctx, s) }); err != nil {
|
2023-03-30 09:31:29 +00:00
|
|
|
return common.PutRes{}, err
|
|
|
|
} else if it.ID == nil {
|
|
|
|
if it.AllFull {
|
|
|
|
return common.PutRes{}, common.ErrNoSpace
|
2022-07-18 06:16:36 +00:00
|
|
|
}
|
2023-03-30 09:31:29 +00:00
|
|
|
return common.PutRes{}, errPutFailed
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-06-05 07:25:25 +00:00
|
|
|
success = true
|
2023-03-30 09:31:29 +00:00
|
|
|
return common.PutRes{StorageID: it.ID.Bytes()}, nil
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-03-30 09:31:29 +00:00
|
|
|
type putIterator struct {
|
|
|
|
B *Blobovniczas
|
2023-09-19 15:08:38 +00:00
|
|
|
ID *ID
|
2023-03-30 09:31:29 +00:00
|
|
|
AllFull bool
|
|
|
|
PutPrm blobovnicza.PutPrm
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
func (i *putIterator) iterate(ctx context.Context, lvlPath string) (bool, error) {
|
2024-10-21 08:20:17 +00:00
|
|
|
active, err := i.B.activeDBManager.GetOpenedActiveDBForLevel(ctx, lvlPath)
|
2023-03-30 09:31:29 +00:00
|
|
|
if err != nil {
|
|
|
|
if !isLogical(err) {
|
2024-10-21 13:27:28 +00:00
|
|
|
i.B.reportError(ctx, logs.BlobovniczatreeCouldNotGetActiveBlobovnicza, err)
|
2023-03-30 09:31:29 +00:00
|
|
|
} else {
|
2024-10-21 07:22:54 +00:00
|
|
|
i.B.log.Debug(ctx, logs.BlobovniczatreeCouldNotGetActiveBlobovnicza,
|
2024-12-13 08:44:56 +00:00
|
|
|
zap.Error(err),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2023-03-30 09:31:29 +00:00
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-03-30 09:31:29 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
if active == nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
i.B.log.Debug(ctx, logs.BlobovniczatreeBlobovniczaOverflowed, zap.String("level", lvlPath),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2023-08-30 20:36:48 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
2024-10-21 13:27:28 +00:00
|
|
|
defer active.Close(ctx)
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
i.AllFull = false
|
|
|
|
|
|
|
|
_, err = active.Blobovnicza().Put(ctx, i.PutPrm)
|
|
|
|
if err != nil {
|
2023-03-30 09:31:29 +00:00
|
|
|
if !isLogical(err) {
|
2024-10-21 13:27:28 +00:00
|
|
|
i.B.reportError(ctx, logs.BlobovniczatreeCouldNotPutObjectToActiveBlobovnicza, err)
|
2023-03-30 09:31:29 +00:00
|
|
|
} else {
|
2024-10-21 07:22:54 +00:00
|
|
|
i.B.log.Debug(ctx, logs.BlobovniczatreeCouldNotPutObjectToActiveBlobovnicza,
|
2023-09-22 10:07:32 +00:00
|
|
|
zap.String("path", active.SystemPath()),
|
2024-12-13 08:44:56 +00:00
|
|
|
zap.Error(err),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2023-03-30 09:31:29 +00:00
|
|
|
}
|
2024-06-06 16:01:25 +00:00
|
|
|
if errors.Is(err, blobovnicza.ErrNoSpace) {
|
|
|
|
i.AllFull = true
|
|
|
|
}
|
2023-03-30 09:31:29 +00:00
|
|
|
return false, nil
|
2022-07-18 06:16:36 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 10:07:32 +00:00
|
|
|
idx := u64FromHexString(filepath.Base(active.SystemPath()))
|
2023-09-19 15:08:38 +00:00
|
|
|
i.ID = NewIDFromBytes([]byte(filepath.Join(lvlPath, u64ToHexString(idx))))
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-03-30 09:31:29 +00:00
|
|
|
return true, nil
|
2022-07-18 06:16:36 +00:00
|
|
|
}
|