From c22886df2eb2a599a072095d0a0dffd339ad77d0 Mon Sep 17 00:00:00 2001 From: Aditya Gurajada Date: Thu, 12 Jan 2023 16:41:13 -0800 Subject: [PATCH] (#533) Add print fn to print branch BTrees under trunk node. - Introduce trunk_print_branch_btrees() to walk the root-addresses of branch BTree nodes for a given trunk node, and to invoke the BTree print methods on each such branch. The top-level BTree root node is being printed right, but upon recursing down, we are running into an unallocated page error. allocator_page_valid() is consistently failing for all sub-trees under root branch BTree. --- src/trunk.c | 42 ++++++++++++++++++++++++++++++++++++-- src/trunk.h | 6 ++++++ tests/unit/splinter_test.c | 3 +++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/trunk.c b/src/trunk.c index 2a08539ff..6a37a9229 100644 --- a/src/trunk.c +++ b/src/trunk.c @@ -2964,7 +2964,10 @@ trunk_get_memtable(trunk_handle *spl, uint64 generation) { uint64 memtable_idx = generation % TRUNK_NUM_MEMTABLES; memtable *mt = &spl->mt_ctxt->mt[memtable_idx]; - platform_assert(mt->generation == generation); + platform_assert((mt->generation == generation), + "mt->generation=%lu, generation=%lu\n", + mt->generation, + generation); return mt; } @@ -8140,7 +8143,7 @@ trunk_print_node(platform_log_handle *log_handle, * trunk_print_subtree() -- * * Print the Trunk node at given 'addr'. Iterate down to all its children and - * print each sub-tree. + * print each trunk sub-tree. */ void trunk_print_subtree(platform_log_handle *log_handle, @@ -8910,6 +8913,41 @@ trunk_print_branches(platform_log_handle *log_handle, trunk_handle *spl) trunk_for_each_node(spl, trunk_node_print_branches, log_handle); } +/* + * Print all the branch BTrees hanging off of input trunk node 'addr'. + */ +void +trunk_print_branch_btrees(trunk_handle *spl, uint64 addr, void *arg) +{ + platform_log_handle *log_handle = (platform_log_handle *)arg; + trunk_node node; + trunk_node_get(spl->cc, addr, &node); + + uint16 start_branch = trunk_start_branch(spl, &node); + uint16 end_branch = trunk_end_branch(spl, &node); + + platform_log(log_handle, + "\n**** Print all BTree branches under " + "Trunk node addr=%lu ****\n{\n\n", + addr); + for (uint16 branch_no = start_branch; branch_no != end_branch; + branch_no = trunk_add_branch_number(spl, branch_no, 1)) + { + uint64 bt_addr = trunk_get_branch(spl, &node, branch_no)->root_addr; + platform_log(log_handle, + "Trunk node addr=%lu, Branch number %u" + ", BTree root addr=%lu\n{\n", + addr, + branch_no, + bt_addr); + btree_print_tree(log_handle, spl->cc, trunk_btree_config(spl), bt_addr); + platform_log(log_handle, "\n}\n"); + } + + trunk_node_unget(spl->cc, &node); + platform_log(log_handle, "\n}\n"); +} + // bool // trunk_node_print_extent_count(trunk_handle *spl, // uint64 addr, diff --git a/src/trunk.h b/src/trunk.h index 4320d9f75..8c0466239 100644 --- a/src/trunk.h +++ b/src/trunk.h @@ -406,10 +406,16 @@ trunk_print_lookup(trunk_handle *spl, platform_log_handle *log_handle); void trunk_print_branches(platform_log_handle *log_handle, trunk_handle *spl); + void trunk_print_extent_counts(platform_log_handle *log_handle, trunk_handle *spl); + +void +trunk_print_branch_btrees(trunk_handle *spl, uint64 addr, void *arg); + void trunk_print_space_use(platform_log_handle *log_handle, trunk_handle *spl); + bool trunk_verify_tree(trunk_handle *spl); diff --git a/tests/unit/splinter_test.c b/tests/unit/splinter_test.c index 9d66168c7..73b037a84 100644 --- a/tests/unit/splinter_test.c +++ b/tests/unit/splinter_test.c @@ -664,6 +664,9 @@ CTEST2(splinter, test_splinter_print_diags) CTEST_LOG_INFO("\n** trunk_print() **\n"); trunk_print(Platform_default_log_handle, spl); + CTEST_LOG_INFO("\n** trunk_print_branch_btrees() on Trunk root node **\n"); + trunk_print_branch_btrees(spl, spl->root_addr, Platform_default_log_handle); + CTEST_LOG_INFO("\n** Allocator stats **\n"); allocator_print_stats(alp); allocator_print_allocated(alp);