Skip to content

TSDB: Simplify OOO Select by copying the head chunk#14396

Merged
bboreham merged 3 commits intoprometheus:mainfrom
bboreham:ooo-series-copies-headchunk
Jul 3, 2024
Merged

TSDB: Simplify OOO Select by copying the head chunk#14396
bboreham merged 3 commits intoprometheus:mainfrom
bboreham:ooo-series-copies-headchunk

Conversation

@bboreham
Copy link
Copy Markdown
Member

@bboreham bboreham commented Jul 2, 2024

Instead of carrying around extra fields in Meta structs which let us approximate what was in the chunk at the time, take a copy of the chunk.

This simplifies lots of code, and lets us correct a couple of tests which were embedding the wrong answer.

Fixes #11837

Instead of carrying around extra fields in `Meta` structs which let us
approximate what was in the chunk at the time, take a copy of the chunk.

This simplifies lots of code, and lets us correct a couple of tests which
were embedding the wrong answer.

Signed-off-by: Bryan Boreham <[email protected]>
@bboreham bboreham requested a review from jesusvazquez as a code owner July 2, 2024 17:22
@bboreham bboreham requested a review from codesome July 2, 2024 17:22
bboreham added 2 commits July 3, 2024 10:11
Signed-off-by: Bryan Boreham <[email protected]>
Was only used to constrain the OOO head chunk, which we now copy.

Signed-off-by: Bryan Boreham <[email protected]>
Copy link
Copy Markdown
Member Author

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

Notes for reviewers.

if headChunk && len(intervals) > 0 {
// Put the last interval in the head chunk
s1.ooo.oooHeadChunk = &oooHeadChunk{
chunk: NewOOOChunk(),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This avoids crashing on a nil pointer, but is still unrealistic since an OOO chunk with zero samples should not be created in the real code.

sample{t: minutes(25), f: float64(1)},
sample{t: minutes(26), f: float64(0)},
sample{t: minutes(30), f: float64(0)},
sample{t: minutes(32), f: float64(1)}, // This sample was added after Series() but before Chunk() and its in between the lastmint and maxt so it should be kept
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This behaviour was a bug - queries should not have results that vary depending on timing - so has been removed from the test.

sample{t: minutes(25), f: float64(1)},
sample{t: minutes(26), f: float64(0)},
sample{t: minutes(30), f: float64(0)},
sample{t: minutes(32), f: float64(1)}, // This sample was added after Series() but before Chunk() and its in between the lastmint and maxt so it should be kept
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This behaviour was a bug - queries should not have results that vary depending on timing - so has been removed from the test.

addChunk(c.minTime, c.maxTime, ref)
var xor chunkenc.Chunk
if len(c.chunk.samples) > 0 { // Empty samples happens in tests, at least.
xor, _ = c.chunk.ToXOR() // Ignoring error because it can't fail.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This could be ToXORBetweenTimestamps(oh.mint, oh.maxt), but I'll leave that change for a later PR.

}
iterable = chk
}
mc.chunkIterables = append(mc.chunkIterables, iterable)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Future optimization: collapse the case where len(mc.chunkIterables) ends up as 1.

@bboreham
Copy link
Copy Markdown
Member Author

bboreham commented Jul 3, 2024

/prombench main

@prombot
Copy link
Copy Markdown
Contributor

prombot commented Jul 3, 2024

⏱️ Welcome to Prometheus Benchmarking Tool. ⏱️

Compared versions: PR-14396 and main

After successful deployment, the benchmarking results can be viewed at:

Other Commands:
To stop benchmark: /prombench cancel
To restart benchmark: /prombench restart main

@bboreham
Copy link
Copy Markdown
Member Author

bboreham commented Jul 3, 2024

(PromBench doesn't generate any OOO data, but we might see an improvement from the smaller Meta structs)

Copy link
Copy Markdown
Member

@jesusvazquez jesusvazquez left a comment

Choose a reason for hiding this comment

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

LGTM

This is a nice simplification of the code, thanks for going through it 👍

@bboreham
Copy link
Copy Markdown
Member Author

bboreham commented Jul 3, 2024

No substantial differences seen in PromBench.

@bboreham
Copy link
Copy Markdown
Member Author

bboreham commented Jul 3, 2024

/prombench cancel

@prombot
Copy link
Copy Markdown
Contributor

prombot commented Jul 3, 2024

Benchmark cancel is in progress.

@bboreham bboreham merged commit 134e8dc into prometheus:main Jul 3, 2024
@bboreham bboreham deleted the ooo-series-copies-headchunk branch July 3, 2024 14:08
Comment on lines -511 to -513
// We can skip chunks that came in later than the last known OOOLastRef.
if chunkRef > meta.OOOLastRef {
break
Copy link
Copy Markdown
Member Author

@bboreham bboreham Aug 3, 2024

Choose a reason for hiding this comment

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

Removing this without any replacement introduced a bug. The symptom is worst in compaction, where it can fail seeing overlapping chunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify chunks.Meta by removing the OOO fields

3 participants