]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/scrub: introducing random_bool_with_probability()
authorRonen Friedman <rfriedma@redhat.com>
Sun, 10 Sep 2023 18:07:31 +0000 (13:07 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Wed, 20 Sep 2023 06:39:10 +0000 (01:39 -0500)
Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/osd/OSD.cc
src/osd/scrubber_common.h

index edb8da1f29d2a4d56e3245554f20e1472aaf058e..29e9e47c605faa53654a5c9a7cc438c05dab968f 100644 (file)
@@ -7599,12 +7599,11 @@ void OSD::handle_fast_scrub(MOSDScrub2 *m)
 
 bool OSD::scrub_random_backoff()
 {
-  bool coin_flip = (rand() / (double)RAND_MAX >=
-                   cct->_conf->osd_scrub_backoff_ratio);
-  if (!coin_flip) {
-    dout(20) << "scrub_random_backoff lost coin flip, randomly backing off (ratio: "
-            << cct->_conf->osd_scrub_backoff_ratio << ")" << dendl;
-    return true;
+  if (random_bool_with_probability(cct->_conf->osd_scrub_backoff_ratio)) {
+    dout(20)
+       << "scrub_random_backoff lost coin flip, randomly backing off (ratio: "
+       << cct->_conf->osd_scrub_backoff_ratio << ")" << dendl;
+    return true; // backing off
   }
   return false;
 }
index 945b77eb3fe1b6c0781edff4cb247715c13d18ca..6cfb1232e582fcc0a83e4e310de2026698034508 100644 (file)
@@ -32,6 +32,11 @@ private:
   ScrubberPasskey& operator=(const ScrubberPasskey&) = delete;
 };
 
+/// randomly returns true with probability equal to the passed parameter
+static inline bool random_bool_with_probability(double probability) {
+  return (ceph::util::generate_random_number<double>(0.0, 1.0) < probability);
+}
+
 namespace Scrub {
 
 /// high/low OP priority