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

Rebalance after deletion. #19

Merged
merged 1 commit into from
Feb 9, 2014
Merged

Conversation

benbjohnson
Copy link
Member

Overview

Added rebalancing which will combine pages as needed after a key is removed. I also refactored the node type to allow sibling traversal.

How it works

Rebalancing follows some fairly simple rules:

  1. A node is a candidate for rebalancing if it is below a "fill threshold" (25%) or it doesn't have the minimum required number of keys (1 for leafs, 2 for branches).
  2. If the node is the root node and it's a branch with only one key then collapse the child so it becomes the new root.
  3. If the adjacent node has more than enough keys then just move one over.
  4. If the adjacent node doesn't have more than the minimum number of keys then merge the two nodes. The reference to one of the nodes will be removed from the parent which will trigger a rebalance on that node.

Caveats

Currently deletion seems to be dog slow. Not sure why yet but I haven't profiled it yet. Also, I added C-style assertion statements that I'm going to remove before the release. It just helps to track down dumb bugs during development.

@benbjohnson
Copy link
Member Author

/cc: @snormore

benbjohnson added a commit that referenced this pull request Feb 9, 2014
@benbjohnson benbjohnson merged commit 768c529 into boltdb:master Feb 9, 2014
@benbjohnson benbjohnson deleted the rebalance branch February 9, 2014 20:48
@benbjohnson
Copy link
Member Author

Fixes #9.

heyitsanthony pushed a commit to heyitsanthony/bolt that referenced this pull request Aug 11, 2017
do not read freelist if database opened readonly
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant