Skip to content

Commit

Permalink
[#1819] common: Add ErrNoSpace
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fyrchik committed Oct 4, 2022
1 parent af56574 commit b89e71f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pkg/local_object_storage/blobstor/blobovniczatree/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()),
Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/local_object_storage/blobstor/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
11 changes: 10 additions & 1 deletion pkg/local_object_storage/blobstor/fstree/fstree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b89e71f

Please sign in to comment.