Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #539 from benbjohnson/rebalance-fix
Browse files Browse the repository at this point in the history
Fix rebalance bug
  • Loading branch information
benbjohnson committed Mar 22, 2016
2 parents 7cb1534 + c093484 commit 6204c54
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,43 +463,6 @@ func (n *node) rebalance() {
target = n.prevSibling()
}

// If target node has extra nodes then just move one over.
if target.numChildren() > target.minKeys() {
if useNextSibling {
// Reparent and move node.
if child, ok := n.bucket.nodes[target.inodes[0].pgid]; ok {
child.parent.removeChild(child)
child.parent = n
child.parent.children = append(child.parent.children, child)
}
n.inodes = append(n.inodes, target.inodes[0])
target.inodes = target.inodes[1:]

// Update target key on parent.
target.parent.put(target.key, target.inodes[0].key, nil, target.pgid, 0)
target.key = target.inodes[0].key
_assert(len(target.key) > 0, "rebalance(1): zero-length node key")
} else {
// Reparent and move node.
if child, ok := n.bucket.nodes[target.inodes[len(target.inodes)-1].pgid]; ok {
child.parent.removeChild(child)
child.parent = n
child.parent.children = append(child.parent.children, child)
}
n.inodes = append(n.inodes, inode{})
copy(n.inodes[1:], n.inodes)
n.inodes[0] = target.inodes[len(target.inodes)-1]
target.inodes = target.inodes[:len(target.inodes)-1]
}

// Update parent key for node.
n.parent.put(n.key, n.inodes[0].key, nil, n.pgid, 0)
n.key = n.inodes[0].key
_assert(len(n.key) > 0, "rebalance(2): zero-length node key")

return
}

// If both this node and the target node are too small then merge them.
if useNextSibling {
// Reparent all child nodes being moved.
Expand Down

0 comments on commit 6204c54

Please sign in to comment.