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