forked from TrueCloudLab/frostfs-node
[#378] shard: Collect expired non-tombstone objects in GC every epoch
Add new epoch event handler to GC that finds all expired non-tombstone objects and marks them to be removed. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
89a22450e5
commit
dab45050b9
2 changed files with 60 additions and 3 deletions
|
@ -42,7 +42,14 @@ func (s *Shard) Init() error {
|
||||||
gc := &gc{
|
gc := &gc{
|
||||||
gcCfg: s.gcCfg,
|
gcCfg: s.gcCfg,
|
||||||
remover: s.removeGarbage,
|
remover: s.removeGarbage,
|
||||||
mEventHandler: map[eventType]*eventHandlers{},
|
mEventHandler: map[eventType]*eventHandlers{
|
||||||
|
eventNewEpoch: {
|
||||||
|
cancelFunc: func() {},
|
||||||
|
handlers: []eventHandler{
|
||||||
|
s.collectExpiredObjects,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
gc.init()
|
gc.init()
|
||||||
|
|
|
@ -186,3 +186,53 @@ func (s *Shard) removeGarbage() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Shard) collectExpiredObjects(ctx context.Context, e Event) {
|
||||||
|
epoch := e.(newEpoch).epoch
|
||||||
|
|
||||||
|
var expired []*object.Address
|
||||||
|
|
||||||
|
// collect expired non-tombstone object
|
||||||
|
err := s.metaBase.IterateExpired(epoch, func(expiredObject *meta.ExpiredObject) error {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return meta.ErrInterruptIterator
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if expiredObject.Type() != object.TypeTombstone {
|
||||||
|
expired = append(expired, expiredObject.Address())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
s.log.Warn("iterator over expired objects failed",
|
||||||
|
zap.String("error", err.Error()),
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
} else if len(expired) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if context canceled
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
// inhume the collected objects
|
||||||
|
_, err = s.metaBase.Inhume(new(meta.InhumePrm).
|
||||||
|
WithAddresses(expired...).
|
||||||
|
WithGCMark(),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
s.log.Warn("could not inhume the objects",
|
||||||
|
zap.String("error", err.Error()),
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue