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
|
|
|
|
|
|
|
"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 {
|
2020-11-30 14:16:11 +00:00
|
|
|
b.log.Debug("opening...")
|
|
|
|
|
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 {
|
|
|
|
b.log.Debug("initializing...")
|
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
if err := b.CConfig.Init(); err != nil {
|
|
|
|
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 {
|
|
|
|
b.log.Debug("closing...")
|
|
|
|
|
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 {
|
|
|
|
b.log.Info("couldn't close storage", zap.String("error", err.Error()))
|
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2022-07-11 12:34:17 +00:00
|
|
|
|
|
|
|
err := b.CConfig.Close()
|
|
|
|
if firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
2022-07-08 11:33:49 +00:00
|
|
|
return firstErr
|
2020-11-30 14:16:11 +00:00
|
|
|
}
|