frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree/control.go
Dmitrii Stepanov 4de5fca547
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
[#1624] blobovniczatree: Return source error from Init()
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>
2025-02-03 17:36:21 +03:00

99 lines
2.5 KiB
Go

package blobovniczatree
import (
"context"
"strings"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)
// Open opens blobovnicza tree.
func (b *Blobovniczas) Open(mode mode.ComponentMode) error {
b.readOnly = mode.ReadOnly()
b.metrics.SetMode(mode)
b.metrics.SetRebuildStatus(rebuildStatusNotStarted)
b.openManagers()
return nil
}
// Init initializes blobovnicza tree.
//
// Should be called exactly once.
func (b *Blobovniczas) Init() error {
b.log.Debug(context.Background(), logs.BlobovniczatreeInitializingBlobovniczas)
if b.readOnly {
b.log.Debug(context.Background(), logs.BlobovniczatreeReadonlyModeSkipBlobovniczasInitialization)
return nil
}
return b.initializeDBs(context.TODO())
}
func (b *Blobovniczas) initializeDBs(ctx context.Context) error {
err := util.MkdirAllX(b.rootPath, b.perm)
if err != nil {
return err
}
eg, egCtx := errgroup.WithContext(ctx)
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()
}
func (b *Blobovniczas) openManagers() {
b.commondbManager.Open() // order important
b.activeDBManager.Open()
b.dbCache.Open()
}
// Close implements common.Storage.
func (b *Blobovniczas) Close(ctx context.Context) error {
b.dbCache.Close() // order important
b.activeDBManager.Close(ctx)
b.commondbManager.Close()
return nil
}
// returns blobovnicza with path p
//
// If blobovnicza is already cached, instance from cache is returned w/o changes.
func (b *Blobovniczas) getBlobovnicza(ctx context.Context, p string) *sharedDB {
return b.dbCache.GetOrCreate(ctx, p)
}
func (b *Blobovniczas) getBlobovniczaWithoutCaching(p string) *sharedDB {
return b.commondbManager.GetByPath(p)
}