]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Add bluestore_debug_fast_recovery_compare_chance
authorAdam Kupczyk <akupczyk@ibm.com>
Tue, 19 May 2026 19:36:37 +0000 (19:36 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Mon, 8 Jun 2026 17:04:29 +0000 (17:04 +0000)
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 <akupczyk@ibm.com>
src/common/options/global.yaml.in
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 3460267c155cce65be6ba66cda70dffb1bb3916b..8e375df59d435a89df70ee8de086d3e083560dde 100644 (file)
@@ -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
index 3a64fb42b502723772cdba814a9118dda2c8e25c..fde30a9499e2d19a3f9a196728db437f7d73037f 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include <bit>
+#include <random>
 #include <utility>
 #include <memory>
 #include <unistd.h>
@@ -29,6 +30,7 @@
 #include <boost/random/uniform_real.hpp>
 
 #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<uint64_t>(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<double>("bluestore_debug_fast_recovery_compare_chance");
   if (cct->_conf.get_val<uint64_t>("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<uint64_t>("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<uint64_t>(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<uint64_t>("bluestore_allocation_recovery_threads") != 0) {
     dout(0) << "New recovery start" << dendl;
index 1f9dc8e69fbc1e9bf2f4992c6ef657cd13c67250..9882949f11f823ac4d553ab6a1a574f8335388f5 100644 (file)
@@ -4135,6 +4135,8 @@ private:
     std::map<uint64_t, volatile_statfs> 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;