MCPcopy
hub / github.com/grafana/tempo / Compact

Method Compact

tempodb/encoding/vparquet5/compactor.go:44–235  ·  view source on GitHub ↗
(ctx context.Context, l log.Logger, r backend.Reader, w backend.Writer, inputs []*backend.BlockMeta)

Source from the content-addressed store, hash-verified

42var pool = newRowPool(1_000_000)
43
44func (c *Compactor) Compact(ctx context.Context, l log.Logger, r backend.Reader, w backend.Writer, inputs []*backend.BlockMeta) (newCompactedBlocks []*backend.BlockMeta, err error) {
45 var (
46 compactionLevel uint32
47 totalRecords int64
48 minBlockStart time.Time
49 maxBlockEnd time.Time
50 bookmarks = make([]*bookmark[parquet.Row], 0, len(inputs))
51 )
52 for _, blockMeta := range inputs {
53 totalRecords += blockMeta.TotalObjects
54
55 if blockMeta.CompactionLevel > compactionLevel {
56 compactionLevel = blockMeta.CompactionLevel
57 }
58
59 if blockMeta.StartTime.Before(minBlockStart) || minBlockStart.IsZero() {
60 minBlockStart = blockMeta.StartTime
61 }
62 if blockMeta.EndTime.After(maxBlockEnd) {
63 maxBlockEnd = blockMeta.EndTime
64 }
65
66 block := newBackendBlock(blockMeta, r)
67
68 derivedCtx, span := tracer.Start(ctx, "vparquet.compactor.iterator")
69 defer span.End()
70
71 iter, err := block.rawIter(derivedCtx, pool)
72 if err != nil {
73 return nil, fmt.Errorf("error creating iterator for block %s: %w", blockMeta.BlockID.String(), err)
74 }
75
76 bookmarks = append(bookmarks, newBookmark(iter))
77 }
78
79 var (
80 replicationFactor = inputs[0].ReplicationFactor
81 nextCompactionLevel = compactionLevel + 1
82 sch, _, _ = SchemaWithDynamicChanges(inputs[0].DedicatedColumns)
83 )
84
85 // Dedupe rows and also call the metrics callback.
86 combine := func(rows []parquet.Row) (parquet.Row, error) {
87 if len(rows) == 0 {
88 return nil, nil
89 }
90
91 if len(rows) == 1 {
92 return rows[0], nil
93 }
94
95 isEqual := true
96 for i := 1; i < len(rows) && isEqual; i++ {
97 isEqual = rows[0].Equal(rows[i])
98 }
99 if isEqual {
100 for i := 1; i < len(rows); i++ {
101 pool.Put(rows[i])

Callers 3

benchmarkCompactorFunction · 0.95
BenchmarkCompactorDupesFunction · 0.95
TestCompactFunction · 0.95

Calls 15

ConsumeWithFinalMethod · 0.95
ResultMethod · 0.95
appendBlockMethod · 0.95
finishBlockMethod · 0.95
NewUUIDFunction · 0.92
SchemaWithDynamicChangesFunction · 0.85
DedupedSpansMethod · 0.80
newBackendBlockFunction · 0.70
newBookmarkFunction · 0.70
countSpansFunction · 0.70
NewCombinerFunction · 0.70

Tested by 3

benchmarkCompactorFunction · 0.76
BenchmarkCompactorDupesFunction · 0.76
TestCompactFunction · 0.76