[#9999] writecache: Use object size to check free space
All checks were successful
DCO action / DCO (pull_request) Successful in 40s
Vulncheck / Vulncheck (pull_request) Successful in 1m34s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m46s
Build / Build Components (pull_request) Successful in 2m31s
Tests and linters / Run gofumpt (pull_request) Successful in 2m53s
Tests and linters / Staticcheck (pull_request) Successful in 3m26s
Tests and linters / Lint (pull_request) Successful in 3m31s
Tests and linters / Tests (pull_request) Successful in 3m59s
Tests and linters / Tests with -race (pull_request) Successful in 3m57s
Tests and linters / gopls check (pull_request) Successful in 3m55s

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-03-10 17:51:06 +03:00
parent bd61f7bf0a
commit 38663a3163
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
2 changed files with 10 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package writecache
import (
"context"
"fmt"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
@ -59,7 +60,15 @@ func (c *cache) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, erro
// 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() {
if prm.RawData == nil { // foolproof: RawData should be marshalled by shard.
data, err := prm.Object.Marshal()
if err != nil {
return fmt.Errorf("cannot marshal object: %w", err)
}
prm.RawData = data
}
size := uint64(len(prm.RawData))
if !c.hasEnoughSpace(size) {
return ErrOutOfSpace
}

View file

@ -7,10 +7,6 @@ func (c *cache) estimateCacheSize() (uint64, uint64) {
return count, size
}
func (c *cache) hasEnoughSpaceFS() bool {
return c.hasEnoughSpace(c.maxObjectSize)
}
func (c *cache) hasEnoughSpace(objectSize uint64) bool {
count, size := c.estimateCacheSize()
if c.maxCacheCount > 0 && count+1 > c.maxCacheCount {