MCPcopy
hub / github.com/prometheus/prometheus / CompactBlockMetas

Function CompactBlockMetas

tsdb/compact.go:441–481  ·  view source on GitHub ↗

CompactBlockMetas merges many block metas into one, combining its source blocks together and adjusting compaction level. Min/Max time of result block meta covers all input blocks.

(uid ulid.ULID, blocks ...*BlockMeta)

Source from the content-addressed store, hash-verified

439// CompactBlockMetas merges many block metas into one, combining its source blocks together
440// and adjusting compaction level. Min/Max time of result block meta covers all input blocks.
441func CompactBlockMetas(uid ulid.ULID, blocks ...*BlockMeta) *BlockMeta {
442 res := &BlockMeta{
443 ULID: uid,
444 }
445
446 sources := map[ulid.ULID]struct{}{}
447 mint := blocks[0].MinTime
448 maxt := blocks[0].MaxTime
449
450 for _, b := range blocks {
451 if b.MinTime < mint {
452 mint = b.MinTime
453 }
454 if b.MaxTime > maxt {
455 maxt = b.MaxTime
456 }
457 if b.Compaction.Level > res.Compaction.Level {
458 res.Compaction.Level = b.Compaction.Level
459 }
460 for _, s := range b.Compaction.Sources {
461 sources[s] = struct{}{}
462 }
463 res.Compaction.Parents = append(res.Compaction.Parents, BlockDesc{
464 ULID: b.ULID,
465 MinTime: b.MinTime,
466 MaxTime: b.MaxTime,
467 })
468 }
469 res.Compaction.Level++
470
471 for s := range sources {
472 res.Compaction.Sources = append(res.Compaction.Sources, s)
473 }
474 slices.SortFunc(res.Compaction.Sources, func(a, b ulid.ULID) int {
475 return a.Compare(b)
476 })
477
478 res.MinTime = mint
479 res.MaxTime = maxt
480 return res
481}
482
483// Compact creates a new block in the compactor's directory from the blocks in the
484// provided directories.

Callers 2

TestCompactBlockMetasFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestCompactBlockMetasFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…