From 4df2123e9f0fd349193589e4f5d0958bb0413d43 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 21 Nov 2011 12:17:16 +0000 Subject: [PATCH] fix some btree bugs --- btree.tcc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/btree.tcc b/btree.tcc index 602fb3b..7726c9e 100644 --- a/btree.tcc +++ b/btree.tcc @@ -93,9 +93,12 @@ btree_detail::node_type node_ref::get_type() const { uint32_t flags = to_cpu(raw_->header.flags); - if (flags & INTERNAL_NODE) + if (flags & INTERNAL_NODE) { + if (flags & LEAF_NODE) + throw runtime_error("btree node is both internal and leaf"); return INTERNAL; - else if (flags & LEAF_NODE) + + } else if (flags & LEAF_NODE) return LEAF; else throw runtime_error("unknown node type"); @@ -108,11 +111,11 @@ node_ref::set_type(node_type t) uint32_t flags = to_cpu(raw_->header.flags); switch (t) { case INTERNAL: - flags |= INTERNAL_NODE; + flags = INTERNAL_NODE; break; case LEAF: - flags |= LEAF_NODE; + flags = LEAF_NODE; break; } raw_->header.flags = to_disk<__le32>(flags); @@ -602,6 +605,7 @@ split_beneath(btree_detail::shadow_spine &spine, // The parent may have changed value type, so we re-get it. internal_node p = spine.template get_node(); p.set_type(btree_detail::INTERNAL); + p.set_max_entries(); p.set_nr_entries(2); p.set_value_size(sizeof(typename uint64_traits::disk_type)); @@ -635,8 +639,9 @@ split_sibling(btree_detail::shadow_spine &spine, unsigned nr_right = l.get_nr_entries() - nr_left; r.set_nr_entries(0); + r.set_max_entries(); r.set_type(l.get_type()); - r.set_max_entries(l.get_max_entries()); + r.set_value_size(sizeof(typename ValueTraits::disk_type)); r.copy_entries(l, nr_left, nr_left + nr_right); l.set_nr_entries(nr_left);