forked from TrueCloudLab/frostfs-node
[#1668] writecache: Use object size to check free space
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
bd61f7bf0a
commit
8643e0abc5
2 changed files with 10 additions and 5 deletions
|
@ -2,6 +2,7 @@ package writecache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
"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.
|
// putBig writes object to FSTree and pushes it to the flush workers queue.
|
||||||
func (c *cache) putBig(ctx context.Context, prm common.PutPrm) error {
|
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
|
return ErrOutOfSpace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,6 @@ func (c *cache) estimateCacheSize() (uint64, uint64) {
|
||||||
return count, size
|
return count, size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cache) hasEnoughSpaceFS() bool {
|
|
||||||
return c.hasEnoughSpace(c.maxObjectSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cache) hasEnoughSpace(objectSize uint64) bool {
|
func (c *cache) hasEnoughSpace(objectSize uint64) bool {
|
||||||
count, size := c.estimateCacheSize()
|
count, size := c.estimateCacheSize()
|
||||||
if c.maxCacheCount > 0 && count+1 > c.maxCacheCount {
|
if c.maxCacheCount > 0 && count+1 > c.maxCacheCount {
|
||||||
|
|
Loading…
Add table
Reference in a new issue