[#1624] blobovniczatree: Return source error from Init()
All checks were successful
DCO action / DCO (pull_request) Successful in 39s
Vulncheck / Vulncheck (pull_request) Successful in 54s
Build / Build Components (pull_request) Successful in 1m23s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m24s
Tests and linters / Run gofumpt (pull_request) Successful in 1m32s
Tests and linters / Staticcheck (pull_request) Successful in 1m56s
Tests and linters / Tests (pull_request) Successful in 2m28s
Tests and linters / Lint (pull_request) Successful in 2m38s
Tests and linters / Tests with -race (pull_request) Successful in 3m47s
Tests and linters / gopls check (pull_request) Successful in 3m49s
Vulncheck / Vulncheck (push) Successful in 1m7s
Pre-commit hooks / Pre-commit (push) Successful in 1m28s
Tests and linters / Run gofumpt (push) Successful in 1m42s
Build / Build Components (push) Successful in 2m9s
Tests and linters / Staticcheck (push) Successful in 2m16s
Tests and linters / Tests (push) Successful in 2m32s
Tests and linters / Lint (push) Successful in 3m6s
Tests and linters / Tests with -race (push) Successful in 3m36s
Tests and linters / gopls check (push) Successful in 3m47s
OCI image / Build container images (push) Successful in 4m28s

As it was before: when the database was opened, an error returned,
but along with the original error, the `context cancelled`` error returned,
because `iterateIncompletedRebuildDBPaths` method has `ctx.Done()` check
and egCtx passed to `iterateIncompletedRebuildDBPaths` method.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-02-03 17:36:21 +03:00
parent 9c4c5a5262
commit 4de5fca547
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
2 changed files with 60 additions and 27 deletions

View file

@ -41,35 +41,34 @@ func (b *Blobovniczas) initializeDBs(ctx context.Context) error {
}
eg, egCtx := errgroup.WithContext(ctx)
eg.SetLimit(b.blzInitWorkerCount)
err = b.iterateIncompletedRebuildDBPaths(egCtx, func(p string) (bool, error) {
eg.Go(func() error {
p = strings.TrimSuffix(p, rebuildSuffix)
shBlz := b.getBlobovniczaWithoutCaching(p)
blz, err := shBlz.Open(egCtx)
if err != nil {
return err
}
defer shBlz.Close(egCtx)
moveInfo, err := blz.ListMoveInfo(egCtx)
if err != nil {
return err
}
for _, move := range moveInfo {
b.deleteProtectedObjects.Add(move.Address)
}
b.log.Debug(egCtx, logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p))
return nil
})
return false, nil
})
if err != nil {
_ = eg.Wait()
return err
if b.blzInitWorkerCount > 0 {
eg.SetLimit(b.blzInitWorkerCount + 1)
}
eg.Go(func() error {
return b.iterateIncompletedRebuildDBPaths(egCtx, func(p string) (bool, error) {
eg.Go(func() error {
p = strings.TrimSuffix(p, rebuildSuffix)
shBlz := b.getBlobovniczaWithoutCaching(p)
blz, err := shBlz.Open(egCtx)
if err != nil {
return err
}
defer shBlz.Close(egCtx)
moveInfo, err := blz.ListMoveInfo(egCtx)
if err != nil {
return err
}
for _, move := range moveInfo {
b.deleteProtectedObjects.Add(move.Address)
}
b.log.Debug(egCtx, logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p))
return nil
})
return false, nil
})
})
return eg.Wait()
}

View file

@ -2,6 +2,9 @@ package blobovniczatree
import (
"context"
"os"
"path"
"strconv"
"testing"
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -129,3 +132,34 @@ func TestObjectsAvailableAfterDepthAndWidthEdit(t *testing.T) {
require.NoError(t, blz.Close(context.Background()))
}
func TestInitBlobovniczasInitErrorType(t *testing.T) {
t.Parallel()
rootDir := t.TempDir()
for idx := 0; idx < 10; idx++ {
f, err := os.Create(path.Join(rootDir, strconv.FormatInt(int64(idx), 10)+".db"))
require.NoError(t, err)
_, err = f.Write([]byte("invalid db"))
require.NoError(t, err)
require.NoError(t, f.Close())
f, err = os.Create(path.Join(rootDir, strconv.FormatInt(int64(idx), 10)+".db"+rebuildSuffix))
require.NoError(t, err)
require.NoError(t, f.Close())
}
blz := NewBlobovniczaTree(
context.Background(),
WithBlobovniczaShallowDepth(1),
WithBlobovniczaShallowWidth(1),
WithRootPath(rootDir),
)
require.NoError(t, blz.Open(mode.ComponentReadWrite))
err := blz.Init()
require.Contains(t, err.Error(), "open blobovnicza")
require.Contains(t, err.Error(), "invalid database")
require.NoError(t, blz.Close(context.Background()))
}