2020-11-30 14:59:00 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Open opens all StorageEngine's components.
|
|
|
|
func (e *StorageEngine) Open() error {
|
|
|
|
e.mtx.RLock()
|
|
|
|
defer e.mtx.RUnlock()
|
|
|
|
|
|
|
|
for id, sh := range e.shards {
|
|
|
|
if err := sh.Open(); err != nil {
|
2021-01-18 08:26:49 +00:00
|
|
|
return errors.Wrapf(err, "could not open shard %s", id)
|
2020-11-30 14:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes all StorageEngine's components.
|
|
|
|
func (e *StorageEngine) Init() error {
|
|
|
|
e.mtx.RLock()
|
|
|
|
defer e.mtx.RUnlock()
|
|
|
|
|
|
|
|
for id, sh := range e.shards {
|
|
|
|
if err := sh.Init(); err != nil {
|
|
|
|
return errors.Wrapf(err, "could not initialize shard %s", id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 13:09:27 +00:00
|
|
|
if e.enableMetrics {
|
|
|
|
registerMetrics()
|
|
|
|
}
|
|
|
|
|
2020-11-30 14:59:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close releases all StorageEngine's components.
|
|
|
|
func (e *StorageEngine) Close() error {
|
|
|
|
e.mtx.RLock()
|
|
|
|
defer e.mtx.RUnlock()
|
|
|
|
|
|
|
|
for id, sh := range e.shards {
|
|
|
|
if err := sh.Close(); err != nil {
|
|
|
|
e.log.Debug("could not close shard",
|
|
|
|
zap.String("id", id),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|