2021-02-19 11:36:21 +05:30
|
|
|
#ifndef DBG_BTREE_NODE_DUMPER
|
|
|
|
#define DBG_BTREE_NODE_DUMPER
|
|
|
|
|
|
|
|
#include "dbg-lib/block_dumper.h"
|
|
|
|
#include "dbg-lib/simple_show_traits.h"
|
|
|
|
#include "persistent-data/data-structures/btree.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace dbg {
|
|
|
|
using persistent_data::block_manager;
|
|
|
|
using persistent_data::btree_detail::node_ref;
|
|
|
|
|
|
|
|
template <typename ShowTraits>
|
|
|
|
class btree_node_dumper : public block_dumper {
|
|
|
|
public:
|
|
|
|
virtual void show(block_manager::read_ref &rr, std::ostream &out) {
|
|
|
|
node_ref<uint64_traits> n = btree_detail::to_node<uint64_traits>(rr);
|
|
|
|
if (n.get_type() == INTERNAL)
|
2021-02-20 22:19:53 +05:30
|
|
|
btree_node_dumper<uint64_show_traits>::show_node(n, out);
|
2021-02-19 11:36:21 +05:30
|
|
|
else {
|
|
|
|
node_ref<typename ShowTraits::value_trait> n = btree_detail::to_node<typename ShowTraits::value_trait>(rr);
|
2021-02-20 22:19:53 +05:30
|
|
|
show_node(n, out);
|
2021-02-19 11:36:21 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 22:19:53 +05:30
|
|
|
static void show_node(node_ref<typename ShowTraits::value_trait> n, std::ostream &out) {
|
2021-02-19 11:36:21 +05:30
|
|
|
formatter::ptr f = create_xml_formatter();
|
|
|
|
|
|
|
|
field(*f, "csum", n.get_checksum());
|
|
|
|
field(*f, "blocknr", n.get_block_nr());
|
|
|
|
field(*f, "type", n.get_type() == INTERNAL ? "internal" : "leaf");
|
|
|
|
field(*f, "nr_entries", n.get_nr_entries());
|
|
|
|
field(*f, "max_entries", n.get_max_entries());
|
|
|
|
field(*f, "value_size", n.get_value_size());
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < n.get_nr_entries(); i++) {
|
|
|
|
formatter::ptr f2 = create_xml_formatter();
|
|
|
|
field(*f2, "key", n.key_at(i));
|
2021-02-20 22:19:53 +05:30
|
|
|
ShowTraits::show(f2, "value", n.value_at(i));
|
2021-02-19 11:36:21 +05:30
|
|
|
f->child(boost::lexical_cast<std::string>(i), f2);
|
|
|
|
}
|
|
|
|
|
|
|
|
f->output(out, 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename ShowTraits>
|
|
|
|
block_dumper::ptr
|
|
|
|
create_btree_node_dumper() {
|
|
|
|
return block_dumper::ptr(new btree_node_dumper<ShowTraits>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|