Skip to content

Commit

Permalink
fixes a bug in storage/segment get method
Browse files Browse the repository at this point in the history
  • Loading branch information
petethepig committed Jan 19, 2021
1 parent fc44cea commit 47ebbd9
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions pkg/storage/segment/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,12 @@ func (sn *streeNode) get(st, et time.Time, cb func(sn *streeNode, d int, t time.
if sn.present && (rel == contain || rel == match) {
cb(sn, sn.depth, sn.time, big.NewRat(1, 1))
} else if rel != outside { // inside or overlap
if sn.present {
// in this case some of the query area might be covered by children
// Consider a case like this:
// S E
// *_|_|_|_|_|x|x|_|_|_*_|_|_|_|_|_|_|_|_|_*
// ^-------sn----------^
// Legend:
// S/E - start and end time
// _ - children are missing
// x - children present
// * - current node (sn) bounds
//
// in this case uncoveredAmount = 6/10
// 6 because that's how many children are missing and fit between S and E
// 10 is how many children are in the node
uncoveredAmount := big.NewRat(0, 1)
for i, v := range sn.children {
if v != nil {
v.get(st, et, cb)
} else {
childT := sn.time.Truncate(durations[sn.depth]).Add(time.Duration(i) * durations[sn.depth-1])
childOverlap := overlapRead(childT, childT.Add(durations[sn.depth-1]), st, et, durations[0])
uncoveredAmount.Add(uncoveredAmount, childOverlap)
}
}
if uncoveredAmount.Num().Int64() != 0 {
cb(sn, sn.depth, sn.time, uncoveredAmount)
}
if sn.present && len(sn.children) == 0 {
// TODO: I did not test this logic as extensively as I would love to.
// See https://github.com/pyroscope-io/pyroscope/issues/28 for more context and ideas on what to do
cb(sn, sn.depth, sn.time, sn.overlapRead(st, et))
} else {
// if current node doesn't have a tree present, defer to children
// if current node doesn't have a tree present or has children, defer to children
for _, v := range sn.children {
if v != nil {
v.get(st, et, cb)
Expand Down

0 comments on commit 47ebbd9

Please sign in to comment.