Format code
parent
420debc2f5
commit
c0a05c8fea
2
Makefile
2
Makefile
|
@ -16,7 +16,7 @@ clean:
|
|||
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
indent: *.cpp *.h
|
||||
clang-format-6.0 -i $^
|
||||
clang-format -style=Microsoft -i $^
|
||||
|
||||
builddep:
|
||||
sudo apt install -y --no-install-recommends libjsoncpp-dev libtcmalloc-minimal4
|
||||
|
|
47
main.cpp
47
main.cpp
|
@ -1,14 +1,14 @@
|
|||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <librados.hpp>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <system_error>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <system_error>
|
||||
|
||||
#include "mysignals.h"
|
||||
#include "radosutil.h"
|
||||
|
@ -43,8 +43,7 @@ template <class T> static uint64_t dur2nsec(const T &dur)
|
|||
return duration_cast<duration<uint64_t, nano>>(dur).count();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void print_breakdown(const vector<T> &all_ops, size_t thread_count)
|
||||
template <class T> static void print_breakdown(const vector<T> &all_ops, size_t thread_count)
|
||||
{
|
||||
T totaltime(0);
|
||||
|
||||
|
@ -112,10 +111,7 @@ static void fill_urandom(char *buf, size_t len)
|
|||
}
|
||||
|
||||
// May be called in a thread.
|
||||
static void _do_bench(
|
||||
const unique_ptr<bench_settings> &settings,
|
||||
const vector<string> &obj_names,
|
||||
IoCtx &ioctx,
|
||||
static void _do_bench(const unique_ptr<bench_settings> &settings, const vector<string> &obj_names, IoCtx &ioctx,
|
||||
vector<steady_clock::duration> &ops)
|
||||
{
|
||||
// TODO: pass bufferlist as arguments
|
||||
|
@ -142,12 +138,8 @@ static void _do_bench(
|
|||
while (b <= stop)
|
||||
{
|
||||
abort_if_signalled();
|
||||
if (ioctx.write(
|
||||
obj_names[rand() % 16],
|
||||
(ops.size() % 2) ? bar1 : bar2,
|
||||
settings->block_size,
|
||||
settings->block_size * (rand() % (settings->object_size / settings->block_size))
|
||||
) < 0)
|
||||
if (ioctx.write(obj_names[rand() % 16], (ops.size() % 2) ? bar1 : bar2, settings->block_size,
|
||||
settings->block_size * (rand() % (settings->object_size / settings->block_size))) < 0)
|
||||
{
|
||||
throw "Write error";
|
||||
}
|
||||
|
@ -182,7 +174,9 @@ static void do_bench(const unique_ptr<bench_settings> &settings, const vector<st
|
|||
throw std::system_error(err, std::system_category(), "Failed to set thread sigmask");
|
||||
}
|
||||
|
||||
threads.push_back(thread(_do_bench, ref(settings), vector<string>(names.begin()+i*16, names.begin()+i*16+16), ref(ioctx), ref(listofops[i])));
|
||||
threads.push_back(thread(_do_bench, ref(settings),
|
||||
vector<string>(names.begin() + i * 16, names.begin() + i * 16 + 16), ref(ioctx),
|
||||
ref(listofops[i])));
|
||||
|
||||
if ((err = pthread_sigmask(SIG_SETMASK, &old_set, NULL)))
|
||||
{
|
||||
|
@ -226,31 +220,28 @@ static void _main(int argc, const char *argv[])
|
|||
{
|
||||
// duration
|
||||
++ai;
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", &settings->secs) != 1 ||
|
||||
settings->secs < 1)
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", &settings->secs) != 1 || settings->secs < 1)
|
||||
throw "Wrong duration";
|
||||
}
|
||||
else if (!strcmp(argv[ai], "-t"))
|
||||
{
|
||||
// threads
|
||||
++ai;
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", &settings->threads) != 1 ||
|
||||
settings->threads < 1)
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", &settings->threads) != 1 || settings->threads < 1)
|
||||
throw "Wrong thread number";
|
||||
}
|
||||
else if (!strcmp(argv[ai], "-b"))
|
||||
{
|
||||
// block size
|
||||
++ai;
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", (int*)&settings->block_size) != 1 ||
|
||||
settings->block_size < 1)
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", (int *)&settings->block_size) != 1 || settings->block_size < 1)
|
||||
throw "Wrong block size";
|
||||
}
|
||||
else if (!strcmp(argv[ai], "-o"))
|
||||
{
|
||||
// object size
|
||||
++ai;
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", (int*)&settings->object_size) != 1 ||
|
||||
if (ai >= argc || sscanf(argv[ai], "%i", (int *)&settings->object_size) != 1 ||
|
||||
settings->object_size < 1)
|
||||
throw "Wrong object size";
|
||||
}
|
||||
|
@ -274,8 +265,7 @@ static void _main(int argc, const char *argv[])
|
|||
|
||||
if (settings->pool.empty() || settings->mode.empty())
|
||||
{
|
||||
cerr << "Usage: " << argv[0]
|
||||
<< " <poolname> <mode=host|osd> [specific item name to test]" << endl;
|
||||
cerr << "Usage: " << argv[0] << " <poolname> <mode=host|osd> [specific item name to test]" << endl;
|
||||
throw "Wrong cmdline";
|
||||
}
|
||||
|
||||
|
@ -329,8 +319,7 @@ static void _main(int argc, const char *argv[])
|
|||
if (location.find(settings->mode) != location.end())
|
||||
{
|
||||
const auto &osd_loc = location.at(settings->mode);
|
||||
if (settings->specific_bench_item.empty() ||
|
||||
osd_loc == settings->specific_bench_item)
|
||||
if (settings->specific_bench_item.empty() || osd_loc == settings->specific_bench_item)
|
||||
{
|
||||
bench_items.insert(osd_loc);
|
||||
}
|
||||
|
@ -362,7 +351,7 @@ static void _main(int argc, const char *argv[])
|
|||
continue;
|
||||
|
||||
auto &names = name2location[bench_item];
|
||||
if (names.size() >= (unsigned)settings->threads*16)
|
||||
if (names.size() >= (unsigned)settings->threads * 16)
|
||||
{
|
||||
bench_items.erase(bench_item);
|
||||
continue;
|
||||
|
@ -391,8 +380,8 @@ static void _main(int argc, const char *argv[])
|
|||
}
|
||||
rados.watch_flush();
|
||||
|
||||
//rados_ioctx_destroy(io);
|
||||
//rados_shutdown(cluster);
|
||||
// rados_ioctx_destroy(io);
|
||||
// rados_shutdown(cluster);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
#include <csignal>
|
||||
|
||||
#include "mysignals.h"
|
||||
|
||||
#include <csignal>
|
||||
static volatile std::sig_atomic_t gSignalStatus;
|
||||
|
||||
static void signal_handler(int signal) { gSignalStatus = signal; }
|
||||
static void signal_handler(int signal)
|
||||
{
|
||||
gSignalStatus = signal;
|
||||
}
|
||||
|
||||
void setup_signal_handlers() {
|
||||
void setup_signal_handlers()
|
||||
{
|
||||
std::signal(SIGINT, signal_handler);
|
||||
std::signal(SIGTERM, signal_handler);
|
||||
}
|
||||
|
||||
void abort_if_signalled() {
|
||||
void abort_if_signalled()
|
||||
{
|
||||
if (gSignalStatus)
|
||||
throw AbortException();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
void setup_signal_handlers();
|
||||
|
||||
class AbortException : public std::exception {};
|
||||
class AbortException : public std::exception
|
||||
{
|
||||
};
|
||||
|
||||
void abort_if_signalled();
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include <string>
|
||||
#include "radosutil.h"
|
||||
|
||||
#include <json/json.h>
|
||||
#include <librados.hpp>
|
||||
|
||||
#include "radosutil.h"
|
||||
#include <librados.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace librados;
|
||||
|
@ -12,13 +12,13 @@ RadosUtils::RadosUtils(Rados *rados_)
|
|||
: rados(rados_), /* */
|
||||
json_reader(new Json::Reader(Json::Features::strictMode())), /* */
|
||||
json_writer(new Json::FastWriter()) /* */
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
// RadosUtils::~RadosUtils() {}
|
||||
|
||||
unsigned int RadosUtils::get_obj_acting_primary(const string &name,
|
||||
const string &pool) {
|
||||
|
||||
unsigned int RadosUtils::get_obj_acting_primary(const string &name, const string &pool)
|
||||
{
|
||||
Json::Value cmd(Json::objectValue);
|
||||
cmd["prefix"] = "osd map";
|
||||
cmd["object"] = name;
|
||||
|
@ -33,7 +33,8 @@ unsigned int RadosUtils::get_obj_acting_primary(const string &name,
|
|||
return acting_primary.asUInt();
|
||||
}
|
||||
|
||||
map<string, string> RadosUtils::get_osd_location(unsigned int osd) {
|
||||
map<string, string> RadosUtils::get_osd_location(unsigned int osd)
|
||||
{
|
||||
Json::Value cmd(Json::objectValue);
|
||||
cmd["prefix"] = "osd find";
|
||||
cmd["id"] = osd;
|
||||
|
@ -43,7 +44,8 @@ map<string, string> RadosUtils::get_osd_location(unsigned int osd) {
|
|||
|
||||
map<string, string> result;
|
||||
|
||||
for (auto &&it = crush.begin(); it != crush.end(); ++it) {
|
||||
for (auto &&it = crush.begin(); it != crush.end(); ++it)
|
||||
{
|
||||
result[it.name()] = it->asString();
|
||||
}
|
||||
|
||||
|
@ -52,7 +54,8 @@ map<string, string> RadosUtils::get_osd_location(unsigned int osd) {
|
|||
return result;
|
||||
}
|
||||
|
||||
set<unsigned int> RadosUtils::get_osds(const string &pool) {
|
||||
set<unsigned int> RadosUtils::get_osds(const string &pool)
|
||||
{
|
||||
Json::Value cmd(Json::objectValue);
|
||||
cmd["prefix"] = "pg ls-by-pool";
|
||||
cmd["poolstr"] = pool;
|
||||
|
@ -61,10 +64,12 @@ set<unsigned int> RadosUtils::get_osds(const string &pool) {
|
|||
|
||||
set<unsigned int> osds;
|
||||
|
||||
if (pgs.isMember("pg_stats")) {
|
||||
if (pgs.isMember("pg_stats"))
|
||||
{
|
||||
pgs = pgs["pg_stats"];
|
||||
}
|
||||
for (const auto &pg : pgs) {
|
||||
for (const auto &pg : pgs)
|
||||
{
|
||||
const auto &primary = pg["acting_primary"];
|
||||
if (!primary.isNumeric())
|
||||
throw "Failed to get acting_primary";
|
||||
|
@ -74,7 +79,8 @@ set<unsigned int> RadosUtils::get_osds(const string &pool) {
|
|||
return osds;
|
||||
}
|
||||
|
||||
unsigned int RadosUtils::get_pool_size(const string &pool) {
|
||||
unsigned int RadosUtils::get_pool_size(const string &pool)
|
||||
{
|
||||
Json::Value cmd(Json::objectValue);
|
||||
cmd["prefix"] = "osd pool get";
|
||||
cmd["pool"] = pool;
|
||||
|
@ -85,15 +91,15 @@ unsigned int RadosUtils::get_pool_size(const string &pool) {
|
|||
return v["size"].asUInt();
|
||||
}
|
||||
|
||||
Json::Value RadosUtils::do_mon_command(Json::Value &cmd) {
|
||||
Json::Value RadosUtils::do_mon_command(Json::Value &cmd)
|
||||
{
|
||||
int err;
|
||||
bufferlist outbl;
|
||||
string outs;
|
||||
cmd["format"] = "json";
|
||||
bufferlist inbl;
|
||||
|
||||
if ((err = rados->mon_command(json_writer->write(cmd), inbl, &outbl, &outs)) <
|
||||
0)
|
||||
if ((err = rados->mon_command(json_writer->write(cmd), inbl, &outbl, &outs)) < 0)
|
||||
throw MyRadosException(err, outs);
|
||||
|
||||
Json::Value root;
|
||||
|
|
32
radosutil.h
32
radosutil.h
|
@ -1,39 +1,45 @@
|
|||
#include <json/json.h>
|
||||
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
|
||||
#include "librados_fwd.hpp"
|
||||
|
||||
namespace Json {
|
||||
namespace Json
|
||||
{
|
||||
class Reader;
|
||||
class FastWriter;
|
||||
class Value;
|
||||
} // namespace Json
|
||||
|
||||
class RadosUtils {
|
||||
public:
|
||||
class RadosUtils
|
||||
{
|
||||
public:
|
||||
explicit RadosUtils(librados::Rados *rados_);
|
||||
unsigned int get_obj_acting_primary(const std::string &name,
|
||||
const std::string &pool);
|
||||
unsigned int get_obj_acting_primary(const std::string &name, const std::string &pool);
|
||||
std::map<std::string, std::string> get_osd_location(unsigned int osd);
|
||||
std::set<unsigned int> get_osds(const std::string &pool);
|
||||
unsigned int get_pool_size(const std::string &pool);
|
||||
|
||||
private:
|
||||
private:
|
||||
Json::Value do_mon_command(Json::Value &cmd);
|
||||
librados::Rados *rados;
|
||||
std::unique_ptr<Json::Reader> json_reader;
|
||||
std::unique_ptr<Json::FastWriter> json_writer;
|
||||
};
|
||||
|
||||
class MyRadosException : public std::exception {
|
||||
public:
|
||||
MyRadosException(int err, const std::string &msg)
|
||||
: descr("Rados err " + std::to_string(err) + ": " + msg){};
|
||||
const char *what() const throw() { return descr.c_str(); }
|
||||
class MyRadosException : public std::exception
|
||||
{
|
||||
public:
|
||||
MyRadosException(int err, const std::string &msg) : descr("Rados err " + std::to_string(err) + ": " + msg){};
|
||||
const char *what() const throw()
|
||||
{
|
||||
return descr.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string descr;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue