Changed from using ceph util random_number_generator class to using std::mt19937_64 as it is compiler independent.
Fixes: https://tracker.ceph.com/issues/73553
Signed-off-by: Matty Williams <Matty.Williams@ibm.com>
void ObjectModel::applyIoOp(IoOp& op) {
auto generate_random = [&rng = rng]() {
- return rng(1, std::numeric_limits<int>::max());
+ std::uniform_int_distribution<long long> distMax(1, std::numeric_limits<int>::max());
+ return distMax(rng);
};
auto verify_and_record_read_op =
bool secondary_created;
std::vector<int> primary_contents;
std::vector<int> secondary_contents;
- ceph::util::random_number_generator<int> rng =
- ceph::util::random_number_generator<int>();
+ std::mt19937_64 rng =
+ std::mt19937_64();
// Track read and write I/Os that can be submitted in
// parallel to detect violations:
#include <boost/program_options.hpp>
#include <optional>
+#include <random>
#include <string>
#include "include/ceph_assert.h"
num_selections>& selections_array>
class ProgramOptionSelector : public ProgramOptionReader<option_type> {
public:
- ProgramOptionSelector(ceph::util::random_number_generator<int>& rng,
+ ProgramOptionSelector(std::mt19937_64& rng,
po::variables_map& vm,
const std::string& option_name,
bool select_first)
} else if (first_value.has_value()) {
return *std::exchange(first_value, std::nullopt);
} else {
- return selections_array[rng(num_selections - 1)];
+ std::uniform_int_distribution<long long> dist_selections(0, num_selections - 1);
+ return selections_array[dist_selections(rng)];
}
}
protected:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
std::optional<option_type> first_value;
};
num_selections_stable>& elections_array_stable>
class StableOptionSelector : public ProgramOptionReader<option_type> {
public:
- StableOptionSelector(ceph::util::random_number_generator<int>& rng,
+ StableOptionSelector(std::mt19937_64& rng,
po::variables_map& vm,
const std::string& option_name,
bool select_first)
} else if (first_value.has_value()) {
return *std::exchange(first_value, std::nullopt);
} else if (stable) {
- return elections_array_stable[rng(num_selections_stable - 1)];
+ std::uniform_int_distribution<long long> dist_selections_stable(0, num_selections_stable - 1);
+ return elections_array_stable[dist_selections_stable(rng)];
} else {
- return selections_array[rng(num_selections - 1)];
+ std::uniform_int_distribution<long long> dist_selections(0, num_selections - 1);
+ return selections_array[dist_selections(rng)];
}
}
protected:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
std::optional<option_type> first_value;
bool stable;
};
class ProgramOptionGeneratedSelector
: public OptionalProgramOptionReader<option_type> {
public:
- ProgramOptionGeneratedSelector(ceph::util::random_number_generator<int>& rng,
+ ProgramOptionGeneratedSelector(std::mt19937_64& rng,
po::variables_map& vm,
const std::string& option_name,
bool first_use)
virtual const std::optional<option_type> selectRandom() {
std::vector<option_type> selection = generate_selections();
- if (selection.size() > 0)
- return selection[rng(selection.size() - 1)];
- else
+ if (selection.size() > 0) {
+ std::uniform_int_distribution<long long> dist_selection(0, selection.size() - 1);
+ return selection[dist_selection(rng)];
+ } else {
return std::nullopt;
+ }
}
bool is_first_use() { return first_use; }
private:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
bool first_use;
};
#include <boost/asio/io_context.hpp>
#include <iostream>
+#include <random>
#include <vector>
#include "common/Formatter.h"
}
ceph::io_sequence::tester::SelectErasureTechnique::SelectErasureTechnique(
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
bool first_use)
}
ceph::io_sequence::tester::lrc::SelectMappingAndLayers::SelectMappingAndLayers(
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
bool first_use)
: rng_seed(rng()),
}
ceph::io_sequence::tester::SelectErasureKM::SelectErasureKM(
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::string>& technique,
}
ceph::io_sequence::tester::jerasure::SelectErasureW::SelectErasureW(
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::string_view>& technique,
}
ceph::io_sequence::tester::shec::SelectErasureC::SelectErasureC(
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::pair<int, int>>& km,
}
ceph::io_sequence::tester::jerasure::SelectErasurePacketSize::
- SelectErasurePacketSize(ceph::util::random_number_generator<int>& rng,
+ SelectErasurePacketSize(std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::string_view>& technique,
}
ceph::io_sequence::tester::SelectErasureChunkSize::SelectErasureChunkSize(
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
ErasureCodeInterfaceRef ec_impl,
bool first_use)
if (4096 % minimum_chunksize == 0) {
choices.push_back(4096);
} else {
- choices.push_back(minimum_chunksize * (rng(4) + 1));
+ std::uniform_int_distribution<long long> dist4(0, 3);
+ choices.push_back(minimum_chunksize * (dist4(rng) + 1));
}
if ((64 * 1024) % minimum_chunksize == 0) {
choices.push_back(64 * 1024);
} else {
- choices.push_back(minimum_chunksize * (rng(64) + 1));
+ std::uniform_int_distribution<long long> dist64(0, 63);
+ choices.push_back(minimum_chunksize * (dist64(rng) + 1));
}
if ((256 * 1024) % minimum_chunksize == 0) {
choices.push_back(256 * 1024);
} else {
- choices.push_back(minimum_chunksize * (rng(256) + 1));
+ std::uniform_int_distribution<long long> dist256(0, 255);
+ choices.push_back(minimum_chunksize * (dist256(rng) + 1));
}
return choices;
ceph::io_sequence::tester::SelectErasureProfile::SelectErasureProfile(
boost::intrusive_ptr<CephContext> cct,
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
librados::Rados& rados,
bool dry_run,
ceph::io_sequence::tester::SelectErasurePool::SelectErasurePool(
boost::intrusive_ptr<CephContext> cct,
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
librados::Rados& rados,
bool dry_run,
const std::string primary_oid, const std::string secondary_oid, librados::Rados& rados,
boost::asio::io_context& asio, SelectBlockSize& sbs, SelectErasurePool& spo,
SelectObjectSize& sos, SelectNumThreads& snt, SelectSeqRange& ssr,
- ceph::util::random_number_generator<int>& rng, ceph::mutex& lock,
+ std::mt19937_64& rng, ceph::mutex& lock,
ceph::condition_variable& cond, bool dryrun, bool verbose,
std::optional<int> seqseed, bool testrecovery, bool checkconsistency, bool delete_objects)
: rng(rng), verbose(verbose), seqseed(seqseed), testrecovery(testrecovery), checkconsistency(checkconsistency),
librados::Rados& rados)
: rados(rados),
seed(vm.contains("seed") ? vm["seed"].as<int>() : time(nullptr)),
- rng(ceph::util::random_number_generator<int>(seed)),
+ rng(seed),
sbs{rng, vm, "blocksize", true},
sos{rng, vm, "objectsize", true},
spo{cct,
primary_object_name, secondary_object_name, sbs.select(), rng());
} else {
const std::string pool = spo.select();
+ dout(0) << "Pool name: " << pool << dendl;
model = std::make_unique<ceph::io_exerciser::RadosIo>(
rados, asio, pool, primary_object_name, secondary_object_name, sbs.select(), rng(),
#include <boost/asio/io_context.hpp>
#include <boost/program_options.hpp>
#include <optional>
+#include <random>
#include <string>
#include <utility>
class SelectErasureKM
: public ProgramOptionGeneratedSelector<std::pair<int, int>> {
public:
- SelectErasureKM(ceph::util::random_number_generator<int>& rng,
+ SelectErasureKM(std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::string>& technique,
const std::vector<std::pair<int, int>> generate_selections() override;
private:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
std::string_view plugin;
std::optional<std::string> technique;
namespace shec {
class SelectErasureC : public ProgramOptionGeneratedSelector<uint64_t> {
public:
- SelectErasureC(ceph::util::random_number_generator<int>& rng,
+ SelectErasureC(std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::pair<int, int>>& km,
const std::vector<uint64_t> generate_selections() override;
private:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
std::string_view plugin;
std::optional<std::pair<int, int>> km;
namespace jerasure {
class SelectErasureW : public ProgramOptionGeneratedSelector<uint64_t> {
public:
- SelectErasureW(ceph::util::random_number_generator<int>& rng,
+ SelectErasureW(std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::string_view>& technique,
const std::vector<uint64_t> generate_selections() override;
private:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
std::string_view plugin;
std::optional<std::string_view> technique;
class SelectErasurePacketSize
: public ProgramOptionGeneratedSelector<uint64_t> {
public:
- SelectErasurePacketSize(ceph::util::random_number_generator<int>& rng,
+ SelectErasurePacketSize(std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
const std::optional<std::string_view>& technique,
const std::vector<uint64_t> generate_selections() override;
private:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
std::string_view plugin;
std::optional<std::string_view> technique;
class SelectMappingAndLayers {
public:
- SelectMappingAndLayers(ceph::util::random_number_generator<int>& rng,
+ SelectMappingAndLayers(std::mt19937_64& rng,
po::variables_map& vm,
bool first_use);
const std::pair<std::string, std::string> select();
private:
uint64_t rng_seed;
- ceph::util::random_number_generator<int> mapping_rng;
- ceph::util::random_number_generator<int> layers_rng;
+ std::mt19937_64 mapping_rng;
+ std::mt19937_64 layers_rng;
SelectMapping sma;
SelectLayers sly;
class SelectErasureTechnique
: public ProgramOptionGeneratedSelector<std::string> {
public:
- SelectErasureTechnique(ceph::util::random_number_generator<int>& rng,
+ SelectErasureTechnique(std::mt19937_64& rng,
po::variables_map& vm,
std::string_view plugin,
bool first_use);
const std::vector<std::string> generate_selections() override;
private:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
std::string_view plugin;
bool stable;
class SelectErasureChunkSize : public ProgramOptionGeneratedSelector<uint64_t> {
public:
- SelectErasureChunkSize(ceph::util::random_number_generator<int>& rng,
+ SelectErasureChunkSize(std::mt19937_64& rng,
po::variables_map& vm,
ErasureCodeInterfaceRef ec_impl,
bool first_use);
const std::vector<uint64_t> generate_selections() override;
private:
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
ErasureCodeInterfaceRef ec_impl;
};
class SelectErasureProfile : public ProgramOptionReader<Profile> {
public:
SelectErasureProfile(boost::intrusive_ptr<CephContext> cct,
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm, librados::Rados& rados,
bool dry_run, bool first_use);
const Profile select() override;
boost::intrusive_ptr<CephContext> cct;
librados::Rados& rados;
bool dry_run;
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
po::variables_map& vm;
bool first_use;
class SelectErasurePool : public ProgramOptionReader<std::string> {
public:
SelectErasurePool(boost::intrusive_ptr<CephContext> cct,
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
po::variables_map& vm,
librados::Rados& rados,
bool dry_run,
ceph::io_sequence::tester::SelectObjectSize& sos,
ceph::io_sequence::tester::SelectNumThreads& snt,
ceph::io_sequence::tester::SelectSeqRange& ssr,
- ceph::util::random_number_generator<int>& rng,
+ std::mt19937_64& rng,
ceph::mutex& lock,
ceph::condition_variable& cond,
bool dryrun,
std::unique_ptr<ceph::io_exerciser::IoSequence> seq;
std::unique_ptr<ceph::io_exerciser::IoOp> op;
bool done;
- ceph::util::random_number_generator<int>& rng;
+ std::mt19937_64& rng;
bool verbose;
std::optional<int> seqseed;
std::optional<std::pair<int, int>> pool_km;
private:
librados::Rados& rados;
int seed;
- ceph::util::random_number_generator<int> rng;
+ std::mt19937_64 rng;
ceph::io_sequence::tester::SelectBlockSize sbs;
ceph::io_sequence::tester::SelectObjectSize sos;