Skip to content

fix: prune raw metrics through the timestamp index, not a rowid anchor - #22

Merged
masseselsev merged 1 commit into
masterfrom
fix/retention-anchor-seek
Sep 18, 2026
Merged

masseselsev merged 1 commit into
masterfrom
fix/retention-anchor-seek

Conversation

@masseselsev

Copy link
Copy Markdown
Owner

Live evidence (0.3.36): Metric retention pass failed … select interface_metrics prune anchor: context deadline exceeded with deleted=258 — the hourly prune never clears the upgrade backlog. The anchor query (max(id) WHERE timestamp < cutoff) is an unindexable full scan of the old rows; the batched DELETE under it is fine. Fix: drop the anchor, let the batch subselect seek the timestamp index directly (EXPLAIN shows COVERING INDEX + rowid point deletes). Also removes the id↔time ordering assumption — the configurable-retention test (seeds old rows after fresh ones) fails against a binary-search anchor and passes here.

The per-batch anchor (max(id) below the cutoff) cannot use any index: it rescans every old row, and on the live router's multi-million-row backlog it consumed the 5-minute prune deadline after deleting only 258 rows — retention never caught up. Each batch now selects its rowids directly with 'timestamp < ? LIMIT n', which the timestamp index answers in O(batch), and the predicate no longer assumes insertion order matches time (the configurable-retention test seeds fresh-then-old rows and caught the anchor's binary-search variant doing exactly that).
@masseselsev
masseselsev merged commit 3b80a8d into master Sep 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant