[#1819] common: Add ErrNoSpace

Add a common error for this case because it is not an error
which should increase error counter. Single error simplifies checks on
the call-site.

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-28 11:10:27 +03:00 committed by fyrchik
parent af56574849
commit b89e71fa78
3 changed files with 20 additions and 3 deletions

View file

@ -26,8 +26,9 @@ func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) {
putPrm.SetMarshaledObject(prm.RawData)
var (
fn func(string) (bool, error)
id *blobovnicza.ID
fn func(string) (bool, error)
id *blobovnicza.ID
allFull = true
)
fn = func(p string) (bool, error) {
@ -59,6 +60,7 @@ func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) {
return fn(p)
}
allFull = false
b.log.Debug("could not put object to active blobovnicza",
zap.String("path", filepath.Join(p, u64ToHexString(active.ind))),
zap.String("error", err.Error()),
@ -77,6 +79,9 @@ func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) {
if err := b.iterateDeepest(prm.Address, fn); err != nil {
return common.PutRes{}, err
} else if id == nil {
if allFull {
return common.PutRes{}, common.ErrNoSpace
}
return common.PutRes{}, errPutFailed
}

View file

@ -5,3 +5,6 @@ import "errors"
// ErrReadOnly MUST be returned for modifying operations when the storage was opened
// in readonly mode.
var ErrReadOnly = errors.New("opened as read-only")
// ErrNoSpace MUST be returned when there is no space to put an object on the device.
var ErrNoSpace = errors.New("no free space")

View file

@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
@ -236,7 +237,15 @@ func (t *FSTree) Put(prm common.PutPrm) (common.PutRes, error) {
if !prm.DontCompress {
prm.RawData = t.Compress(prm.RawData)
}
return common.PutRes{StorageID: []byte{}}, os.WriteFile(p, prm.RawData, t.Permissions)
err := os.WriteFile(p, prm.RawData, t.Permissions)
if err != nil {
var pe *fs.PathError
if errors.As(err, &pe) && pe.Err == syscall.ENOSPC {
err = common.ErrNoSpace
}
}
return common.PutRes{StorageID: []byte{}}, err
}
// PutStream puts executes handler on a file opened for write.