-
Notifications
You must be signed in to change notification settings - Fork 703
Compact symdb #2136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Compact symdb #2136
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b4b4e86
Add stacktrace rewriter
kolesnikovae 21a11b1
Fixes
kolesnikovae e7d4145
Add lookup table test
kolesnikovae 8c74e3a
Symbols reader integration
kolesnikovae 129ffec
Add SymbolsResolver.WriteStats
kolesnikovae b8f5509
Fix lookup table
kolesnikovae 9bf7151
Add symbols writer
kolesnikovae 4c3841f
Load symdb block files at compaction
kolesnikovae 030e8f0
Update pkg/iter/tree.go
cyriltovena c05dd18
Fix meta samples stats
kolesnikovae 4926461
Add dedup slice append
kolesnikovae a299f91
Cleanup
kolesnikovae ddcb3c8
Convert locations to stacktrace
kolesnikovae bd4ae92
Implement symdb Reader.Load
kolesnikovae 8b33efc
Fix stacktrace inserter
kolesnikovae 60ba14d
Fix symdb meta
kolesnikovae e4290de
Fix lint issues
kolesnikovae 5a04b99
Fix symbols rewriter integration
kolesnikovae 756d883
Remove unused rowNum field
kolesnikovae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package phlaredb | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/grafana/pyroscope/pkg/iter" | ||
| schemav1 "github.com/grafana/pyroscope/pkg/phlaredb/schemas/v1" | ||
| "github.com/grafana/pyroscope/pkg/phlaredb/symdb" | ||
| ) | ||
|
|
||
| // TODO(kolesnikovae): Refactor to symdb. | ||
|
|
||
| type SymbolsReader interface { | ||
| SymbolsResolver(partition uint64) (SymbolsResolver, error) | ||
| } | ||
|
|
||
| type SymbolsResolver interface { | ||
| ResolveStacktraces(ctx context.Context, dst symdb.StacktraceInserter, stacktraces []uint32) error | ||
|
|
||
| Locations(iter.Iterator[uint32]) iter.Iterator[*schemav1.InMemoryLocation] | ||
| Mappings(iter.Iterator[uint32]) iter.Iterator[*schemav1.InMemoryMapping] | ||
| Functions(iter.Iterator[uint32]) iter.Iterator[*schemav1.InMemoryFunction] | ||
| Strings(iter.Iterator[uint32]) iter.Iterator[string] | ||
|
|
||
| WriteStats(*symdb.Stats) | ||
| } | ||
|
|
||
| type inMemorySymbolsReader struct { | ||
| partitions map[uint64]*inMemorySymbolsResolver | ||
|
|
||
| // TODO(kolesnikovae): Split into partitions. | ||
| strings inMemoryparquetReader[string, *schemav1.StringPersister] | ||
| functions inMemoryparquetReader[*schemav1.InMemoryFunction, *schemav1.FunctionPersister] | ||
| locations inMemoryparquetReader[*schemav1.InMemoryLocation, *schemav1.LocationPersister] | ||
| mappings inMemoryparquetReader[*schemav1.InMemoryMapping, *schemav1.MappingPersister] | ||
| stacktraces StacktraceDB | ||
| } | ||
|
|
||
| func (r *inMemorySymbolsReader) SymbolsResolver(partition uint64) (SymbolsResolver, error) { | ||
| p, ok := r.partitions[partition] | ||
| if !ok { | ||
| p = &inMemorySymbolsResolver{ | ||
| partition: partition, | ||
| reader: r, | ||
| } | ||
| r.partitions[partition] = p | ||
| } | ||
| return p, nil | ||
| } | ||
|
|
||
| type inMemorySymbolsResolver struct { | ||
| partition uint64 | ||
| reader *inMemorySymbolsReader | ||
| } | ||
|
|
||
| func (s inMemorySymbolsResolver) ResolveStacktraces(ctx context.Context, dst symdb.StacktraceInserter, stacktraces []uint32) error { | ||
| return s.reader.stacktraces.Resolve(ctx, s.partition, dst, stacktraces) | ||
| } | ||
|
|
||
| func (s inMemorySymbolsResolver) Locations(i iter.Iterator[uint32]) iter.Iterator[*schemav1.InMemoryLocation] { | ||
| return iter.NewSliceIndexIterator(s.reader.locations.cache, i) | ||
| } | ||
|
|
||
| func (s inMemorySymbolsResolver) Mappings(i iter.Iterator[uint32]) iter.Iterator[*schemav1.InMemoryMapping] { | ||
| return iter.NewSliceIndexIterator(s.reader.mappings.cache, i) | ||
| } | ||
|
|
||
| func (s inMemorySymbolsResolver) Functions(i iter.Iterator[uint32]) iter.Iterator[*schemav1.InMemoryFunction] { | ||
| return iter.NewSliceIndexIterator(s.reader.functions.cache, i) | ||
| } | ||
|
|
||
| func (s inMemorySymbolsResolver) Strings(i iter.Iterator[uint32]) iter.Iterator[string] { | ||
| return iter.NewSliceIndexIterator(s.reader.strings.cache, i) | ||
| } | ||
|
|
||
| func (s inMemorySymbolsResolver) WriteStats(stats *symdb.Stats) { | ||
| s.reader.stacktraces.WriteStats(s.partition, stats) | ||
| stats.LocationsTotal = len(s.reader.locations.cache) | ||
| stats.MappingsTotal = len(s.reader.mappings.cache) | ||
| stats.FunctionsTotal = len(s.reader.functions.cache) | ||
| stats.StringsTotal = len(s.reader.strings.cache) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package phlaredb | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path/filepath" | ||
|
|
||
| schemav1 "github.com/grafana/pyroscope/pkg/phlaredb/schemas/v1" | ||
| "github.com/grafana/pyroscope/pkg/phlaredb/symdb" | ||
| ) | ||
|
|
||
| // TODO(kolesnikovae): Refactor to symdb. | ||
|
|
||
| type SymbolsWriter interface { | ||
| SymbolsAppender(partition uint64) (SymbolsAppender, error) | ||
| } | ||
|
|
||
| type SymbolsAppender interface { | ||
| AppendStacktraces([]uint32, []*schemav1.Stacktrace) | ||
| AppendLocations([]uint32, []*schemav1.InMemoryLocation) | ||
| AppendMappings([]uint32, []*schemav1.InMemoryMapping) | ||
| AppendFunctions([]uint32, []*schemav1.InMemoryFunction) | ||
| AppendStrings([]uint32, []string) | ||
| } | ||
|
|
||
| type symbolsWriter struct { | ||
| partitions map[uint64]*symbolsAppender | ||
|
|
||
| locations deduplicatingSlice[*schemav1.InMemoryLocation, locationsKey, *locationsHelper, *schemav1.LocationPersister] | ||
| mappings deduplicatingSlice[*schemav1.InMemoryMapping, mappingsKey, *mappingsHelper, *schemav1.MappingPersister] | ||
| functions deduplicatingSlice[*schemav1.InMemoryFunction, functionsKey, *functionsHelper, *schemav1.FunctionPersister] | ||
| strings deduplicatingSlice[string, string, *stringsHelper, *schemav1.StringPersister] | ||
| tables []Table | ||
|
|
||
| symdb *symdb.SymDB | ||
| } | ||
|
|
||
| func newSymbolsWriter(dst string, cfg *ParquetConfig) (*symbolsWriter, error) { | ||
| w := symbolsWriter{ | ||
| partitions: make(map[uint64]*symbolsAppender), | ||
| } | ||
| dir := filepath.Join(dst, symdb.DefaultDirName) | ||
| w.symdb = symdb.NewSymDB(symdb.DefaultConfig().WithDirectory(dir)) | ||
| w.tables = []Table{ | ||
| &w.locations, | ||
| &w.mappings, | ||
| &w.functions, | ||
| &w.strings, | ||
| } | ||
| for _, t := range w.tables { | ||
| if err := t.Init(dst, cfg, contextHeadMetrics(context.Background())); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| return &w, nil | ||
| } | ||
|
|
||
| func (w *symbolsWriter) SymbolsAppender(partition uint64) (SymbolsAppender, error) { | ||
| p, ok := w.partitions[partition] | ||
| if !ok { | ||
| appender := w.symdb.SymbolsAppender(partition) | ||
| x := &symbolsAppender{ | ||
| stacktraces: appender.StacktraceAppender(), | ||
| writer: w, | ||
| } | ||
| w.partitions[partition] = x | ||
| p = x | ||
| } | ||
| return p, nil | ||
| } | ||
|
|
||
| func (w *symbolsWriter) Close() error { | ||
| for _, t := range w.tables { | ||
| _, _, err := t.Flush(context.Background()) | ||
| if err != nil { | ||
| return fmt.Errorf("flushing table %s: %w", t.Name(), err) | ||
| } | ||
| if err = t.Close(); err != nil { | ||
| return fmt.Errorf("closing table %s: %w", t.Name(), err) | ||
| } | ||
| } | ||
| if err := w.symdb.Flush(); err != nil { | ||
| return fmt.Errorf("flushing symbol database: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| type symbolsAppender struct { | ||
| stacktraces symdb.StacktraceAppender | ||
| writer *symbolsWriter | ||
| } | ||
|
|
||
| func (s symbolsAppender) AppendStacktraces(dst []uint32, stacktraces []*schemav1.Stacktrace) { | ||
| s.stacktraces.AppendStacktrace(dst, stacktraces) | ||
| } | ||
|
|
||
| func (s symbolsAppender) AppendLocations(dst []uint32, locations []*schemav1.InMemoryLocation) { | ||
| s.writer.locations.append(dst, locations) | ||
| } | ||
|
|
||
| func (s symbolsAppender) AppendMappings(dst []uint32, mappings []*schemav1.InMemoryMapping) { | ||
| s.writer.mappings.append(dst, mappings) | ||
| } | ||
|
|
||
| func (s symbolsAppender) AppendFunctions(dst []uint32, functions []*schemav1.InMemoryFunction) { | ||
| s.writer.functions.append(dst, functions) | ||
| } | ||
|
|
||
| func (s symbolsAppender) AppendStrings(dst []uint32, strings []string) { | ||
| s.writer.strings.append(dst, strings) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compacting v1 stacktraces might be a bit challenging. It is easy if a source block is compacted entirely, when we read all of its profiles sequentially. However, in practice I guess we will need to filter based on time and series which changes the access pattern to random access.
@cyriltovena what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we don't compact v1.