[#1445] shard/gc: Remove graves
Some checks failed
Vulncheck / Vulncheck (pull_request) Successful in 3m6s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m35s
Tests and linters / gopls check (pull_request) Successful in 4m0s
Tests and linters / Run gofumpt (pull_request) Successful in 6m26s
DCO action / DCO (pull_request) Successful in 6m59s
Build / Build Components (pull_request) Successful in 7m56s
Tests and linters / Staticcheck (pull_request) Successful in 8m0s
Tests and linters / Lint (pull_request) Successful in 9m14s
Tests and linters / Tests with -race (pull_request) Failing after 12m32s
Tests and linters / Tests (pull_request) Failing after 16m43s

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-12-18 12:37:02 +03:00
parent 6bc49eb741
commit 42681223d0
Signed by: a-savchuk
GPG key ID: 70C0A7FF6F9C4639

View file

@ -534,9 +534,12 @@ func (s *Shard) collectExpiredGraves(ctx context.Context, e Event) {
log.Debug(ctx, logs.ShardStartedExpiredTombstonesHandling) log.Debug(ctx, logs.ShardStartedExpiredTombstonesHandling)
defer log.Debug(ctx, logs.ShardFinishedExpiredTombstonesHandling) defer log.Debug(ctx, logs.ShardFinishedExpiredTombstonesHandling)
// TODO(@a-savchuk): Magic number. Should it be configurable? Same way
// it's done for handling expired objects: batch size and worker count.
const tssDeleteBatch = 50 const tssDeleteBatch = 50
tss := make([]meta.TombstonedObject, 0, tssDeleteBatch) tss := make([]meta.TombstonedObject, 0, tssDeleteBatch)
tssExp := make([]meta.TombstonedObject, 0, tssDeleteBatch) expiredGravesWithExpEpoch := make([]meta.TombstonedObject, 0, tssDeleteBatch)
expiredGravesWithoutExpEpoch := make([]meta.TombstonedObject, 0, tssDeleteBatch)
var iterPrm meta.GraveyardIterationPrm var iterPrm meta.GraveyardIterationPrm
iterPrm.SetHandler(func(deletedObject meta.TombstonedObject) error { iterPrm.SetHandler(func(deletedObject meta.TombstonedObject) error {
@ -577,22 +580,41 @@ func (s *Shard) collectExpiredGraves(ctx context.Context, e Event) {
} }
for _, ts := range tss { for _, ts := range tss {
if !s.tsSource.IsTombstoneAvailable(ctx, ts.Tombstone(), epoch) { if ts.ExpirationEpoch() != meta.NoExpirationEpoch {
tssExp = append(tssExp, ts) expiredGravesWithExpEpoch = append(expiredGravesWithExpEpoch, ts)
} else if !s.tsSource.IsTombstoneAvailable(ctx, ts.Tombstone(), epoch) {
expiredGravesWithoutExpEpoch = append(expiredGravesWithoutExpEpoch, ts)
} }
} }
log.Debug(ctx, logs.ShardHandlingExpiredTombstonesBatch, zap.Int("number", len(tssExp))) log.Debug(ctx, logs.ShardHandlingExpiredTombstonesBatch,
if len(tssExp) > 0 { zap.Int("with exp. epoch", len(expiredGravesWithExpEpoch)),
s.expiredGravesCallback(ctx, tssExp) zap.Int("without exp. epoch", len(expiredGravesWithoutExpEpoch)),
} )
s.handleExpiredGraves(ctx, expiredGravesWithExpEpoch, expiredGravesWithoutExpEpoch)
iterPrm.SetOffset(tss[tssLen-1].Address()) iterPrm.SetOffset(tss[tssLen-1].Address())
tss = tss[:0] tss = tss[:0]
tssExp = tssExp[:0] expiredGravesWithExpEpoch = expiredGravesWithExpEpoch[:0]
expiredGravesWithoutExpEpoch = expiredGravesWithoutExpEpoch[:0]
} }
} }
func (s *Shard) handleExpiredGraves(ctx context.Context,
expiredWithExpEpoch []meta.TombstonedObject, expiredWithoutExpEpoch []meta.TombstonedObject,
) {
if len(expiredWithExpEpoch) > 0 {
s.removeGraves(ctx, expiredWithExpEpoch)
}
if len(expiredWithoutExpEpoch) > 0 {
s.expiredGravesCallback(ctx, expiredWithoutExpEpoch)
}
}
func (s *Shard) removeGraves(_ context.Context, _ []meta.TombstonedObject) {
}
func (s *Shard) getExpiredObjects(ctx context.Context, epoch uint64, onExpiredFound func(*meta.ExpiredObject)) error { func (s *Shard) getExpiredObjects(ctx context.Context, epoch uint64, onExpiredFound func(*meta.ExpiredObject)) error {
s.m.RLock() s.m.RLock()
defer s.m.RUnlock() defer s.m.RUnlock()