Skip to content

tsdb: fix grow/shrink nextIndex calculation#17863

Merged
krajorama merged 1 commit intoprometheus:mainfrom
juliusmh:jmh/fix_tsdb_exemplar_grow_shrink
Jan 14, 2026
Merged

tsdb: fix grow/shrink nextIndex calculation#17863
krajorama merged 1 commit intoprometheus:mainfrom
juliusmh:jmh/fix_tsdb_exemplar_grow_shrink

Conversation

@juliusmh
Copy link
Contributor

@juliusmh juliusmh commented Jan 14, 2026

As was pointed out by AI on a mimir PR, there is a bug when calculating the nextIndex during exemplar buffer grow/shrink operations. When the buffer is not full, nextIndex is calculated based on the non-empty entries only, which is incorrect. We have to include all entries to get the valid position in the buffer.

This PR changes copyExemplarRanges to return two values: totalCopied and migratedEntries (non-empty). It also adds two new test cases that grow and shrink non-full buffers (which fail without the fix).

The original comment: grafana/mimir#14009 (comment)

Which issue(s) does the PR fix:

n/a

Does this PR introduce a user-facing change?

[BUGFIX] Fix a bug during exemplar buffer grow/shrink that could cause exemplars to be incorrectly discarded.

Signed-off-by: Julius Hinze <julius.hinze@grafana.com>
@juliusmh juliusmh force-pushed the jmh/fix_tsdb_exemplar_grow_shrink branch from 61a11e4 to a073a9a Compare January 14, 2026 14:59
Copy link
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@krajorama krajorama enabled auto-merge (squash) January 14, 2026 15:25
@krajorama krajorama merged commit ccb7468 into prometheus:main Jan 14, 2026
58 of 59 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.

2 participants