From: Adam Kupczyk Date: Tue, 19 May 2026 19:36:37 +0000 (+0000) Subject: os/bluestore: Add bluestore_debug_fast_recovery_compare_chance X-Git-Tag: v21.0.1~8^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4138fcf7b49d74dd6c2d49780ee6ca352c70e50f;p=ceph.git os/bluestore: Add bluestore_debug_fast_recovery_compare_chance The setting is used for testing purposes only. It allows to force compare if required, or set chance to use in teuthology thrash tests. Signed-off-by: Adam Kupczyk --- diff --git a/src/common/options/global.yaml.in b/src/common/options/global.yaml.in index 3460267c155..8e375df59d4 100644 --- a/src/common/options/global.yaml.in +++ b/src/common/options/global.yaml.in @@ -5388,6 +5388,19 @@ options: - startup see_also: - bluestore_allocation_from_file +- name: bluestore_debug_fast_recovery_compare_chance + type: float + level: dev + desc: For testing only. Compare legacy and multithread allocation recovery. + long_desc: Chance to perform compare between procedures. + Value in range <0..1>; defines chance to perform comparision between legacy + and multithreaded allocation recovery. 0 means never compare. 1 means always compare. + default: 0 + with_legacy: false + flags: + - startup + see_also: + - bluestore_allocation_recovery_threads - name: bluestore_debug_inject_allocation_from_file_failure type: float level: dev diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 3a64fb42b50..fde30a9499e 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include "common/dout.h" +#include "include/ceph_assert.h" #include "include/cpp-btree/btree_set.h" #include "BlueStore.h" @@ -20883,22 +20885,40 @@ int BlueStore::read_allocation_from_onodes(SimpleBitmap *sbmap, read_alloc_stats //--------------------------------------------------------- int BlueStore::reconstruct_allocations(SimpleBitmap *sbmap, read_alloc_stats_t &stats) { - // first set space used by superblock - auto super_length = std::max(min_alloc_size, SUPER_RESERVED); - set_allocation_in_simple_bmap(sbmap, 0, super_length); - stats.extent_count++; - - // then set all space taken by Objects int ret; + double chance = cct->_conf.get_val("bluestore_debug_fast_recovery_compare_chance"); if (cct->_conf.get_val("bluestore_allocation_recovery_threads") == 0) { - ret = read_allocation_from_onodes(sbmap, stats); + // do not compare if multithread is disabled + chance = 0; + } + double roll = 0; + if (chance > 0) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_real_distribution<> dis(0.0, 1.0); + roll = dis(gen); + } + + // first set all space taken by Objects + if (chance > 0 && chance > roll) { + ret = allocation_recover_and_compare(sbmap, stats); + ceph_assert((ret == 0) && "comparing allocator recovery failed"); } else { - ret = read_allocation_from_onodes_mt(sbmap, stats); + if (cct->_conf.get_val("bluestore_allocation_recovery_threads") == 0) { + ret = read_allocation_from_onodes(sbmap, stats); + } else { + ret = read_allocation_from_onodes_mt(sbmap, stats); + } } + if (ret < 0) { derr << "failed read_allocation_from_onodes()" << dendl; return ret; } + // then set space used by superblock + auto super_length = std::max(min_alloc_size, SUPER_RESERVED); + set_allocation_in_simple_bmap(sbmap, 0, super_length); + stats.extent_count++; std::lock_guard l(vstatfs_lock); store_statfs_t s; @@ -21168,11 +21188,22 @@ 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); + return ret; +} + +int BlueStore::allocation_recover_and_compare( + SimpleBitmap *sbmap, + read_alloc_stats_t &stats) +{ + int ret = 0; + SimpleBitmap& old_bitmap = *sbmap; + read_alloc_stats_t& old_stats = stats; SimpleBitmap mt_bitmap(cct, (bdev->get_size()/ min_alloc_size)); + read_alloc_stats_t mt_stats = {}; utime_t start; utime_t duration; - read_alloc_stats_t old_stats = {}; - read_alloc_stats_t mt_stats = {}; if (cct->_conf.get_val("bluestore_allocation_recovery_threads") != 0) { dout(0) << "New recovery start" << dendl; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 1f9dc8e69fb..9882949f11f 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -4135,6 +4135,8 @@ private: std::map actual_pool_vstatfs; volatile_statfs actual_store_vstatfs; }; + int allocation_recover_and_compare(SimpleBitmap *sbmap, read_alloc_stats_t &stats); + class Decoder_AllocationsAndStatFS; class ExtentDecoderPartial : public ExtentMap::ExtentDecoder { BlueStore& store;