fix: filter deleted entries

Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com>
This commit is contained in:
x1unix 2026-04-07 09:58:10 -04:00
parent 3bf8f550b9
commit ecaee0923c
No known key found for this signature in database
GPG key ID: 9A37F16B8645A398
2 changed files with 8 additions and 4 deletions

View file

@ -777,7 +777,7 @@ func (db *DB) truncate(mint int64) error {
AtIndex: last,
BatchSize: db.opts.CheckpointBatchSize,
ActiveSeries: db.series.Iterate(),
DeletedSeries: deletedSeriesIter(db.deleted),
DeletedSeries: deletedSeriesIter(db.deleted, last),
})
} else {
_, err = wlog.Checkpoint(db.logger, db.wal, first, last, db.keepSeriesInWALCheckpointFn(last), mint, db.opts.EnableSTStorage)

View file

@ -384,11 +384,15 @@ func (s *stripeSeries) Iterate() iter.Seq[ActiveSeries] {
}
// deletedSeriesIter returns an iterator over deleted series from the given map.
func deletedSeriesIter(m map[chunks.HeadSeriesRef]deletedRefMeta) iter.Seq[DeletedSeries] {
// Only series whose lastSegment is greater than last are emitted, matching the
// filtering behaviour of [wlog.Checkpoint] keep function.
func deletedSeriesIter(m map[chunks.HeadSeriesRef]deletedRefMeta, last int) iter.Seq[DeletedSeries] {
return func(yield func(DeletedSeries) bool) {
for ref, meta := range m {
if !yield(deletedSeries{ref: ref, labels: meta.labels}) {
return
if meta.lastSegment > last {
if !yield(deletedSeries{ref: ref, labels: meta.labels}) {
return
}
}
}
}