2021-02-16 11:34:48 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-16 12:17:37 +00:00
|
|
|
"sync"
|
2021-02-16 11:34:48 +00:00
|
|
|
"time"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-02-16 11:34:48 +00:00
|
|
|
"go.uber.org/zap"
|
2023-03-17 08:06:15 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
minExpiredWorkers = 2
|
|
|
|
minExpiredBatchSize = 1
|
2021-02-16 11:34:48 +00:00
|
|
|
)
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
// TombstoneSource is an interface that checks
|
2023-02-05 15:59:38 +00:00
|
|
|
// tombstone status in the FrostFS network.
|
2022-04-19 18:00:22 +00:00
|
|
|
type TombstoneSource interface {
|
|
|
|
// IsTombstoneAvailable must return boolean value that means
|
2023-02-05 15:59:38 +00:00
|
|
|
// provided tombstone's presence in the FrostFS network at the
|
2022-04-19 18:00:22 +00:00
|
|
|
// time of the passed epoch.
|
2022-05-31 17:00:41 +00:00
|
|
|
IsTombstoneAvailable(ctx context.Context, addr oid.Address, epoch uint64) bool
|
2022-04-19 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
// Event represents class of external events.
|
|
|
|
type Event interface {
|
|
|
|
typ() eventType
|
|
|
|
}
|
|
|
|
|
|
|
|
type eventType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ eventType = iota
|
2021-02-16 17:32:46 +00:00
|
|
|
eventNewEpoch
|
2021-02-16 11:34:48 +00:00
|
|
|
)
|
|
|
|
|
2021-02-16 17:32:46 +00:00
|
|
|
type newEpoch struct {
|
|
|
|
epoch uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e newEpoch) typ() eventType {
|
|
|
|
return eventNewEpoch
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventNewEpoch returns new epoch event.
|
|
|
|
func EventNewEpoch(e uint64) Event {
|
|
|
|
return newEpoch{
|
|
|
|
epoch: e,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
type eventHandler func(context.Context, Event)
|
|
|
|
|
|
|
|
type eventHandlers struct {
|
2021-02-16 12:17:37 +00:00
|
|
|
prevGroup sync.WaitGroup
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
cancelFunc context.CancelFunc
|
|
|
|
|
|
|
|
handlers []eventHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
type gc struct {
|
|
|
|
*gcCfg
|
|
|
|
|
2021-11-11 13:54:36 +00:00
|
|
|
onceStop sync.Once
|
2021-08-04 12:04:37 +00:00
|
|
|
stopChannel chan struct{}
|
2022-10-25 06:08:18 +00:00
|
|
|
wg sync.WaitGroup
|
2021-08-04 12:04:37 +00:00
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
workerPool util.WorkerPool
|
|
|
|
|
|
|
|
remover func()
|
|
|
|
|
2022-09-26 06:30:41 +00:00
|
|
|
eventChan chan Event
|
2021-02-16 11:34:48 +00:00
|
|
|
mEventHandler map[eventType]*eventHandlers
|
|
|
|
}
|
|
|
|
|
|
|
|
type gcCfg struct {
|
|
|
|
removerInterval time.Duration
|
|
|
|
|
|
|
|
log *logger.Logger
|
|
|
|
|
|
|
|
workerPoolInit func(int) util.WorkerPool
|
2023-03-17 08:06:15 +00:00
|
|
|
|
|
|
|
expiredCollectorWorkersCount int
|
|
|
|
expiredCollectorBatchSize int
|
2021-02-16 11:34:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 12:07:38 +00:00
|
|
|
func defaultGCCfg() gcCfg {
|
|
|
|
return gcCfg{
|
2021-02-16 11:34:48 +00:00
|
|
|
removerInterval: 10 * time.Second,
|
2022-09-28 07:41:01 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
2021-02-16 11:34:48 +00:00
|
|
|
workerPoolInit: func(int) util.WorkerPool {
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-23 14:59:14 +00:00
|
|
|
func (gc *gc) init(ctx context.Context) {
|
2021-02-16 11:34:48 +00:00
|
|
|
sz := 0
|
|
|
|
|
|
|
|
for _, v := range gc.mEventHandler {
|
|
|
|
sz += len(v.handlers)
|
|
|
|
}
|
|
|
|
|
|
|
|
if sz > 0 {
|
|
|
|
gc.workerPool = gc.workerPoolInit(sz)
|
|
|
|
}
|
|
|
|
|
2022-10-25 06:08:18 +00:00
|
|
|
gc.wg.Add(2)
|
2021-02-16 11:34:48 +00:00
|
|
|
go gc.tickRemover()
|
2023-03-23 14:59:14 +00:00
|
|
|
go gc.listenEvents(ctx)
|
2021-02-16 11:34:48 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 14:59:14 +00:00
|
|
|
func (gc *gc) listenEvents(ctx context.Context) {
|
2022-10-25 06:08:18 +00:00
|
|
|
defer gc.wg.Done()
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
for {
|
2022-04-21 13:37:42 +00:00
|
|
|
event, ok := <-gc.eventChan
|
2021-02-16 11:34:48 +00:00
|
|
|
if !ok {
|
|
|
|
gc.log.Warn("stop event listener by closed channel")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
v, ok := gc.mEventHandler[event.typ()]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
v.cancelFunc()
|
2021-02-16 12:17:37 +00:00
|
|
|
v.prevGroup.Wait()
|
2021-02-16 11:34:48 +00:00
|
|
|
|
2023-04-03 16:15:13 +00:00
|
|
|
var runCtx context.Context
|
|
|
|
runCtx, v.cancelFunc = context.WithCancel(ctx)
|
2021-02-16 11:34:48 +00:00
|
|
|
|
2021-02-16 12:17:37 +00:00
|
|
|
v.prevGroup.Add(len(v.handlers))
|
|
|
|
|
2021-02-19 08:14:51 +00:00
|
|
|
for i := range v.handlers {
|
|
|
|
h := v.handlers[i]
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
err := gc.workerPool.Submit(func() {
|
2023-04-03 16:15:13 +00:00
|
|
|
h(runCtx, event)
|
2021-02-16 12:17:37 +00:00
|
|
|
v.prevGroup.Done()
|
2021-02-16 11:34:48 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
gc.log.Warn("could not submit GC job to worker pool",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
2021-02-16 12:17:37 +00:00
|
|
|
|
|
|
|
v.prevGroup.Done()
|
2021-02-16 11:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gc *gc) tickRemover() {
|
2022-10-25 06:08:18 +00:00
|
|
|
defer gc.wg.Done()
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
timer := time.NewTimer(gc.removerInterval)
|
|
|
|
defer timer.Stop()
|
|
|
|
|
|
|
|
for {
|
2021-08-04 12:04:37 +00:00
|
|
|
select {
|
|
|
|
case <-gc.stopChannel:
|
2021-10-19 13:34:34 +00:00
|
|
|
if gc.workerPool != nil {
|
|
|
|
gc.workerPool.Release()
|
|
|
|
}
|
2022-09-26 06:30:41 +00:00
|
|
|
|
|
|
|
close(gc.eventChan)
|
|
|
|
|
2021-08-04 12:04:37 +00:00
|
|
|
gc.log.Debug("GC is stopped")
|
|
|
|
return
|
|
|
|
case <-timer.C:
|
|
|
|
gc.remover()
|
|
|
|
timer.Reset(gc.removerInterval)
|
|
|
|
}
|
2021-02-16 11:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 12:04:37 +00:00
|
|
|
func (gc *gc) stop() {
|
2021-11-11 13:54:36 +00:00
|
|
|
gc.onceStop.Do(func() {
|
|
|
|
gc.stopChannel <- struct{}{}
|
|
|
|
})
|
2022-10-25 06:08:18 +00:00
|
|
|
|
|
|
|
gc.log.Info("waiting for GC workers to stop...")
|
|
|
|
gc.wg.Wait()
|
2021-08-04 12:04:37 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 14:19:31 +00:00
|
|
|
// iterates over metabase and deletes objects
|
2021-02-16 11:34:48 +00:00
|
|
|
// with GC-marked graves.
|
2021-12-27 11:04:07 +00:00
|
|
|
// Does nothing if shard is in "read-only" mode.
|
2021-02-16 11:34:48 +00:00
|
|
|
func (s *Shard) removeGarbage() {
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode != mode.ReadWrite {
|
2021-12-27 11:04:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
buf := make([]oid.Address, 0, s.rmBatchSize)
|
2021-02-16 11:34:48 +00:00
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterPrm meta.GarbageIterationPrm
|
|
|
|
iterPrm.SetHandler(func(g meta.GarbageObject) error {
|
2021-04-08 14:19:31 +00:00
|
|
|
buf = append(buf, g.Address())
|
2021-02-16 11:34:48 +00:00
|
|
|
|
2021-02-19 08:24:10 +00:00
|
|
|
if len(buf) == s.rmBatchSize {
|
|
|
|
return meta.ErrInterruptIterator
|
|
|
|
}
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// iterate over metabase's objects with GC mark
|
|
|
|
// (no more than s.rmBatchSize objects)
|
|
|
|
err := s.metaBase.IterateOverGarbage(iterPrm)
|
2021-02-16 11:34:48 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("iterator over metabase graveyard failed",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
} else if len(buf) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var deletePrm DeletePrm
|
2022-07-13 12:43:04 +00:00
|
|
|
deletePrm.SetAddresses(buf...)
|
2022-05-20 18:08:59 +00:00
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
// delete accumulated objects
|
2022-12-07 17:42:35 +00:00
|
|
|
_, err = s.delete(deletePrm)
|
2021-02-16 11:34:48 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("could not delete the objects",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:34:45 +00:00
|
|
|
|
2023-03-17 08:06:15 +00:00
|
|
|
func (s *Shard) getExpiredObjectsParameters() (workersCount, batchSize int) {
|
|
|
|
workersCount = minExpiredWorkers
|
|
|
|
batchSize = minExpiredBatchSize
|
|
|
|
|
|
|
|
if s.gc.gcCfg.expiredCollectorBatchSize > batchSize {
|
|
|
|
batchSize = s.gc.gcCfg.expiredCollectorBatchSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.gc.gcCfg.expiredCollectorWorkersCount > workersCount {
|
|
|
|
workersCount = s.gc.gcCfg.expiredCollectorWorkersCount
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-16 17:34:45 +00:00
|
|
|
func (s *Shard) collectExpiredObjects(ctx context.Context, e Event) {
|
2023-03-17 08:06:15 +00:00
|
|
|
workersCount, batchSize := s.getExpiredObjectsParameters()
|
|
|
|
|
|
|
|
errGroup, egCtx := errgroup.WithContext(ctx)
|
|
|
|
errGroup.SetLimit(workersCount)
|
|
|
|
|
|
|
|
errGroup.Go(func() error {
|
|
|
|
batch := make([]oid.Address, 0, batchSize)
|
|
|
|
err := s.getExpiredObjects(egCtx, e.(newEpoch).epoch, func(o *meta.ExpiredObject) {
|
|
|
|
if o.Type() != object.TypeTombstone && o.Type() != object.TypeLock {
|
|
|
|
batch = append(batch, o.Address())
|
|
|
|
|
|
|
|
if len(batch) == batchSize {
|
|
|
|
expired := batch
|
|
|
|
errGroup.Go(func() error {
|
|
|
|
s.handleExpiredObjects(egCtx, expired)
|
|
|
|
return egCtx.Err()
|
|
|
|
})
|
|
|
|
batch = make([]oid.Address, 0, batchSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-01-19 12:12:34 +00:00
|
|
|
if err != nil {
|
2023-03-17 08:06:15 +00:00
|
|
|
return err
|
2021-02-16 17:34:45 +00:00
|
|
|
}
|
2023-03-17 08:06:15 +00:00
|
|
|
|
|
|
|
if len(batch) > 0 {
|
|
|
|
expired := batch
|
|
|
|
errGroup.Go(func() error {
|
|
|
|
s.handleExpiredObjects(egCtx, expired)
|
|
|
|
return egCtx.Err()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err := errGroup.Wait(); err != nil {
|
|
|
|
s.log.Warn("iterator over expired objects failed", zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) handleExpiredObjects(ctx context.Context, expired []oid.Address) {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2021-02-16 17:34:45 +00:00
|
|
|
return
|
2023-03-17 08:06:15 +00:00
|
|
|
default:
|
2021-02-16 17:34:45 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-17 09:56:59 +00:00
|
|
|
expired, err := s.getExpiredWithLinked(expired)
|
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("failed to get expired objects with linked", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var inhumePrm meta.InhumePrm
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(expired...)
|
|
|
|
inhumePrm.SetGCMark()
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-16 17:34:45 +00:00
|
|
|
// inhume the collected objects
|
2022-09-09 11:36:34 +00:00
|
|
|
res, err := s.metaBase.Inhume(inhumePrm)
|
2021-02-16 17:34:45 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("could not inhume the objects",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2022-09-09 11:36:34 +00:00
|
|
|
|
|
|
|
s.decObjectCounterBy(logical, res.AvailableInhumed())
|
2023-02-02 20:28:42 +00:00
|
|
|
|
|
|
|
i := 0
|
|
|
|
for i < res.GetDeletionInfoLength() {
|
|
|
|
delInfo := res.GetDeletionInfoByIndex(i)
|
|
|
|
s.addToContainerSize(delInfo.CID.EncodeToString(), -int64(delInfo.Size))
|
|
|
|
i++
|
|
|
|
}
|
2023-05-17 09:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) getExpiredWithLinked(source []oid.Address) ([]oid.Address, error) {
|
|
|
|
result := make([]oid.Address, 0, len(source))
|
|
|
|
parentToChildren, err := s.metaBase.GetChildren(source)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for parent, children := range parentToChildren {
|
|
|
|
result = append(result, parent)
|
|
|
|
result = append(result, children...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2021-02-16 17:34:45 +00:00
|
|
|
}
|
2021-02-17 12:27:40 +00:00
|
|
|
|
|
|
|
func (s *Shard) collectExpiredTombstones(ctx context.Context, e Event) {
|
2022-04-19 18:00:22 +00:00
|
|
|
epoch := e.(newEpoch).epoch
|
|
|
|
log := s.log.With(zap.Uint64("epoch", epoch))
|
|
|
|
|
|
|
|
log.Debug("started expired tombstones handling")
|
|
|
|
|
|
|
|
const tssDeleteBatch = 50
|
|
|
|
tss := make([]meta.TombstonedObject, 0, tssDeleteBatch)
|
|
|
|
tssExp := make([]meta.TombstonedObject, 0, tssDeleteBatch)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterPrm meta.GraveyardIterationPrm
|
|
|
|
iterPrm.SetHandler(func(deletedObject meta.TombstonedObject) error {
|
2022-04-19 18:00:22 +00:00
|
|
|
tss = append(tss, deletedObject)
|
|
|
|
|
|
|
|
if len(tss) == tssDeleteBatch {
|
|
|
|
return meta.ErrInterruptIterator
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-03-10 17:58:58 +00:00
|
|
|
})
|
2022-04-19 18:00:22 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
log.Debug("iterating tombstones")
|
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
2022-10-26 06:12:09 +00:00
|
|
|
s.log.Debug("shard is in a degraded mode, skip collecting expired tombstones")
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RUnlock()
|
|
|
|
|
2022-10-26 06:12:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
err := s.metaBase.IterateOverGraveyard(iterPrm)
|
2022-01-19 12:12:34 +00:00
|
|
|
if err != nil {
|
2022-04-19 18:00:22 +00:00
|
|
|
log.Error("iterator over graveyard failed", zap.Error(err))
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RUnlock()
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
return
|
2022-01-19 12:12:34 +00:00
|
|
|
}
|
2022-04-19 18:00:22 +00:00
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RUnlock()
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
tssLen := len(tss)
|
|
|
|
if tssLen == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ts := range tss {
|
|
|
|
if !s.tsSource.IsTombstoneAvailable(ctx, ts.Tombstone(), epoch) {
|
|
|
|
tssExp = append(tssExp, ts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:18:21 +00:00
|
|
|
log.Debug("handling expired tombstones batch", zap.Int("number", len(tssExp)))
|
|
|
|
s.expiredTombstonesCallback(ctx, tssExp)
|
2022-04-19 18:00:22 +00:00
|
|
|
|
|
|
|
iterPrm.SetOffset(tss[tssLen-1].Address())
|
|
|
|
tss = tss[:0]
|
|
|
|
tssExp = tssExp[:0]
|
2022-01-19 12:12:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
log.Debug("finished expired tombstones handling")
|
2022-01-19 12:12:34 +00:00
|
|
|
}
|
2021-02-17 12:27:40 +00:00
|
|
|
|
2022-03-10 17:58:58 +00:00
|
|
|
func (s *Shard) collectExpiredLocks(ctx context.Context, e Event) {
|
2023-03-17 08:06:15 +00:00
|
|
|
workersCount, batchSize := s.getExpiredObjectsParameters()
|
|
|
|
|
|
|
|
errGroup, egCtx := errgroup.WithContext(ctx)
|
|
|
|
errGroup.SetLimit(workersCount)
|
|
|
|
|
|
|
|
errGroup.Go(func() error {
|
|
|
|
batch := make([]oid.Address, 0, batchSize)
|
|
|
|
|
|
|
|
err := s.getExpiredObjects(egCtx, e.(newEpoch).epoch, func(o *meta.ExpiredObject) {
|
|
|
|
if o.Type() == object.TypeLock {
|
|
|
|
batch = append(batch, o.Address())
|
|
|
|
|
|
|
|
if len(batch) == batchSize {
|
|
|
|
expired := batch
|
|
|
|
errGroup.Go(func() error {
|
2023-03-28 08:17:15 +00:00
|
|
|
s.expiredLocksCallback(egCtx, e.(newEpoch).epoch, expired)
|
2023-03-17 08:06:15 +00:00
|
|
|
return egCtx.Err()
|
|
|
|
})
|
|
|
|
batch = make([]oid.Address, 0, batchSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-03-10 17:58:58 +00:00
|
|
|
if err != nil {
|
2023-03-17 08:06:15 +00:00
|
|
|
return err
|
2022-03-10 17:58:58 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 08:06:15 +00:00
|
|
|
if len(batch) > 0 {
|
|
|
|
expired := batch
|
|
|
|
errGroup.Go(func() error {
|
2023-03-28 08:17:15 +00:00
|
|
|
s.expiredLocksCallback(egCtx, e.(newEpoch).epoch, expired)
|
2023-03-17 08:06:15 +00:00
|
|
|
return egCtx.Err()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err := errGroup.Wait(); err != nil {
|
|
|
|
s.log.Warn("iterator over expired locks failed", zap.String("error", err.Error()))
|
|
|
|
}
|
2022-03-10 17:58:58 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 08:06:15 +00:00
|
|
|
func (s *Shard) getExpiredObjects(ctx context.Context, epoch uint64, onExpiredFound func(*meta.ExpiredObject)) error {
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
2023-03-17 08:06:15 +00:00
|
|
|
return ErrDegradedMode
|
2022-10-26 06:12:09 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 12:27:40 +00:00
|
|
|
err := s.metaBase.IterateExpired(epoch, func(expiredObject *meta.ExpiredObject) error {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return meta.ErrInterruptIterator
|
|
|
|
default:
|
2023-03-17 08:06:15 +00:00
|
|
|
onExpiredFound(expiredObject)
|
2022-01-19 12:12:34 +00:00
|
|
|
return nil
|
2021-02-17 12:27:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-03-17 08:06:15 +00:00
|
|
|
return err
|
2021-02-17 12:27:40 +00:00
|
|
|
}
|
2023-03-17 08:06:15 +00:00
|
|
|
return ctx.Err()
|
2021-02-17 12:27:40 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 08:17:15 +00:00
|
|
|
func (s *Shard) selectExpired(ctx context.Context, epoch uint64, addresses []oid.Address) ([]oid.Address, error) {
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return nil, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.metaBase.FilterExpired(ctx, epoch, addresses)
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
// HandleExpiredTombstones marks tombstones themselves as garbage
|
|
|
|
// and clears up corresponding graveyard records.
|
2021-02-17 12:27:40 +00:00
|
|
|
//
|
|
|
|
// Does not modify tss.
|
2022-04-19 18:00:22 +00:00
|
|
|
func (s *Shard) HandleExpiredTombstones(tss []meta.TombstonedObject) {
|
2022-10-26 06:12:09 +00:00
|
|
|
if s.GetMode().NoMetabase() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
// Mark tombstones as garbage.
|
2021-10-14 13:23:21 +00:00
|
|
|
var pInhume meta.InhumePrm
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
tsAddrs := make([]oid.Address, 0, len(tss))
|
2022-04-19 18:00:22 +00:00
|
|
|
for _, ts := range tss {
|
|
|
|
tsAddrs = append(tsAddrs, ts.Tombstone())
|
2021-10-14 13:23:21 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
pInhume.SetGCMark()
|
|
|
|
pInhume.SetAddresses(tsAddrs...)
|
2021-10-14 13:23:21 +00:00
|
|
|
|
|
|
|
// inhume tombstones
|
2022-09-09 11:36:34 +00:00
|
|
|
res, err := s.metaBase.Inhume(pInhume)
|
2021-02-17 12:27:40 +00:00
|
|
|
if err != nil {
|
2021-10-14 13:23:21 +00:00
|
|
|
s.log.Warn("could not mark tombstones as garbage",
|
2021-02-17 12:27:40 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2022-04-19 18:00:22 +00:00
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
s.decObjectCounterBy(logical, res.AvailableInhumed())
|
|
|
|
|
2023-02-02 20:28:42 +00:00
|
|
|
i := 0
|
|
|
|
for i < res.GetDeletionInfoLength() {
|
|
|
|
delInfo := res.GetDeletionInfoByIndex(i)
|
|
|
|
s.addToContainerSize(delInfo.CID.EncodeToString(), -int64(delInfo.Size))
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
// drop just processed expired tombstones
|
|
|
|
// from graveyard
|
|
|
|
err = s.metaBase.DropGraves(tss)
|
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("could not drop expired grave records", zap.Error(err))
|
|
|
|
}
|
2021-02-17 12:27:40 +00:00
|
|
|
}
|
2022-03-10 17:58:58 +00:00
|
|
|
|
|
|
|
// HandleExpiredLocks unlocks all objects which were locked by lockers.
|
|
|
|
// If successful, marks lockers themselves as garbage.
|
2023-03-28 08:17:15 +00:00
|
|
|
func (s *Shard) HandleExpiredLocks(ctx context.Context, epoch uint64, lockers []oid.Address) {
|
2022-10-26 06:12:09 +00:00
|
|
|
if s.GetMode().NoMetabase() {
|
|
|
|
return
|
|
|
|
}
|
2023-03-28 08:17:15 +00:00
|
|
|
unlocked, err := s.metaBase.FreeLockedBy(lockers)
|
2022-03-10 17:58:58 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("failure to unlock objects",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var pInhume meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
pInhume.SetAddresses(lockers...)
|
2023-03-28 08:17:15 +00:00
|
|
|
pInhume.SetForceGCMark()
|
2022-03-10 17:58:58 +00:00
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
res, err := s.metaBase.Inhume(pInhume)
|
2022-03-10 17:58:58 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("failure to mark lockers as garbage",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2022-09-09 11:36:34 +00:00
|
|
|
|
|
|
|
s.decObjectCounterBy(logical, res.AvailableInhumed())
|
2023-02-02 20:28:42 +00:00
|
|
|
|
|
|
|
i := 0
|
|
|
|
for i < res.GetDeletionInfoLength() {
|
|
|
|
delInfo := res.GetDeletionInfoByIndex(i)
|
|
|
|
s.addToContainerSize(delInfo.CID.EncodeToString(), -int64(delInfo.Size))
|
|
|
|
i++
|
|
|
|
}
|
2023-03-28 08:17:15 +00:00
|
|
|
|
|
|
|
s.inhumeUnlockedIfExpired(ctx, epoch, unlocked)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) inhumeUnlockedIfExpired(ctx context.Context, epoch uint64, unlocked []oid.Address) {
|
|
|
|
expiredUnlocked, err := s.selectExpired(ctx, epoch, unlocked)
|
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("failure to get expired unlocked objects", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(expiredUnlocked) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s.handleExpiredObjects(ctx, expiredUnlocked)
|
2022-03-10 17:58:58 +00:00
|
|
|
}
|
2022-05-26 17:38:32 +00:00
|
|
|
|
|
|
|
// HandleDeletedLocks unlocks all objects which were locked by lockers.
|
|
|
|
func (s *Shard) HandleDeletedLocks(lockers []oid.Address) {
|
2022-10-26 06:12:09 +00:00
|
|
|
if s.GetMode().NoMetabase() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-28 08:17:15 +00:00
|
|
|
_, err := s.metaBase.FreeLockedBy(lockers)
|
2022-05-26 17:38:32 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("failure to unlock objects",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2022-09-26 06:30:41 +00:00
|
|
|
|
|
|
|
// NotificationChannel returns channel for shard events.
|
|
|
|
func (s *Shard) NotificationChannel() chan<- Event {
|
|
|
|
return s.gc.eventChan
|
|
|
|
}
|