seaweedfs/weed/util/bptree
Chris Lu 8f2e4be074 wip
2021-09-18 14:04:30 -07:00
..
tree_store add memory kv store 2021-08-21 15:00:44 -07:00
bpmap.go split node based on the last inserted key 2021-09-18 01:29:47 -07:00
bptree.go split node based on the last inserted key 2021-09-18 01:29:47 -07:00
bptree.pb.go change value type to ItemValue 2021-08-21 15:52:17 -07:00
bptree.proto make proto node 2021-08-21 13:36:52 -07:00
bptree_node.go split node based on the last inserted key 2021-09-18 01:29:47 -07:00
bptree_store_test.go wip 2021-09-18 14:04:30 -07:00
bptree_test.go split node based on the last inserted key 2021-09-18 01:29:47 -07:00
getter_setter.go bptree does not work well for auto-increasing keys 2021-08-22 18:19:26 -07:00
int.go started by copying from https://sourcegraph.com/github.com/timtadh/data-structures@master/-/tree/tree/bptree 2021-08-20 01:12:52 -07:00
Makefile make proto node 2021-08-21 13:36:52 -07:00
rand.go started by copying from https://sourcegraph.com/github.com/timtadh/data-structures@master/-/tree/tree/bptree 2021-08-20 01:12:52 -07:00
README.md bptree does not work well for auto-increasing keys 2021-08-22 18:19:26 -07:00
serde.go wip 2021-09-18 14:04:30 -07:00
string.go started by copying from https://sourcegraph.com/github.com/timtadh/data-structures@master/-/tree/tree/bptree 2021-08-20 01:12:52 -07:00
types.go change key type to ItemKey 2021-08-21 15:54:42 -07:00

This adapts one b+ tree implementation https://sourcegraph.com/github.com/timtadh/data-structures@master/-/tree/tree/bptree to persist changes to on disk.

When a node needs to persist itself?

  • A node changed its key or value

    • When an item is added.
    • When an item is updated.
    • When an item is deleted.
  • When a node is split.

    • 2 new nodes are created (they shoud persist themselves).
    • Parent node need to point to the new nodes.
  • When a node is merged.

    • delete one node
    • persist the merged node

In general, if one node is returned from a function, the node should have already been persisted. The parent node may need to delete the old node.

BpTree Add(key ItemKey, value ItemValue) new_root = self.getRoot().put(key,value) a, b, err := self.insert(key, value) self.internal_insert(key, value) self.internal_split(q.keys[0], q) persist(a,b) self.persist() // child add q node self.maybePersist(child == p) self.leaf_insert(key, value) self.persist() // if dedup self.leaf_split(key, value) self.pure_leaf_split(key, value) persist(a,b) a.persist() persist(a,b) self.put_kv(key, value) new_root.persist() self.setRoot(new_root) oldroot.destroy() // maybe persist BpTree new root

Replace(key ItemKey, where WhereFunc, value ItemValue) leaf.persist() RemoveWhere(key ItemKey, where WhereFunc) self.getRoot().remove(key, where) self.internal_remove(key, nil, where) child.leaf_remove(key, nil, where) child.leaf_remove(key, sibling.keys[0], where) l.destroy() // when the node is empty a.maybePersist(hasChange) self.destroy() // when no keys left self.persist() // when some keys are left self.leaf_remove(key, self.keys[len(self.keys)-1], where) new_root.persist() // when new root is added // maybe persist BpTree new root