2020-11-30 14:30:49 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Open opens all Shard's components.
|
|
|
|
func (s *Shard) Open() error {
|
2020-12-01 07:35:25 +00:00
|
|
|
components := []interface{ Open() error }{
|
|
|
|
s.blobStor, s.metaBase,
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.hasWriteCache() {
|
|
|
|
components = append(components, s.writeCache)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, component := range components {
|
2020-11-30 14:30:49 +00:00
|
|
|
if err := component.Open(); err != nil {
|
2021-01-18 12:54:55 +00:00
|
|
|
return errors.Wrapf(err, "could not open %T", component)
|
2020-11-30 14:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes all Shard's components.
|
|
|
|
func (s *Shard) Init() error {
|
2020-12-01 07:35:25 +00:00
|
|
|
components := []interface{ Init() error }{
|
|
|
|
s.blobStor, s.metaBase,
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.hasWriteCache() {
|
|
|
|
components = append(components, s.writeCache)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, component := range components {
|
2020-11-30 14:30:49 +00:00
|
|
|
if err := component.Init(); err != nil {
|
2021-01-18 08:27:27 +00:00
|
|
|
return errors.Wrapf(err, "could not initialize %T", component)
|
2020-11-30 14:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 11:38:34 +00:00
|
|
|
gc := &gc{
|
|
|
|
gcCfg: s.gcCfg,
|
|
|
|
remover: s.removeGarbage,
|
|
|
|
mEventHandler: map[eventType]*eventHandlers{},
|
|
|
|
}
|
|
|
|
|
|
|
|
gc.init()
|
|
|
|
|
2020-11-30 14:30:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close releases all Shard's components.
|
|
|
|
func (s *Shard) Close() error {
|
2020-12-01 07:35:25 +00:00
|
|
|
components := []interface{ Close() error }{
|
|
|
|
s.blobStor, s.metaBase,
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.hasWriteCache() {
|
|
|
|
components = append(components, s.writeCache)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, component := range components {
|
2020-11-30 14:30:49 +00:00
|
|
|
if err := component.Close(); err != nil {
|
|
|
|
return errors.Wrapf(err, "could not close %s", component)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|