Skip to content

Commit

Permalink
keyviz: support to merge cold logical range
Browse files Browse the repository at this point in the history
Signed-off-by: Zheng Xiangsheng <hundundm@gmail.com>
  • Loading branch information
HunDunDM committed Jul 13, 2020
1 parent 5af71fe commit 264451a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/keyvisual/matrix/axis.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,61 @@ func (c *chunk) Focus(strategy Strategy, threshold uint64, ratio int, target int
}
generateBucket(len(c.Values))

newChunk := createChunk(newKeys, newValues)
if len(newValues) >= target*2 {
newChunk = newChunk.MergeColdLogicalRange(strategy, threshold, target)
}
return newChunk
}

func (c *chunk) MergeColdLogicalRange(strategy Strategy, threshold uint64, target int) chunk {
threshold /= 4 // TODO: This var can be adjusted

newKeys := make([]string, 0, target)
newValues := make([]uint64, 0, target)
newKeys = append(newKeys, c.Keys[0])

coldStart := 0
coldEnd := 0
var coldRangeSum uint64 = 0
mergeColdRange := func() {
if coldEnd <= coldStart {
return
}
newKeys = append(newKeys, c.Keys[coldEnd])
newValues = append(newValues, coldRangeSum)
coldStart = coldEnd
coldRangeSum = 0
}
generateRange := func(end int) {
if end <= coldEnd {
return
}
var rangeSum uint64 = 0
for i := coldEnd; i < end; i++ {
rangeSum += c.Values[i]
}
if coldRangeSum > threshold || rangeSum > threshold {
mergeColdRange()
}
if rangeSum > threshold {
newKeys = append(newKeys, c.Keys[coldEnd+1:end+1]...)
newValues = append(newValues, c.Values[coldEnd:end]...)
coldStart = end
} else {
coldRangeSum += rangeSum
}
coldEnd = end
}

for i := range c.Values {
if strategy.CrossBorder(c.Keys[i], c.Keys[i+1]) {
generateRange(i + 1)
}
}
generateRange(len(c.Values))
mergeColdRange()

return createChunk(newKeys, newValues)
}

Expand Down

0 comments on commit 264451a

Please sign in to comment.