aboutsummaryrefslogtreecommitdiff
path: root/node.go
diff options
context:
space:
mode:
Diffstat (limited to 'node.go')
-rw-r--r--node.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/node.go b/node.go
index 11b5e2f..1460f52 100644
--- a/node.go
+++ b/node.go
@@ -161,10 +161,8 @@ func (n *node) write(p *page) {
// Initialize page.
if n.isLeaf {
p.flags |= p_leaf
- // warn("∑", p.id, "leaf")
} else {
p.flags |= p_branch
- // warn("∑", p.id, "branch")
}
p.count = uint16(len(n.inodes))
@@ -177,13 +175,11 @@ func (n *node) write(p *page) {
elem.pos = uint32(uintptr(unsafe.Pointer(&b[0])) - uintptr(unsafe.Pointer(elem)))
elem.ksize = uint32(len(item.key))
elem.vsize = uint32(len(item.value))
- // warn(" »", string(item.key), "->", string(item.value))
} else {
elem := p.branchPageElement(uint16(i))
elem.pos = uint32(uintptr(unsafe.Pointer(&b[0])) - uintptr(unsafe.Pointer(elem)))
elem.ksize = uint32(len(item.key))
elem.pgid = item.pgid
- // warn(" »", string(item.key))
}
// Write data for the element to the end of the page.
@@ -341,6 +337,26 @@ func (n *node) rebalance() {
n.parent.rebalance()
}
+// dereference causes the node to copy all its inode key/value references to heap memory.
+// This is required when the mmap is reallocated so inodes are not pointing to stale data.
+func (n *node) dereference() {
+ key := make([]byte, len(n.key))
+ copy(key, n.key)
+ n.key = key
+
+ for i, _ := range n.inodes {
+ inode := &n.inodes[i]
+
+ key := make([]byte, len(inode.key))
+ copy(key, inode.key)
+ inode.key = key
+
+ value := make([]byte, len(inode.value))
+ copy(value, inode.value)
+ inode.value = value
+ }
+}
+
// nodesByDepth sorts a list of branches by deepest first.
type nodesByDepth []*node