Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mmaped b+ tree #207

Merged
merged 27 commits into from
Oct 22, 2020
Merged

add mmaped b+ tree #207

merged 27 commits into from
Oct 22, 2020

Conversation

NamanJain8
Copy link
Contributor

@NamanJain8 NamanJain8 commented Oct 22, 2020

This PR adds a custom mmaped B+ tree. This data structure creates a mapping from uint64 to uint64.
Structure of node:
Each node in the node is of size pageSize. Two kinds of nodes. Leaf nodes and internal nodes.
Leaf nodes only contain the data. Internal nodes would contain the key and the offset to the child node.
Internal node would have first entry as:
<0 offset to child>, <1000 offset>, <5000 offset>, and so on...
Leaf nodes would just have: <key, value>, <key, value>, and so on...
Last 16 bytes of the node are off limits.
| pageID (8 bytes) | metaBits (1 byte) | 3 free bytes | numKeys (4 bytes) |


This change is Reviewable

@CLAassistant
Copy link

CLAassistant commented Oct 22, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Let's get this merged.

Reviewed 2 of 2 files at r6.
Reviewable status: 1 of 2 files reviewed, 6 unresolved discussions (waiting on @jarifibrahim, @manishrjain, @martinmr, and @NamanJain8)


z/btree.go, line 29 at r6 (raw file):

		nextPage: 1,
	}
	t.newNode(0)

Add a comment here saying that this is the root.


z/btree.go, line 31 at r6 (raw file):

	t.newNode(0)
	// This acts as the rightmost pointer (all the keys are <= this key).
	// This is necessary for B+ tree property that, all leaf nodes should

Remove comment about B+ tree property.


z/btree.go, line 64 at r6 (raw file):

func (t *Tree) Set(k, v uint64) {
	if k == math.MaxUint64 || k == 0 {
		panic("Does not support setting MaxUint64/Zero")

setting zero or MaxUint64.


z/btree.go, line 237 at r6 (raw file):

func (n node) uint32(start int) uint32 { return *(*uint32)(unsafe.Pointer(&n[start])) }

func keyOffset(i int) int        { return 16 * i }   // Last 16 bytes are kept off limits.

Remove this comment.


z/btree.go, line 292 at r6 (raw file):

1000


z/btree.go, line 334 at r6 (raw file):

		// If the value is non-zero, move the kv to left.
		// TODO(naman): Add test for second condition.
		if v != 0 || k == math.MaxUint64-1 {

Add a comment for this.

@NamanJain8 NamanJain8 merged commit 1d4870a into master Oct 22, 2020
@NamanJain8 NamanJain8 deleted the mrjn/btree branch October 22, 2020 18:06
Copy link
Contributor Author

@NamanJain8 NamanJain8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 6 unresolved discussions (waiting on @jarifibrahim, @manishrjain, @martinmr, and @NamanJain8)


z/btree.go, line 31 at r6 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Remove comment about B+ tree property.

Done.


z/btree.go, line 64 at r6 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

setting zero or MaxUint64.

Done.


z/btree.go, line 237 at r6 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Remove this comment.

Done.


z/btree.go, line 334 at r6 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Add a comment for this.

Not needed now.

@NamanJain8 NamanJain8 restored the mrjn/btree branch October 23, 2020 11:18
@manishrjain manishrjain deleted the mrjn/btree branch October 23, 2020 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants