storagenode/blobstore/testblobs: don't error checks in BadDB

We automatically start a chore to check whether the blobstore is
writeable and readable, however, we don't want to fail the tests due to
that reason. Usually we want to test some other failure.

There probably should be some nicer way to achieve this, but this is an
easier fix.

Change-Id: I77ada75329f88d3ea52edd2022e811e337c5255a
This commit is contained in:
Egon Elbre 2023-04-11 16:09:32 +03:00
parent e2ecee41b5
commit 8fba740332
4 changed files with 43 additions and 50 deletions

View File

@ -1280,7 +1280,7 @@ func TestConcurrentAuditsUnknownError(t *testing.T) {
// hits the same set of nodes, and every node is touched by every audit
Satellite: testplanet.ReconfigureRS(minPieces-badNodes, minPieces, minPieces, minPieces),
StorageNodeDB: func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) {
return newBadBlobsAllowVerify(log.Named("baddb"), db), nil
return testblobs.NewBadDB(log.Named("baddb"), db), nil
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
@ -1363,7 +1363,7 @@ func TestConcurrentAuditsFailure(t *testing.T) {
// hits the same set of nodes, and every node is touched by every audit
Satellite: testplanet.ReconfigureRS(minPieces-badNodes, minPieces, minPieces, minPieces),
StorageNodeDB: func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) {
return newBadBlobsAllowVerify(log.Named("baddb"), db), nil
return testblobs.NewBadDB(log.Named("baddb"), db), nil
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc) {
@ -1557,26 +1557,3 @@ func TestConcurrentAuditsTimeout(t *testing.T) {
}
})
}
func newBadBlobsAllowVerify(log *zap.Logger, nodeDB storagenode.DB) storagenode.DB {
badBlobsDB := testblobs.NewBadDB(log.Named("baddb"), nodeDB)
badBlobsDB.Blobs = &badBlobsAllowVerify{ErrorBlobs: badBlobsDB.Blobs, goodBlobs: nodeDB.Pieces()}
return badBlobsDB
}
type badBlobsAllowVerify struct {
testblobs.ErrorBlobs
goodBlobs blobstore.Blobs
}
func (b *badBlobsAllowVerify) VerifyStorageDir(ctx context.Context, id storj.NodeID) error {
return b.goodBlobs.VerifyStorageDir(ctx, id)
}
func (b *badBlobsAllowVerify) CreateVerificationFile(ctx context.Context, id storj.NodeID) error {
return b.goodBlobs.CreateVerificationFile(ctx, id)
}
func (b *badBlobsAllowVerify) CheckWritability(ctx context.Context) error {
return b.goodBlobs.CheckWritability(ctx)
}

View File

@ -95,16 +95,16 @@ type Blobs interface {
// version. This avoids the potential need to check multiple storage formats for the blob
// when the format is already known.
StatWithStorageFormat(ctx context.Context, ref BlobRef, formatVer FormatVersion) (BlobInfo, error)
// FreeSpace return how much free space is available to the blobstore.
FreeSpace(ctx context.Context) (int64, error)
// CheckWritability tests writability of the storage directory by creating and deleting a file.
CheckWritability(ctx context.Context) error
// SpaceUsedForTrash returns the total space used by the trash.
SpaceUsedForTrash(ctx context.Context) (int64, error)
// SpaceUsedForBlobs adds up how much is used in all namespaces.
SpaceUsedForBlobs(ctx context.Context) (int64, error)
// SpaceUsedForBlobsInNamespace adds up how much is used in the given namespace.
SpaceUsedForBlobsInNamespace(ctx context.Context, namespace []byte) (int64, error)
// ListNamespaces finds all namespaces in which keys might currently be stored.
ListNamespaces(ctx context.Context) ([][]byte, error)
// WalkNamespace executes walkFunc for each locally stored blob, stored with
@ -112,11 +112,15 @@ type Blobs interface {
// error, WalkNamespace will stop iterating and return the error immediately. The ctx
// parameter is intended to allow canceling iteration early.
WalkNamespace(ctx context.Context, namespace []byte, walkFunc func(BlobInfo) error) error
// CheckWritability tests writability of the storage directory by creating and deleting a file.
CheckWritability(ctx context.Context) error
// CreateVerificationFile creates a file to be used for storage directory verification.
CreateVerificationFile(ctx context.Context, id storj.NodeID) error
// VerifyStorageDir verifies that the storage directory is correct by checking for the existence and validity
// of the verification file.
VerifyStorageDir(ctx context.Context, id storj.NodeID) error
// Close closes the blob store and any resources associated with it.
Close() error
}

View File

@ -21,6 +21,7 @@ import (
type ErrorBlobs interface {
blobstore.Blobs
SetError(err error)
SetCheckError(err error)
}
// BadDB implements bad storage node DB.
@ -45,16 +46,22 @@ func (bad *BadDB) Pieces() blobstore.Blobs {
return bad.Blobs
}
// SetError sets an error to be returned for all piece operations.
// SetError sets an error to be returned for piece operations.
func (bad *BadDB) SetError(err error) {
bad.Blobs.SetError(err)
}
// SetCheckError sets an error to be returned for check and verification operations.
func (bad *BadDB) SetCheckError(err error) {
bad.Blobs.SetCheckError(err)
}
// BadBlobs implements a bad blob store.
type BadBlobs struct {
err lockedErr
blobs blobstore.Blobs
log *zap.Logger
err lockedErr
checkErr lockedErr
blobs blobstore.Blobs
log *zap.Logger
}
type lockedErr struct {
@ -85,11 +92,16 @@ func newBadBlobs(log *zap.Logger, blobs blobstore.Blobs) *BadBlobs {
}
}
// SetError configures the blob store to return a specific error for all operations.
// SetError configures the blob store to return a specific error for all operations, except verification.
func (bad *BadBlobs) SetError(err error) {
bad.err.Set(err)
}
// SetCheckError configures the blob store to return a specific error for verification operations.
func (bad *BadBlobs) SetCheckError(err error) {
bad.checkErr.Set(err)
}
// Create creates a new blob that can be written optionally takes a size
// argument for performance improvements, -1 is unknown size.
func (bad *BadBlobs) Create(ctx context.Context, ref blobstore.BlobRef, size int64) (blobstore.BlobWriter, error) {
@ -216,14 +228,6 @@ func (bad *BadBlobs) FreeSpace(ctx context.Context) (int64, error) {
return bad.blobs.FreeSpace(ctx)
}
// CheckWritability tests writability of the storage directory by creating and deleting a file.
func (bad *BadBlobs) CheckWritability(ctx context.Context) error {
if err := bad.err.Err(); err != nil {
return err
}
return bad.blobs.CheckWritability(ctx)
}
// SpaceUsedForBlobs adds up how much is used in all namespaces.
func (bad *BadBlobs) SpaceUsedForBlobs(ctx context.Context) (int64, error) {
if err := bad.err.Err(); err != nil {
@ -248,9 +252,17 @@ func (bad *BadBlobs) SpaceUsedForTrash(ctx context.Context) (int64, error) {
return bad.blobs.SpaceUsedForTrash(ctx)
}
// CheckWritability tests writability of the storage directory by creating and deleting a file.
func (bad *BadBlobs) CheckWritability(ctx context.Context) error {
if err := bad.checkErr.Err(); err != nil {
return err
}
return bad.blobs.CheckWritability(ctx)
}
// CreateVerificationFile creates a file to be used for storage directory verification.
func (bad *BadBlobs) CreateVerificationFile(ctx context.Context, id storj.NodeID) error {
if err := bad.err.Err(); err != nil {
if err := bad.checkErr.Err(); err != nil {
return err
}
return bad.blobs.CreateVerificationFile(ctx, id)
@ -259,7 +271,7 @@ func (bad *BadBlobs) CreateVerificationFile(ctx context.Context, id storj.NodeID
// VerifyStorageDir verifies that the storage directory is correct by checking for the existence and validity
// of the verification file.
func (bad *BadBlobs) VerifyStorageDir(ctx context.Context, id storj.NodeID) error {
if err := bad.err.Err(); err != nil {
if err := bad.checkErr.Err(); err != nil {
return err
}
return bad.blobs.VerifyStorageDir(ctx, id)

View File

@ -180,14 +180,6 @@ func (slow *SlowBlobs) FreeSpace(ctx context.Context) (int64, error) {
return slow.blobs.FreeSpace(ctx)
}
// CheckWritability tests writability of the storage directory by creating and deleting a file.
func (slow *SlowBlobs) CheckWritability(ctx context.Context) error {
if err := slow.sleep(ctx); err != nil {
return errs.Wrap(err)
}
return slow.blobs.CheckWritability(ctx)
}
// SpaceUsedForBlobs adds up how much is used in all namespaces.
func (slow *SlowBlobs) SpaceUsedForBlobs(ctx context.Context) (int64, error) {
if err := slow.sleep(ctx); err != nil {
@ -212,6 +204,14 @@ func (slow *SlowBlobs) SpaceUsedForTrash(ctx context.Context) (int64, error) {
return slow.blobs.SpaceUsedForTrash(ctx)
}
// CheckWritability tests writability of the storage directory by creating and deleting a file.
func (slow *SlowBlobs) CheckWritability(ctx context.Context) error {
if err := slow.sleep(ctx); err != nil {
return errs.Wrap(err)
}
return slow.blobs.CheckWritability(ctx)
}
// CreateVerificationFile creates a file to be used for storage directory verification.
func (slow *SlowBlobs) CreateVerificationFile(ctx context.Context, id storj.NodeID) error {
if err := slow.sleep(ctx); err != nil {