feat: cache generation and sequence to reduce TSM filename parsing#26905
feat: cache generation and sequence to reduce TSM filename parsing#26905davidby-influx merged 8 commits intomaster-1.xfrom
Conversation
Add `FileStore.SupportsCompactionPlanning()` which allows compaction planners to check if a `FileStore` supports compaction planning. Currently this means the `FileStore` must have a TSM filename parsing function available.
tsdb/engine/tsm1/reader.go
Outdated
| } | ||
| if t.parseFileNameFunc != nil { | ||
| if t.generation, t.sequence, err = t.parseFileNameFunc(path); err != nil { | ||
| return fmt.Errorf("failed parsing filename %q for generation and sequence numbers: %w", path, err) |
There was a problem hiding this comment.
This error adds context that the same error in NewTSMReader does not. I think the context here is redundant because the error from DefaultParseFileName (the only one we use) includes the filename.
I would remove the name from this context, but add that the parsing error occurred during TSMReader.Rename.
tsdb/engine/tsm1/reader.go
Outdated
| // that does not involve compaction planning, and was not created by the FileStore | ||
| t.generation, t.sequence, err = t.parseFileNameFunc(t.Path()) | ||
| if err != nil { | ||
| return nil, err |
There was a problem hiding this comment.
It might be a good idea to add context that the parse filename error occurred during the NewTSMReader call.
tsdb/engine/tsm1/reader.go
Outdated
| if t.parseFileNameFunc != nil { | ||
| if t.generation, t.sequence, err = t.parseFileNameFunc(path); err != nil { | ||
| return fmt.Errorf("failed parsing filename %q for generation and sequence numbers: %w", path, err) | ||
| } | ||
| } |
There was a problem hiding this comment.
We may even want to refactor this chunk of code into
tsdb/engine/tsm1/reader.go
Outdated
| if nil != t.parseFileNameFunc { | ||
| // If parseFileNameFunc is nil, we are in a test or another TSMReader use | ||
| // that does not involve compaction planning, and was not created by the FileStore | ||
| t.generation, t.sequence, err = t.parseFileNameFunc(t.Path()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } |
There was a problem hiding this comment.
We may want to refactor this chunk of code into it's own method, something like TSMReader.parseFileName. We repeat the same basic code twice and it might be nice to have a "safe" wrapper around parseFileNameFunc.
…26905) (#27189) Parse TSM file names only on creation or rename and cache the generation and level, instead of parsing them for those values repeatedly Fixes #26794 --------- (cherry picked from commit 8b1696a) Co-authored-by: davidby-influx <72418212+davidby-influx@users.noreply.github.com> Co-authored-by: Geoffrey Wossum <gwossum@influxdata.com>
Parsing TSM filenames for generation and level is a large CPU
cost in the compaction planner. Because these file names do
not change except through an explicit TSMReader.Rename()
call, we can cache generation and level on creation and
rename to avoid CPU load.
Fixes #26794