2020-11-30 14:16:11 +00:00
|
|
|
package blobstor
|
|
|
|
|
2022-06-27 08:36:32 +00:00
|
|
|
import (
|
2023-08-31 16:26:47 +00:00
|
|
|
"context"
|
2022-06-27 08:36:32 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2022-07-08 11:33:49 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2024-02-09 06:17:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2022-07-08 11:33:49 +00:00
|
|
|
"go.uber.org/zap"
|
2022-06-27 08:36:32 +00:00
|
|
|
)
|
|
|
|
|
2020-11-30 14:16:11 +00:00
|
|
|
// Open opens BlobStor.
|
2024-02-09 06:17:17 +00:00
|
|
|
func (b *BlobStor) Open(ctx context.Context, mode mode.Mode) error {
|
2024-10-21 07:22:54 +00:00
|
|
|
b.log.Debug(ctx, logs.BlobstorOpening)
|
2020-11-30 14:16:11 +00:00
|
|
|
|
2024-02-09 06:17:17 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-06-04 13:28:47 +00:00
|
|
|
func (b *BlobStor) openBlobStor(ctx context.Context, mod mode.Mode) error {
|
2022-07-08 11:33:49 +00:00
|
|
|
for i := range b.storage {
|
2023-08-31 16:26:47 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
default:
|
|
|
|
}
|
2024-06-04 13:28:47 +00:00
|
|
|
err := b.storage[i].Storage.Open(mode.ConvertToComponentMode(mod))
|
2022-07-08 11:33:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2020-11-30 14:16:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 08:36:32 +00:00
|
|
|
// ErrInitBlobovniczas is returned when blobovnicza initialization fails.
|
|
|
|
var ErrInitBlobovniczas = errors.New("failure on blobovnicza initialization stage")
|
|
|
|
|
2020-11-30 14:16:11 +00:00
|
|
|
// Init initializes internal data structures and system resources.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// If BlobStor is already initialized, no action is taken.
|
2022-06-27 08:36:32 +00:00
|
|
|
//
|
|
|
|
// Returns wrapped ErrInitBlobovniczas on blobovnicza tree's initializaiton failure.
|
2024-10-21 13:27:28 +00:00
|
|
|
func (b *BlobStor) Init(ctx context.Context) error {
|
|
|
|
b.log.Debug(ctx, logs.BlobstorInitializing)
|
2020-11-30 14:16:11 +00:00
|
|
|
|
2022-08-19 14:29:53 +00:00
|
|
|
if err := b.compression.Init(); err != nil {
|
2022-07-11 12:34:17 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
for i := range b.storage {
|
|
|
|
err := b.storage[i].Storage.Init()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("%w: %v", ErrInitBlobovniczas, err)
|
|
|
|
}
|
2022-06-27 08:36:32 +00:00
|
|
|
}
|
|
|
|
return nil
|
2020-11-30 14:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close releases all internal resources of BlobStor.
|
2024-10-21 13:27:28 +00:00
|
|
|
func (b *BlobStor) Close(ctx context.Context) error {
|
|
|
|
b.log.Debug(ctx, logs.BlobstorClosing)
|
2020-11-30 14:16:11 +00:00
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
var firstErr error
|
|
|
|
for i := range b.storage {
|
2024-10-21 13:27:28 +00:00
|
|
|
err := b.storage[i].Storage.Close(ctx)
|
2022-07-08 11:33:49 +00:00
|
|
|
if err != nil {
|
2024-10-21 13:27:28 +00:00
|
|
|
b.log.Info(ctx, logs.BlobstorCouldntCloseStorage, zap.String("error", err.Error()))
|
2022-07-08 11:33:49 +00:00
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2022-07-11 12:34:17 +00:00
|
|
|
|
2022-08-19 14:29:53 +00:00
|
|
|
err := b.compression.Close()
|
2022-07-11 12:34:17 +00:00
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
2023-06-06 06:05:52 +00:00
|
|
|
if firstErr == nil {
|
|
|
|
b.metrics.Close()
|
|
|
|
}
|
2022-07-08 11:33:49 +00:00
|
|
|
return firstErr
|
2020-11-30 14:16:11 +00:00
|
|
|
}
|