Skip to content

Commit

Permalink
storage/spanlatch: catch identical upper bound on recomputation durin…
Browse files Browse the repository at this point in the history
…g removal

This change modifies `adjustUpperBoundOnRemoval` to avoid a degenerate
case in element removal where all intervals have the same end key. In
this case, we would previously adjust the upper bound of every node from
the root of the tree to the node that the interval was being removed
from. We now check whether removing the element with the largest end key
is actually changing the upper bound of the node. If there are other
elements with the same end key then this is not the case and we can
avoid repeat calls to `adjustUpperBoundOnRemoval` while traversing back
up the tree.

This came up while profiling a benchmark that was giving suprising
results.

Release note: None
  • Loading branch information
nvanbenschoten committed Nov 22, 2018
1 parent 681ae97 commit 148cb30
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/storage/spanlatch/interval_btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,9 @@ func (n *node) adjustUpperBoundOnRemoval(la *latch, child *node) bool {
}
}
if n.max.compare(up) == 0 {
// up was previous upper bound of n.
n.max = n.findUpperBound()
return true
return n.max.compare(up) != 0
}
return false
}
Expand Down

0 comments on commit 148cb30

Please sign in to comment.