Skip to content

Commit

Permalink
blobstor: Return ErrNoSpace if all sub-storages are full
Browse files Browse the repository at this point in the history
Previously, `BlobStor` returned `ErrNoPlaceFound` when all sub-storages
were full. This error is related to policy compliance instead of free
space. To make component more responsive, the `ErrNoSpace` error should
be returned in these cases.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Jul 21, 2023
1 parent fa03442 commit ff1a428
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/local_object_storage/blobstor/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (b *BlobStor) Put(prm common.PutPrm) (common.PutRes, error) {
res, err := b.storage[i].Storage.Put(prm)
if err == nil {
logOp(b.log, putOp, prm.Address, b.storage[i].Storage.Type(), res.StorageID)
} else if errors.Is(err, common.ErrNoSpace) {
} else if errors.Is(err, common.ErrNoSpace) && i < len(b.storage)-1 {
b.log.Debug("blobstor sub-storage overflowed, will try another one",
zap.String("type", b.storage[i].Storage.Type()))
continue
Expand Down
11 changes: 9 additions & 2 deletions pkg/local_object_storage/blobstor/put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ func (x *mockWriter) Put(common.PutPrm) (common.PutRes, error) {
func (x *mockWriter) SetCompressor(*compression.Config) {}

func TestBlobStor_Put_Overflow(t *testing.T) {
sub1 := &mockWriter{full: true}
sub2 := &mockWriter{full: false}
bs := blobstor.New(blobstor.WithStorages(
[]blobstor.SubStorage{
{Storage: &mockWriter{full: true}},
{Storage: &mockWriter{full: false}},
{Storage: sub1},
{Storage: sub2},
},
))

_, err := bs.Put(common.PutPrm{})
require.NoError(t, err)

sub2.full = true

_, err = bs.Put(common.PutPrm{})
require.ErrorIs(t, err, common.ErrNoSpace)
}

0 comments on commit ff1a428

Please sign in to comment.