2020-11-30 14:16:11 +00:00
|
|
|
package blobstor
|
|
|
|
|
2022-06-27 08:36:32 +00:00
|
|
|
import (
|
|
|
|
"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"
|
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.
|
2022-06-28 13:42:50 +00:00
|
|
|
func (b *BlobStor) Open(readOnly bool) error {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(logs.BlobstorOpening)
|
2020-11-30 14:16:11 +00:00
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
for i := range b.storage {
|
|
|
|
err := b.storage[i].Storage.Open(readOnly)
|
|
|
|
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.
|
2020-11-30 14:16:11 +00:00
|
|
|
func (b *BlobStor) Init() error {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(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.
|
|
|
|
func (b *BlobStor) Close() error {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(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 {
|
|
|
|
err := b.storage[i].Storage.Close()
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Info(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
|
|
|
|
}
|
2022-07-08 11:33:49 +00:00
|
|
|
return firstErr
|
2020-11-30 14:16:11 +00:00
|
|
|
}
|