Skip to content

Commit b3183ae

Browse files
committed
add symdb write closer option
1 parent 93f66db commit b3183ae

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

pkg/experiment/block/compaction.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"io"
78
"os"
89
"slices"
910
"sort"
@@ -547,13 +548,16 @@ func newSymbolsRewriter() *symbolsRewriter {
547548
buf: buf,
548549
rw: make(map[*Dataset]*symdb.Rewriter),
549550
w: symdb.NewSymDB(&symdb.Config{
550-
Version: symdb.FormatV3,
551-
Writer: buf,
552-
NoStatsUpdate: true,
551+
Version: symdb.FormatV3,
552+
Writer: &nopWriteCloser{buf},
553553
}),
554554
}
555555
}
556556

557+
type nopWriteCloser struct{ io.Writer }
558+
559+
func (*nopWriteCloser) Close() error { return nil }
560+
557561
func (s *symbolsRewriter) rewriteRow(e ProfileEntry) (err error) {
558562
rw := s.rewriterFor(e.Dataset)
559563
e.Row.ForStacktraceIDsValues(func(values []parquet.Value) {

pkg/experiment/query_backend/query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (q *blockContext) lookupDatasets() error {
208208
return q.obj.ReadMetadata(ctx)
209209
})
210210
g.Go(func() error {
211-
return ds.Open(q.ctx, block.SectionTSDB)
211+
return ds.Open(ctx, block.SectionTSDB)
212212
})
213213
if err := g.Wait(); err != nil {
214214
return err

pkg/phlaredb/symdb/block_writer_v3.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func newEncodersV3() encodersV3 {
6363

6464
func (w *writerV3) writePartitions(partitions []*PartitionWriter) (err error) {
6565
if dst := w.config.Writer; dst != nil {
66+
defer func() {
67+
_ = w.config.Writer.Close()
68+
}()
6669
return w.writePartitionsWithWriter(withWriterOffset(dst), partitions)
6770
}
6871
if err = os.MkdirAll(w.config.Dir, 0o755); err != nil {
@@ -74,7 +77,7 @@ func (w *writerV3) writePartitions(partitions []*PartitionWriter) (err error) {
7477
return err
7578
}
7679
defer func() {
77-
err = f.Close()
80+
_ = f.Close()
7881
w.files = []block.File{f.meta()}
7982
}()
8083
return w.writePartitionsWithWriter(f.w, partitions)

pkg/phlaredb/symdb/symdb.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,22 @@ type SymDB struct {
9797
}
9898

9999
type Config struct {
100-
Dir string
101-
Version FormatVersion
102-
Stacktraces StacktracesConfig
103-
Parquet ParquetConfig
104-
NoStatsUpdate bool
105-
Writer io.Writer // V3 only.
106-
}
100+
Version FormatVersion
101+
// Output writer. Optional, V3 only.
102+
Writer io.WriteCloser
107103

108-
type StacktracesConfig struct {
109104
// DEPRECATED: the parameter is not used and
110105
// will be removed in the future versions.
106+
Dir string
107+
// DEPRECATED: the parameter is not used and
108+
// will be removed in the future versions.
109+
Stacktraces StacktracesConfig
110+
// DEPRECATED: the parameter is not used and
111+
// will be removed in the future versions.
112+
Parquet ParquetConfig
113+
}
114+
115+
type StacktracesConfig struct {
111116
MaxNodesPerChunk uint32
112117
}
113118

@@ -169,10 +174,8 @@ func NewSymDB(c *Config) *SymDB {
169174
db.config.Version = FormatV2
170175
db.writer = newWriterV2(c)
171176
}
172-
if !c.NoStatsUpdate {
173-
db.wg.Add(1)
174-
go db.updateStatsLoop()
175-
}
177+
db.wg.Add(1)
178+
go db.updateStatsLoop()
176179
return db
177180
}
178181

0 commit comments

Comments
 (0)