From 42020a56a746e61fed4b928c9933b57bdd3371c7 Mon Sep 17 00:00:00 2001 From: Matty Williams Date: Fri, 17 Oct 2025 16:50:52 +0100 Subject: [PATCH] test: Removed ObjectModel seed generation from constructor Having rng() in the constructor of ObjectModel and RadosIo was causing random number generation to differ between compilers. Fixes: https://tracker.ceph.com/issues/73553 Signed-off-by: Matty Williams --- src/common/io_exerciser/ObjectModel.cc | 17 +++---------- src/common/io_exerciser/ObjectModel.h | 4 +-- .../ProgramOptionReader.h | 13 ---------- .../ceph_test_rados_io_sequence.cc | 25 +++++++++---------- 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/common/io_exerciser/ObjectModel.cc b/src/common/io_exerciser/ObjectModel.cc index 3e47caeca338..cd9f741065a7 100644 --- a/src/common/io_exerciser/ObjectModel.cc +++ b/src/common/io_exerciser/ObjectModel.cc @@ -4,20 +4,14 @@ #include #include #include - -#include "common/debug.h" -#include "common/dout.h" - -#define dout_subsys ceph_subsys_rados -#define dout_context g_ceph_context +#include using ObjectModel = ceph::io_exerciser::ObjectModel; ObjectModel::ObjectModel(const std::string& primary_oid, const std::string& secondary_oid, uint64_t block_size, int seed, bool delete_objects) - : Model(primary_oid, secondary_oid, block_size, delete_objects), primary_created(false), secondary_created(false) { - rng.seed(seed); -} + : Model(primary_oid, secondary_oid, block_size, delete_objects), + primary_created(false), secondary_created(false), rng(seed) {} int ObjectModel::get_seed(uint64_t offset) const { ceph_assert(offset < primary_contents.size()); @@ -58,10 +52,7 @@ void ObjectModel::applyIoOp(IoOp& op) { constexpr int64_t max = static_cast(std::numeric_limits::max()); constexpr uint64_t range = static_cast(max - min + 1); uint64_t rand_value = rng(); - int64_t result = static_cast(rand_value % range + min); - dout(0) << "S1 rand_value: " << rand_value << " range: " - << range << " result: " << result << " addr: " << &rng << dendl; - return result; + return static_cast(rand_value % range + min); }; auto verify_and_record_read_op = diff --git a/src/common/io_exerciser/ObjectModel.h b/src/common/io_exerciser/ObjectModel.h index f14bfd0c64b8..c2db1d1314bb 100644 --- a/src/common/io_exerciser/ObjectModel.h +++ b/src/common/io_exerciser/ObjectModel.h @@ -7,6 +7,7 @@ #include #include +#include /* Overview * @@ -29,8 +30,7 @@ class ObjectModel : public Model { bool secondary_created; std::vector primary_contents; std::vector secondary_contents; - std::mt19937_64 rng = - std::mt19937_64(); + std::mt19937_64 rng; // Track read and write I/Os that can be submitted in // parallel to detect violations: diff --git a/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h b/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h index 15a268cb2c57..11e5ba13ee42 100644 --- a/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h +++ b/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h @@ -5,14 +5,9 @@ #include #include -#include "common/debug.h" -#include "common/dout.h" #include "include/ceph_assert.h" #include "include/random.h" -#define dout_subsys ceph_subsys_rados -#define dout_context g_ceph_context - /* Overview * * class ProgramOptionReader @@ -114,8 +109,6 @@ class ProgramOptionSelector : public ProgramOptionReader { uint64_t range = static_cast(num_selections); uint64_t rand_value = rng(); size_t index = static_cast(rand_value % range); - dout(0) << "S4 rand_value: " << rand_value << " range: " - << range << " index: " << index << " addr: " << &rng << dendl; return selections_array[index]; } } @@ -165,15 +158,11 @@ public: uint64_t range = static_cast(num_selections_stable); uint64_t rand_value = rng(); size_t index = static_cast(rand_value % range); - dout(0) << "S2 rand_value: " << rand_value << " range: " - << range << " index: " << index << " addr: " << &rng << dendl; return selections_array_stable[index]; } else { uint64_t range = static_cast(num_selections); uint64_t rand_value = rng(); size_t index = static_cast(rand_value % range); - dout(0) << "S6 rand_value: " << rand_value << " range: " - << range << " index: " << index << " addr: " << &rng << dendl; return selections_array[index]; } } @@ -223,8 +212,6 @@ class ProgramOptionGeneratedSelector uint64_t range = static_cast(selection.size()); uint64_t rand_value = rng(); size_t index = static_cast(rand_value % range); - dout(0) << "S3 rand_value: " << rand_value << " range: " - << range << " index: " << index << " addr: " << &rng << dendl; return selection[index]; } else { return std::nullopt; diff --git a/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc b/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc index a8e66354890e..4f4d68c5edfb 100644 --- a/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc +++ b/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc @@ -552,30 +552,27 @@ ceph::io_sequence::tester::SelectErasureChunkSize::generate_selections() { auto generate_random_int = [this](uint64_t range) -> uint64_t { uint64_t rand_value = rng(); - uint64_t index = rand_value % range; - dout(0) << "S5 rand_value: " << rand_value << " range: " - << range << " index: " << index << " addr: " << &rng << dendl; - return index; + return rand_value % range;; }; if (4096 % minimum_chunksize == 0) { choices.push_back(4096); } else { - uint64_t r = generate_random_int(4); // 0–3 + uint64_t r = generate_random_int(4); // [0–3] choices.push_back(minimum_chunksize * (r + 1)); } if ((64 * 1024) % minimum_chunksize == 0) { choices.push_back(64 * 1024); } else { - uint64_t r = generate_random_int(64); // 0–63 + uint64_t r = generate_random_int(64); // [0–63] choices.push_back(minimum_chunksize * (r + 1)); } if ((256 * 1024) % minimum_chunksize == 0) { choices.push_back(256 * 1024); } else { - uint64_t r = generate_random_int(256); // 0–255 + uint64_t r = generate_random_int(256); // [0–255] choices.push_back(minimum_chunksize * (r + 1)); } @@ -1042,8 +1039,9 @@ ceph::io_sequence::tester::TestObject::TestObject( : rng(rng), verbose(verbose), seqseed(seqseed), testrecovery(testrecovery), checkconsistency(checkconsistency), delete_objects(delete_objects) { if (dryrun) { + int model_seed = rng(); exerciser_model = std::make_unique( - primary_oid, secondary_oid, sbs.select(), rng(), delete_objects); + primary_oid, secondary_oid, sbs.select(), model_seed, delete_objects); } else { const std::string pool = spo.select(); if (!dryrun) { @@ -1061,9 +1059,9 @@ ceph::io_sequence::tester::TestObject::TestObject( bufferlist outbl; auto formatter = std::make_unique(false); - + int model_seed = rng(); exerciser_model = std::make_unique( - rados, asio, pool, primary_oid, secondary_oid, sbs.select(), rng(), + rados, asio, pool, primary_oid, secondary_oid, sbs.select(), model_seed, threads, lock, cond, spo.is_replicated_pool(), spo.get_allow_pool_ec_optimizations(), delete_objects); dout(0) << "= " << primary_oid << " pool=" << pool << " threads=" << threads @@ -1324,14 +1322,15 @@ bool ceph::io_sequence::tester::TestRunner::run_interactive_test() { std::unique_ptr model; if (dryrun) { + int model_seed = rng(); model = std::make_unique( - primary_object_name, secondary_object_name, sbs.select(), rng()); + primary_object_name, secondary_object_name, sbs.select(), model_seed); } else { const std::string pool = spo.select(); dout(0) << "Pool name: " << pool << dendl; - + int model_seed = rng(); model = std::make_unique( - rados, asio, pool, primary_object_name, secondary_object_name, sbs.select(), rng(), + rados, asio, pool, primary_object_name, secondary_object_name, sbs.select(), model_seed, 1, // 1 thread lock, cond, spo.is_replicated_pool(), spo.get_allow_pool_ec_optimizations()); -- 2.47.3