mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-27 05:32:27 -08:00
tsdb: drop deleted series from the WAL sooner (#12297)
`head.deleted` holds the WAL segment in use at the time each series was removed from the head. At the end of `truncateWAL()` we will delete all segments up to `last`, so we can drop any series that were last seen in a segment at or before that point. (same change in Prometheus Agent too) Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
0d049feac7
commit
0ab9553611
|
@ -665,7 +665,7 @@ func (db *DB) truncate(mint int64) error {
|
|||
}
|
||||
|
||||
seg, ok := db.deleted[id]
|
||||
return ok && seg >= first
|
||||
return ok && seg > last
|
||||
}
|
||||
|
||||
db.metrics.checkpointCreationTotal.Inc()
|
||||
|
@ -687,7 +687,7 @@ func (db *DB) truncate(mint int64) error {
|
|||
// The checkpoint is written and segments before it are truncated, so we
|
||||
// no longer need to track deleted series that were being kept around.
|
||||
for ref, segment := range db.deleted {
|
||||
if segment < first {
|
||||
if segment <= last {
|
||||
delete(db.deleted, ref)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1212,9 +1212,9 @@ func (h *Head) truncateWAL(mint int64) error {
|
|||
return true
|
||||
}
|
||||
h.deletedMtx.Lock()
|
||||
_, ok := h.deleted[id]
|
||||
keepUntil, ok := h.deleted[id]
|
||||
h.deletedMtx.Unlock()
|
||||
return ok
|
||||
return ok && keepUntil > last
|
||||
}
|
||||
h.metrics.checkpointCreationTotal.Inc()
|
||||
if _, err = wlog.Checkpoint(h.logger, h.wal, first, last, keep, mint); err != nil {
|
||||
|
@ -1235,7 +1235,7 @@ func (h *Head) truncateWAL(mint int64) error {
|
|||
// longer need to track deleted series that are before it.
|
||||
h.deletedMtx.Lock()
|
||||
for ref, segment := range h.deleted {
|
||||
if segment < first {
|
||||
if segment <= last {
|
||||
delete(h.deleted, ref)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue