From: Loic Dachary Date: Mon, 3 Feb 2014 13:00:41 +0000 (+0100) Subject: erasure-code: add ceph_erasure_code debug command X-Git-Tag: v0.78~224^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F1177%2Fhead;p=ceph.git erasure-code: add ceph_erasure_code debug command It loads a designated erasure-code plugin and calls its methods. It is convenient to figure out and tune the number of data chunks, the size of an aligned chunk etc. For instance: ceph_erasure_code \ --parameter erasure-code-plugin=jerasure \ --parameter erasure-code-directory=.libs \ --parameter erasure-code-technique=reed_sol_van \ --parameter erasure-code-k=2 \ --parameter erasure-code-m=2 \ --all displays the chunk size when encoding an object of 1024 bytes. get_chunk_size(1024) 512 get_data_chunk_count 2 get_chunk_count 4 Signed-off-by: Loic Dachary --- diff --git a/ceph.spec.in b/ceph.spec.in index d18aa4f984af..a16882a9881d 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -616,6 +616,7 @@ fi %{_bindir}/ceph_dupstore %{_bindir}/ceph_kvstorebench %{_bindir}/ceph_multi_stress_watch +%{_bindir}/ceph_erasure_code %{_bindir}/ceph_erasure_code_benchmark %{_bindir}/ceph_omapbench %{_bindir}/ceph_psim diff --git a/debian/ceph-test.install b/debian/ceph-test.install index d2c84408de07..d0da0d731bb7 100644 --- a/debian/ceph-test.install +++ b/debian/ceph-test.install @@ -5,6 +5,7 @@ usr/bin/ceph_filestore_dump usr/bin/ceph_filestore_tool usr/bin/ceph_kvstorebench usr/bin/ceph_multi_stress_watch +usr/bin/ceph_erasure_code usr/bin/ceph_erasure_code_benchmark usr/bin/ceph_omapbench usr/bin/ceph_psim diff --git a/src/.gitignore b/src/.gitignore index a9bbac58cffd..3c08aa3b7514 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -27,6 +27,7 @@ Makefile /ceph_filestore_tool /ceph_mon_store_converter /ceph_multi_stress_watch +/ceph_erasure_code /ceph_erasure_code_benchmark /ceph_psim /ceph_radosacl diff --git a/src/test/erasure-code/Makefile.am b/src/test/erasure-code/Makefile.am index d5e9eac1443d..b467eea5a2fd 100644 --- a/src/test/erasure-code/Makefile.am +++ b/src/test/erasure-code/Makefile.am @@ -6,5 +6,13 @@ ceph_erasure_code_benchmark_LDADD += -ldl endif bin_DEBUGPROGRAMS += ceph_erasure_code_benchmark +ceph_erasure_code_SOURCES = \ + test/erasure-code/ceph_erasure_code.cc +ceph_erasure_code_LDADD = $(LIBOSD) $(LIBCOMMON) $(BOOST_PROGRAM_OPTIONS_LIBS) $(CEPH_GLOBAL) +if LINUX +ceph_erasure_code_LDADD += -ldl +endif +bin_DEBUGPROGRAMS += ceph_erasure_code + noinst_HEADERS += \ test/erasure-code/ceph_erasure_code_benchmark.h diff --git a/src/test/erasure-code/ceph_erasure_code.cc b/src/test/erasure-code/ceph_erasure_code.cc new file mode 100644 index 000000000000..800ef76f2dd3 --- /dev/null +++ b/src/test/erasure-code/ceph_erasure_code.cc @@ -0,0 +1,166 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2014 Cloudwatt + * + * Author: Loic Dachary + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "global/global_context.h" +#include "global/global_init.h" +#include "common/ceph_argparse.h" +#include "common/config.h" +#include "common/Clock.h" +#include "include/utime.h" +#include "osd/ErasureCodePlugin.h" + +namespace po = boost::program_options; + +class ErasureCodeCommand { + po::variables_map vm; + map parameters; +public: + int setup(int argc, char** argv); + int run(); +}; + +int ErasureCodeCommand::setup(int argc, char** argv) { + + po::options_description desc("Allowed options"); + desc.add_options() + ("help,h", "produce help message") + ("all", "implies " + "--get_chunk_size 1024 " + "--get_data_chunk_count " + "--get_chunk_count ") + ("get_chunk_size", po::value(), + "display get_chunk_size()") + ("get_data_chunk_count", "display get_data_chunk_count()") + ("get_chunk_count", "display get_chunk_count()") + ("parameter,P", po::value >(), + "parameters") + ; + + po::parsed_options parsed = + po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + po::store( + parsed, + vm); + po::notify(vm); + + vector ceph_options, def_args; + vector ceph_option_strings = po::collect_unrecognized( + parsed.options, po::include_positional); + ceph_options.reserve(ceph_option_strings.size()); + for (vector::iterator i = ceph_option_strings.begin(); + i != ceph_option_strings.end(); + ++i) { + ceph_options.push_back(i->c_str()); + } + + global_init( + &def_args, ceph_options, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + common_init_finish(g_ceph_context); + g_ceph_context->_conf->apply_changes(NULL); + + if (vm.count("help")) { + cout << desc << std::endl; + return 1; + } + + if (vm.count("parameter")) { + const vector &p = vm["parameter"].as< vector >(); + for (vector::const_iterator i = p.begin(); + i != p.end(); + i++) { + std::vector strs; + boost::split(strs, *i, boost::is_any_of("=")); + if (strs.size() != 2) { + cerr << "--parameter " << *i + << " ignored because it does not contain exactly one =" << endl; + } else { + parameters[strs[0]] = strs[1]; + } + } + } + + if (parameters.count("erasure-code-directory") == 0) + parameters["erasure-code-directory"] = ".libs"; + if (parameters.count("erasure-code-plugin") == 0) { + cerr << "--parameter erasure-code-plugin= is mandatory" << endl; + return 1; + } + + return 0; +} + +int ErasureCodeCommand::run() { + ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance(); + instance.disable_dlclose = true; + ErasureCodeInterfaceRef erasure_code; + int code = instance.factory(parameters["erasure-code-plugin"], + parameters, + &erasure_code); + if (code) + return code; + + if (vm.count("all") || vm.count("get_chunk_size")) { + unsigned int object_size = 1024; + if (vm.count("get_chunk_size")) + object_size = vm["get_chunk_size"].as(); + cout << "get_chunk_size(" << object_size << ")\t" + << erasure_code->get_chunk_size(object_size) << endl; + } + if (vm.count("all") || vm.count("get_data_chunk_count")) + cout << "get_data_chunk_count\t" + << erasure_code->get_data_chunk_count() << endl; + if (vm.count("all") || vm.count("get_chunk_count")) + cout << "get_chunk_count\t" + << erasure_code->get_chunk_count() << endl; + return 0; +} + +int main(int argc, char** argv) { + ErasureCodeCommand eccommand; + int err = eccommand.setup(argc, argv); + if (err) + return err; + return eccommand.run(); +} + +/* + * Local Variables: + * compile-command: "cd ../.. ; make -j4 && + * make -j4 ceph_erasure_code && + * valgrind --tool=memcheck --leak-check=full \ + * ./ceph_erasure_code \ + * --parameter erasure-code-plugin=jerasure \ + * --parameter erasure-code-directory=.libs \ + * --parameter erasure-code-technique=reed_sol_van \ + * --parameter erasure-code-k=2 \ + * --parameter erasure-code-m=2 \ + * --get_chunk_size 1024 \ + * --get_data_chunk_count \ + * --get_chunk_count \ + * " + * End: + */