Dmitrii Stepanov
692749dba1
Some checks failed
DCO action / DCO (pull_request) Failing after 1m30s
Tests and linters / Run gofumpt (pull_request) Successful in 1m26s
Vulncheck / Vulncheck (pull_request) Successful in 2m11s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m25s
Build / Build Components (pull_request) Successful in 2m29s
Tests and linters / Lint (pull_request) Failing after 2m26s
Tests and linters / gopls check (pull_request) Successful in 2m43s
Tests and linters / Staticcheck (pull_request) Successful in 2m56s
Tests and linters / Tests (pull_request) Successful in 4m22s
Tests and linters / Tests with -race (pull_request) Successful in 5m58s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
93 lines
2 KiB
Go
93 lines
2 KiB
Go
package blobstor
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// Open opens BlobStor.
|
|
func (b *BlobStor) Open(ctx context.Context, mode mode.Mode) error {
|
|
b.log.Debug(ctx, logs.BlobstorOpening)
|
|
|
|
b.modeMtx.Lock()
|
|
defer b.modeMtx.Unlock()
|
|
b.mode = mode
|
|
|
|
err := b.openBlobStor(ctx, mode)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
b.metrics.SetMode(mode.ReadOnly())
|
|
|
|
return nil
|
|
}
|
|
|
|
func (b *BlobStor) openBlobStor(ctx context.Context, mod mode.Mode) error {
|
|
for i := range b.storage {
|
|
select {
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
default:
|
|
}
|
|
err := b.storage[i].Storage.Open(mode.ConvertToComponentMode(mod))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ErrInitBlobovniczas is returned when blobovnicza initialization fails.
|
|
var ErrInitBlobovniczas = errors.New("failure on blobovnicza initialization stage")
|
|
|
|
// Init initializes internal data structures and system resources.
|
|
//
|
|
// If BlobStor is already initialized, no action is taken.
|
|
//
|
|
// Returns wrapped ErrInitBlobovniczas on blobovnicza tree's initializaiton failure.
|
|
func (b *BlobStor) Init() error {
|
|
b.log.Debug(context.Background(), logs.BlobstorInitializing)
|
|
|
|
if err := b.compression.Init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for i := range b.storage {
|
|
err := b.storage[i].Storage.Init()
|
|
if err != nil {
|
|
return fmt.Errorf("%w: %v", ErrInitBlobovniczas, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Close releases all internal resources of BlobStor.
|
|
func (b *BlobStor) Close() error {
|
|
b.log.Debug(context.Background(), logs.BlobstorClosing)
|
|
|
|
var firstErr error
|
|
for i := range b.storage {
|
|
err := b.storage[i].Storage.Close()
|
|
if err != nil {
|
|
b.log.Info(context.Background(), logs.BlobstorCouldntCloseStorage, zap.String("error", err.Error()))
|
|
if firstErr == nil {
|
|
firstErr = err
|
|
}
|
|
continue
|
|
}
|
|
}
|
|
|
|
err := b.compression.Close()
|
|
if firstErr == nil {
|
|
firstErr = err
|
|
}
|
|
if firstErr == nil {
|
|
b.metrics.Close()
|
|
}
|
|
return firstErr
|
|
}
|