Skip to content

Commit c4730a9

Browse files
authored
Merge pull request ceph#61164 from chardan/wip-objectstore-ops-replayer-sign-warning
ops_replayer: fix signed/unsigned warning and add parameter range checking.
2 parents e93e155 + 8de1828 commit c4730a9

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/test/objectstore/allocsim/ops_replayer.cc

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <algorithm>
2+
#include <functional>
23
#include <boost/program_options/value_semantic.hpp>
34
#include <cassert>
45
#include <cctype>
@@ -13,26 +14,46 @@
1314
#include <fstream>
1415
#include <filesystem>
1516
#include <mutex>
16-
#include "include/rados/buffer_fwd.h"
17-
#include "include/rados/librados.hpp"
1817
#include <atomic>
19-
#include <fmt/format.h>
2018
#include <map>
2119
#include <memory>
2220
#include <random>
2321
#include <string>
2422
#include <iostream>
2523
#include <vector>
24+
#include <format>
25+
26+
#include <fmt/format.h>
2627

2728
#include <boost/program_options/variables_map.hpp>
2829
#include <boost/program_options/parsers.hpp>
2930

31+
#include "include/rados/buffer_fwd.h"
32+
#include "include/rados/librados.hpp"
33+
3034
namespace po = boost::program_options;
3135

3236

3337
using namespace std;
3438
using namespace ceph;
3539

40+
namespace settings {
41+
42+
// Returns a function which restricts a value to a specified range by throwing if it is not in range:
43+
// (Note: std::clamp() does not throw.)
44+
auto clamp_or_throw(auto min, auto max)
45+
{
46+
return [=](auto& x) {
47+
if(std::less<>{}(x, min) or std::greater<>{}(x, max)) {
48+
throw std::out_of_range(fmt::format("value expected between {} and {}, but got {}", min, max, x));
49+
}
50+
51+
return x;
52+
};
53+
}
54+
55+
} // namespace settings
56+
3657
// compare shared_ptr<string>
3758
struct StringPtrCompare
3859
{
@@ -338,8 +359,8 @@ int main(int argc, char** argv) {
338359

339360
// options
340361
uint64_t io_depth = 8;
341-
uint64_t nparser_threads = 16;
342-
uint64_t nworker_threads = 16;
362+
int nparser_threads = 16;
363+
int nworker_threads = 16;
343364
string file("input.txt");
344365
string ceph_conf_path("./ceph.conf");
345366
string pool("test_pool");
@@ -351,8 +372,8 @@ int main(int argc, char** argv) {
351372
("input-files,i", po::value<vector<string>>()->multitoken(), "List of input files (output of op_scraper.py). Multiple files will be merged and sorted by time order")
352373
("ceph-conf", po::value<string>(&ceph_conf_path)->default_value("ceph.conf"), "Path to ceph conf")
353374
("io-depth", po::value<uint64_t>(&io_depth)->default_value(64), "I/O depth")
354-
("parser-threads", po::value<uint64_t>(&nparser_threads)->default_value(16), "Number of parser threads")
355-
("worker-threads", po::value<uint64_t>(&nworker_threads)->default_value(16), "Number of I/O worker threads")
375+
("parser-threads", po::value<int>(&nparser_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of parser threads")
376+
("worker-threads", po::value<int>(&nworker_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of I/O worker threads")
356377
("pool", po::value<string>(&pool)->default_value("test_pool"), "Pool to use for I/O")
357378
("skip-do-ops", po::bool_switch(&skip_do_ops)->default_value(false), "Skip doing operations")
358379
;

0 commit comments

Comments
 (0)