From: Adam Kupczyk Date: Fri, 29 May 2026 11:16:39 +0000 (+0000) Subject: os/bluestore: Add printout to CBT's recovery-compare command X-Git-Tag: v21.0.1~8^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0970b2e1ac51e690f65b503e71dc539b6d4ca5ee;p=ceph.git os/bluestore: Add printout to CBT's recovery-compare command 1) recovery-compare prints on stdout 2) gracefully rejects comparing when multithreaded not enabled Signed-off-by: Adam Kupczyk --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index fde30a9499e..4629bc3b4c3 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -21168,7 +21168,7 @@ int BlueStore::read_allocation_from_drive_for_bluestore_tool() return ret; } -int BlueStore::compare_allocation_recovery_for_bluestore_tool() +int BlueStore::compare_allocation_recovery_for_bluestore_tool(ostream& out) { dout(5) << __func__ << dendl; int ret = 0; @@ -21189,13 +21189,14 @@ int BlueStore::compare_allocation_recovery_for_bluestore_tool() SimpleBitmap old_bitmap(cct, (bdev->get_size()/ min_alloc_size)); read_alloc_stats_t old_stats = {}; - ret = allocation_recover_and_compare(&old_bitmap, old_stats); + ret = allocation_recover_and_compare(&old_bitmap, old_stats, &out); return ret; } int BlueStore::allocation_recover_and_compare( SimpleBitmap *sbmap, - read_alloc_stats_t &stats) + read_alloc_stats_t &stats, + ostream* extra_out) { int ret = 0; SimpleBitmap& old_bitmap = *sbmap; @@ -21204,27 +21205,41 @@ int BlueStore::allocation_recover_and_compare( read_alloc_stats_t mt_stats = {}; utime_t start; utime_t duration; + ostringstream out; + auto flushl = [&]() { + dout(0) << out.str() << dendl; + if (extra_out) { + (*extra_out) << out.str() << std::endl; + std::flush(*extra_out); + } + out.str(""); + }; if (cct->_conf.get_val("bluestore_allocation_recovery_threads") != 0) { - dout(0) << "New recovery start" << dendl; + out << "New recovery start"; flushl(); start = ceph_clock_now(); ret = read_allocation_from_onodes_mt(&mt_bitmap, mt_stats); duration = ceph_clock_now() - start; - dout(0) << "New recovery result=" << ret << " took " << duration << " seconds" << dendl; - dout(0) << "New recovery stats=" << std::endl << mt_stats << dendl; + out << "New recovery result=" << ret << " took " << duration << " seconds"; flushl(); + out << "New recovery stats=" << std::endl << mt_stats; flushl(); } - dout(0) << "Legacy recovery start" << dendl; + out << "Legacy recovery start"; flushl(); start = ceph_clock_now(); ret = read_allocation_from_onodes(&old_bitmap, old_stats); duration = ceph_clock_now() - start; - dout(0) << "Legacy recovery result=" << ret << " took " << duration << " seconds" << dendl; - dout(0) << "Legacy recovery stats=" << std::endl << old_stats << dendl; + out << "Legacy recovery result=" << ret << " took " << duration << " seconds"; flushl(); + out << "Legacy recovery stats=" << std::endl << old_stats; flushl(); - if (old_stats.actual_pool_vstatfs == mt_stats.actual_pool_vstatfs) - dout(0) << "FSstats the same." << dendl; - else { - dout(0) << "FSTATS DIFFERENT !" << dendl; + if (cct->_conf.get_val("bluestore_allocation_recovery_threads") == 0) { + out << "bluestore_allocation_recovery_threads = 0"; flushl(); + out << "No multithread recovery to compare."; flushl(); + return 0; + } + if (old_stats.actual_pool_vstatfs == mt_stats.actual_pool_vstatfs) { + out << "FSstats the same."; flushl(); + } else { + out << "FSTATS DIFFERENT !"; flushl(); ret = -1; } @@ -21235,9 +21250,9 @@ int BlueStore::allocation_recover_and_compare( ext_a = mt_bitmap.get_next_set_extent(offset); ext_b = old_bitmap.get_next_set_extent(offset); if (ext_a != ext_b) { - dout(0) << "ALLOCATOR DIFFERENT !, first:" << dendl; - dout(0) << ext_a.offset << "~" << ext_a.length << dendl; - dout(0) << ext_b.offset << "~" << ext_b.length << dendl; + out << "ALLOCATOR DIFFERENT !, first:"; flushl(); + out << ext_a.offset << "~" << ext_a.length; flushl(); + out << ext_b.offset << "~" << ext_b.length; flushl(); offset = 1; ret = -1; break; @@ -21245,7 +21260,7 @@ int BlueStore::allocation_recover_and_compare( offset = ext_a.offset + ext_a.length; } while (offset != 0); if (offset == 0) { - dout(0) << "Allocators the same." << dendl; + out << "Allocators the same."; flushl(); } return ret; } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 9882949f11f..f7fba91227b 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -4115,7 +4115,7 @@ public: int push_allocation_to_rocksdb(); int read_allocation_from_drive_for_bluestore_tool(); #endif - int compare_allocation_recovery_for_bluestore_tool(); + int compare_allocation_recovery_for_bluestore_tool(std::ostream& out); void set_allocation_in_simple_bmap(SimpleBitmap* sbmap, uint64_t offset, uint64_t length); @@ -4135,7 +4135,10 @@ private: std::map actual_pool_vstatfs; volatile_statfs actual_store_vstatfs; }; - int allocation_recover_and_compare(SimpleBitmap *sbmap, read_alloc_stats_t &stats); + int allocation_recover_and_compare( + SimpleBitmap *sbmap, + read_alloc_stats_t &stats, + std::ostream* extra_out = nullptr); class Decoder_AllocationsAndStatFS; class ExtentDecoderPartial : public ExtentMap::ExtentDecoder { diff --git a/src/os/bluestore/bluestore_tool.cc b/src/os/bluestore/bluestore_tool.cc index e010f127aff..74aab7ce72c 100644 --- a/src/os/bluestore/bluestore_tool.cc +++ b/src/os/bluestore/bluestore_tool.cc @@ -720,7 +720,7 @@ int main(int argc, char **argv) cout << action << " bluestore compare new and legacy onode recovery" << std::endl; validate_path(cct.get(), path, false); BlueStore bluestore(cct.get(), path); - int r = bluestore.compare_allocation_recovery_for_bluestore_tool(); + int r = bluestore.compare_allocation_recovery_for_bluestore_tool(cout); if (r < 0) { cerr << action << " failed: " << cpp_strerror(r) << std::endl; exit(EXIT_FAILURE);