Skip to content

[MSD benchmark] Annotations: Split cleanup into separate queries and deletes to avoid deadlocks on MySQL#7

Open
khaliqgant wants to merge 16 commits into
msd-benchmark-base/grafana/pr-80329from
msd-benchmark/grafana/pr-80329
Open

[MSD benchmark] Annotations: Split cleanup into separate queries and deletes to avoid deadlocks on MySQL#7
khaliqgant wants to merge 16 commits into
msd-benchmark-base/grafana/pr-80329from
msd-benchmark/grafana/pr-80329

Conversation

@khaliqgant

Copy link
Copy Markdown

MSD benchmark PR recreated from Martian Code Review Bench.

Source PR: grafana#80329
Dataset: grafana
Original title: Annotations: Split cleanup into separate queries and deletes to avoid deadlocks on MySQL

What is this feature?

Writes to annotations are sometimes rejected on MySQL due to a recurring deadlock with the annotation cleanup job.
Details here: grafana#64979

Why do we need this feature?

The deadlock seems to be a result of the subquery, under normal circumstances a plain insert and delete should not lock, and there are no extended transactions at play.

This PR splits the subquery into a separate SQL statement. These statements do not share a transaction, and therefore allow locks to flush in between.

Unfortunately we could not reduce this to a single DELETE statement, due to the batching - DELETE LIMIT is not supported on all databases without needing to reintroduce the subquery. The IDs loaded into memory are of bounded size due to the batch size configuration.

Which issue(s) does this PR fix?:

grafana#64979

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@khaliqgant khaliqgant changed the base branch from main to msd-benchmark-base/grafana/pr-80329 May 15, 2026 14:57
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.

3 participants