From: Ronen Friedman Date: Sun, 10 Sep 2023 18:07:31 +0000 (-0500) Subject: osd/scrub: introducing random_bool_with_probability() X-Git-Tag: v19.0.0~438^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=46d291a7fcd45874b0d7a1998e2aadc88d2464a7;p=ceph.git osd/scrub: introducing random_bool_with_probability() Signed-off-by: Ronen Friedman --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index edb8da1f29d..29e9e47c605 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -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; } diff --git a/src/osd/scrubber_common.h b/src/osd/scrubber_common.h index 945b77eb3fe..6cfb1232e58 100644 --- a/src/osd/scrubber_common.h +++ b/src/osd/scrubber_common.h @@ -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(0.0, 1.0) < probability); +} + namespace Scrub { /// high/low OP priority