Dmitrii Stepanov
692749dba1
Some checks failed
DCO action / DCO (pull_request) Failing after 1m30s
Tests and linters / Run gofumpt (pull_request) Successful in 1m26s
Vulncheck / Vulncheck (pull_request) Successful in 2m11s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m25s
Build / Build Components (pull_request) Successful in 2m29s
Tests and linters / Lint (pull_request) Failing after 2m26s
Tests and linters / gopls check (pull_request) Successful in 2m43s
Tests and linters / Staticcheck (pull_request) Successful in 2m56s
Tests and linters / Tests (pull_request) Successful in 4m22s
Tests and linters / Tests with -race (pull_request) Successful in 5m58s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package writecache
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
storagelog "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/log"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// Put puts object to write-cache.
|
|
//
|
|
// Returns ErrReadOnly if write-cache is in R/O mode.
|
|
// Returns ErrNotInitialized if write-cache has not been initialized yet.
|
|
// Returns ErrOutOfSpace if saving an object leads to WC's size overflow.
|
|
// Returns ErrBigObject if an objects exceeds maximum object size.
|
|
func (c *cache) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, error) {
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "writecache.Put",
|
|
trace.WithAttributes(
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
|
attribute.Bool("dont_compress", prm.DontCompress),
|
|
))
|
|
defer span.End()
|
|
|
|
startedAt := time.Now()
|
|
added := false
|
|
storageType := StorageTypeUndefined
|
|
defer func() {
|
|
c.metrics.Put(time.Since(startedAt), added, storageType)
|
|
}()
|
|
|
|
if !c.modeMtx.TryRLock() {
|
|
return common.PutRes{}, ErrNotInitialized
|
|
}
|
|
defer c.modeMtx.RUnlock()
|
|
if c.readOnly() {
|
|
return common.PutRes{}, ErrReadOnly
|
|
}
|
|
if c.noMetabase() {
|
|
return common.PutRes{}, ErrDegraded
|
|
}
|
|
|
|
sz := uint64(len(prm.RawData))
|
|
if sz > c.maxObjectSize {
|
|
return common.PutRes{}, ErrBigObject
|
|
}
|
|
|
|
storageType = StorageTypeFSTree
|
|
err := c.putBig(ctx, prm)
|
|
if err == nil {
|
|
added = true
|
|
}
|
|
return common.PutRes{}, metaerr.Wrap(err)
|
|
}
|
|
|
|
// putBig writes object to FSTree and pushes it to the flush workers queue.
|
|
func (c *cache) putBig(ctx context.Context, prm common.PutPrm) error {
|
|
if !c.hasEnoughSpaceFS() {
|
|
return ErrOutOfSpace
|
|
}
|
|
|
|
_, err := c.fsTree.Put(ctx, prm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
storagelog.Write(ctx, c.log,
|
|
storagelog.AddressField(prm.Address.EncodeToString()),
|
|
storagelog.StorageTypeField(wcStorageType),
|
|
storagelog.OpField("fstree PUT"),
|
|
)
|
|
// counter changed by fstree
|
|
c.estimateCacheSize()
|
|
|
|
return nil
|
|
}
|