@@ -6,6 +6,7 @@ package convert
66
77import (
88 "log/slog"
9+ "slices"
910 "time"
1011
1112 "github.com/thanos-io/thanos/pkg/block/metadata"
@@ -31,25 +32,23 @@ func (blc *BlockLineageChecker) IsRedundantConversion(
3132 parquetMetas map [string ]schema.Meta ,
3233) bool {
3334 blockULID := tsdbBlock .ULID .String ()
34-
35+
3536 // Check if this exact TSDB block has already been used as source for any parquet block
3637 for _ , parquetMeta := range parquetMetas {
37- for _ , sourceBlock := range parquetMeta .SourceBlocks {
38- if sourceBlock == blockULID {
39- blc .logger .Info ("Block already converted" ,
40- "tsdb_block" , blockULID ,
41- "parquet_block" , parquetMeta .Name ,
42- "day" , day .Format ("2006-01-02" ))
43- return true
44- }
38+ if slices .Contains (parquetMeta .SourceBlocks , blockULID ) {
39+ blc .logger .Info ("Block already converted" ,
40+ "tsdb_block" , blockULID ,
41+ "parquet_block" , parquetMeta .Name ,
42+ "day" , day .Format ("2006-01-02" ))
43+ return true
4544 }
4645 }
47-
46+
4847 // Check if this is a compacted block and its constituent blocks have been converted
4948 if len (tsdbBlock .BlockMeta .Compaction .Parents ) > 0 {
5049 return blc .isCompactedBlockRedundant (tsdbBlock , day , parquetMetas )
5150 }
52-
51+
5352 return false
5453}
5554
@@ -64,29 +63,29 @@ func (blc *BlockLineageChecker) isCompactedBlockRedundant(
6463 for _ , parent := range compactedBlock .BlockMeta .Compaction .Parents {
6564 parentULIDs [parent .ULID .String ()] = false // false = not found in parquet blocks
6665 }
67-
66+
6867 // Check if all parent blocks have been used as sources for parquet blocks
6968 // covering the same day
7069 dayStart := util .BeginOfDay (day )
7170 dayEnd := util .EndOfDay (day )
72-
71+
7372 for _ , parquetMeta := range parquetMetas {
7473 // Only consider parquet blocks that overlap with the day we're checking
7574 parquetStart := time .UnixMilli (parquetMeta .Mint )
7675 parquetEnd := time .UnixMilli (parquetMeta .Maxt )
77-
76+
7877 if parquetEnd .Before (dayStart ) || parquetStart .After (dayEnd ) {
7978 continue // No overlap with the day
8079 }
81-
80+
8281 // Mark any parent blocks found in this parquet block's sources
8382 for _ , sourceBlock := range parquetMeta .SourceBlocks {
8483 if _ , exists := parentULIDs [sourceBlock ]; exists {
8584 parentULIDs [sourceBlock ] = true
8685 }
8786 }
8887 }
89-
88+
9089 // Check if all parent blocks covering this day have been converted
9190 allParentsConverted := true
9291 for parentULID , found := range parentULIDs {
@@ -99,15 +98,15 @@ func (blc *BlockLineageChecker) isCompactedBlockRedundant(
9998 allParentsConverted = false
10099 }
101100 }
102-
101+
103102 if allParentsConverted && len (parentULIDs ) > 0 {
104103 blc .logger .Info ("Compacted block is redundant - all parent blocks already converted" ,
105104 "compacted_block" , compactedBlock .ULID .String (),
106105 "parent_count" , len (parentULIDs ),
107106 "day" , day .Format ("2006-01-02" ))
108107 return true
109108 }
110-
109+
111110 return false
112111}
113112
@@ -122,24 +121,21 @@ func (blc *BlockLineageChecker) GetConflictingParquetBlocks(
122121 blockULID := tsdbBlock .ULID .String ()
123122 dayStart := util .BeginOfDay (day )
124123 dayEnd := util .EndOfDay (day )
125-
124+
126125 for parquetName , parquetMeta := range parquetMetas {
127126 // Check if parquet block overlaps with the day
128127 parquetStart := time .UnixMilli (parquetMeta .Mint )
129128 parquetEnd := time .UnixMilli (parquetMeta .Maxt )
130-
129+
131130 if parquetEnd .Before (dayStart ) || parquetStart .After (dayEnd ) {
132131 continue // No overlap
133132 }
134-
133+
135134 // Check if this parquet block was created from the same TSDB block
136- for _ , sourceBlock := range parquetMeta .SourceBlocks {
137- if sourceBlock == blockULID {
138- conflicts = append (conflicts , parquetName )
139- break
140- }
135+ if slices .Contains (parquetMeta .SourceBlocks , blockULID ) {
136+ conflicts = append (conflicts , parquetName )
141137 }
142138 }
143-
139+
144140 return conflicts
145141}
0 commit comments