frostfs-node/pkg/local_object_storage/shard/control.go
Leonard Lyubich 717f2beb47 [#378] shard: Collect expired tombstones in GC every epoch
Add new epoch event handler to GC that finds all expired tombstones and
marks them and underlying objects to be removed. Shard uses callbacks
provided by the storage engine to mark underlying objects.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-02-19 11:56:32 +03:00

78 lines
1.5 KiB
Go

package shard
import (
"github.com/pkg/errors"
)
// Open opens all Shard's components.
func (s *Shard) Open() error {
components := []interface{ Open() error }{
s.blobStor, s.metaBase,
}
if s.hasWriteCache() {
components = append(components, s.writeCache)
}
for _, component := range components {
if err := component.Open(); err != nil {
return errors.Wrapf(err, "could not open %T", component)
}
}
return nil
}
// Init initializes all Shard's components.
func (s *Shard) Init() error {
components := []interface{ Init() error }{
s.blobStor, s.metaBase,
}
if s.hasWriteCache() {
components = append(components, s.writeCache)
}
for _, component := range components {
if err := component.Init(); err != nil {
return errors.Wrapf(err, "could not initialize %T", component)
}
}
gc := &gc{
gcCfg: s.gcCfg,
remover: s.removeGarbage,
mEventHandler: map[eventType]*eventHandlers{
eventNewEpoch: {
cancelFunc: func() {},
handlers: []eventHandler{
s.collectExpiredObjects,
s.collectExpiredTombstones,
},
},
},
}
gc.init()
return nil
}
// Close releases all Shard's components.
func (s *Shard) Close() error {
components := []interface{ Close() error }{
s.blobStor, s.metaBase,
}
if s.hasWriteCache() {
components = append(components, s.writeCache)
}
for _, component := range components {
if err := component.Close(); err != nil {
return errors.Wrapf(err, "could not close %s", component)
}
}
return nil
}