diff --git a/utils/keeper-bench/Generator.cpp b/utils/keeper-bench/Generator.cpp index 280593ed511..12e628ed1e5 100644 --- a/utils/keeper-bench/Generator.cpp +++ b/utils/keeper-bench/Generator.cpp @@ -87,64 +87,6 @@ void removeRecursive(Coordination::ZooKeeper & zookeeper, const std::string & pa remove_future.get(); } -std::unique_ptr getGenerator(const std::string & name) -{ - //if (name == "create_no_data") - //{ - // return std::make_unique(); - //} - //else if (name == "create_small_data") - //{ - // return std::make_unique("/create_generator", 5, 32); - //} - //else if (name == "create_medium_data") - //{ - // return std::make_unique("/create_generator", 5, 1024); - //} - //else if (name == "create_big_data") - //{ - // return std::make_unique("/create_generator", 5, 512 * 1024); - //} - //else if (name == "get_no_data") - //{ - // return std::make_unique("/get_generator", 10, 0); - //} - //else if (name == "get_small_data") - //{ - // return std::make_unique("/get_generator", 10, 32); - //} - //else if (name == "get_medium_data") - //{ - // return std::make_unique("/get_generator", 10, 1024); - //} - //else if (name == "get_big_data") - //{ - // return std::make_unique("/get_generator", 10, 512 * 1024); - //} - //else if (name == "list_no_nodes") - //{ - // return std::make_unique("/list_generator", 0, 1); - //} - //else if (name == "list_few_nodes") - //{ - // return std::make_unique("/list_generator", 10, 5); - //} - //else if (name == "list_medium_nodes") - //{ - // return std::make_unique("/list_generator", 1000, 5); - //} - //else if (name == "list_a_lot_nodes") - //{ - // return std::make_unique("/list_generator", 100000, 5); - //} - //else if (name == "set_small_data") - //{ - // return std::make_unique("/set_generator", 5); - //} - - throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "Unknown generator {}", name); -} - NumberGetter NumberGetter::fromConfig(const std::string & key, const Poco::Util::AbstractConfiguration & config, std::optional default_value) { @@ -321,6 +263,10 @@ std::string PathGetter::description() const return description; } +RequestGetter::RequestGetter(std::vector request_generators_) + : request_generators(std::move(request_generators_)) +{} + RequestGetter RequestGetter::fromConfig(const std::string & key, const Poco::Util::AbstractConfiguration & config, bool for_multi) { RequestGetter request_getter; @@ -658,7 +604,7 @@ Generator::Generator(const Poco::Util::AbstractConfiguration & config) static const std::string generator_key = "generator"; - std::cout << "---- Parsing setup ---- " << std::endl; + std::cout << "---- Parsing setup ---- " << std::endl; static const std::string setup_key = generator_key + ".setup"; Poco::Util::AbstractConfiguration::Keys keys; config.keys(setup_key, keys); diff --git a/utils/keeper-bench/Generator.h b/utils/keeper-bench/Generator.h index 5c15d2bce9a..60c4fcb3cc4 100644 --- a/utils/keeper-bench/Generator.h +++ b/utils/keeper-bench/Generator.h @@ -9,115 +9,6 @@ #include #include - -std::string generateRandomPath(const std::string & prefix, size_t length = 5); - -std::string generateRandomData(size_t size); - -// -//class CreateRequestGenerator final : public IGenerator -//{ -//public: -// explicit CreateRequestGenerator( -// std::string path_prefix_ = "/create_generator", -// std::optional path_length_ = std::nullopt, -// std::optional data_size_ = std::nullopt) -// : path_prefix(path_prefix_) -// , path_length(path_length_) -// , data_size(data_size_) -// {} -// -// void startup(Coordination::ZooKeeper & zookeeper) override; -// Coordination::ZooKeeperRequestPtr generate() override; -// -//private: -// std::string path_prefix; -// std::optional path_length; -// std::optional data_size; -// std::unordered_set paths_created; -//}; -// -// -//class GetRequestGenerator final : public IGenerator -//{ -//public: -// explicit GetRequestGenerator( -// std::string path_prefix_ = "/get_generator", -// std::optional num_nodes_ = std::nullopt, -// std::optional nodes_data_size_ = std::nullopt) -// : path_prefix(path_prefix_) -// , num_nodes(num_nodes_) -// , nodes_data_size(nodes_data_size_) -// , rng(randomSeed()) -// , distribution(0, num_nodes ? *num_nodes - 1 : 0) -// {} -// -// void startup(Coordination::ZooKeeper & zookeeper) override; -// Coordination::ZooKeeperRequestPtr generate() override; -// -//private: -// std::string path_prefix; -// std::optional num_nodes; -// std::optional nodes_data_size; -// std::vector paths_to_get; -// -// pcg64 rng; -// std::uniform_int_distribution distribution; -//}; -// -//class ListRequestGenerator final : public IGenerator -//{ -//public: -// explicit ListRequestGenerator( -// std::string path_prefix_ = "/list_generator", -// std::optional num_nodes_ = std::nullopt, -// std::optional paths_length_ = std::nullopt) -// : path_prefix(path_prefix_) -// , num_nodes(num_nodes_) -// , paths_length(paths_length_) -// {} -// -// void startup(Coordination::ZooKeeper & zookeeper) override; -// Coordination::ZooKeeperRequestPtr generate() override; -// -//private: -// std::string path_prefix; -// std::optional num_nodes; -// std::optional paths_length; -//}; -// -//class SetRequestGenerator final : public IGenerator -//{ -//public: -// explicit SetRequestGenerator( -// std::string path_prefix_ = "/set_generator", -// uint64_t data_size_ = 5) -// : path_prefix(path_prefix_) -// , data_size(data_size_) -// {} -// -// void startup(Coordination::ZooKeeper & zookeeper) override; -// Coordination::ZooKeeperRequestPtr generate() override; -// -//private: -// std::string path_prefix; -// uint64_t data_size; -//}; -// -//class MixedRequestGenerator final : public IGenerator -//{ -//public: -// explicit MixedRequestGenerator(std::vector> generators_) -// : generators(std::move(generators_)) -// {} -// -// void startup(Coordination::ZooKeeper & zookeeper) override; -// Coordination::ZooKeeperRequestPtr generate() override; -// -//private: -// std::vector> generators; -//}; - struct NumberGetter { static NumberGetter fromConfig(const std::string & key, const Poco::Util::AbstractConfiguration & config, std::optional default_value = std::nullopt); @@ -247,6 +138,10 @@ private: struct RequestGetter { + explicit RequestGetter(std::vector request_generators_); + + RequestGetter() = default; + static RequestGetter fromConfig(const std::string & key, const Poco::Util::AbstractConfiguration & config, bool for_multi = false); RequestGeneratorPtr getRequestGenerator() const; @@ -279,7 +174,6 @@ public: void startup(Coordination::ZooKeeper & zookeeper); Coordination::ZooKeeperRequestPtr generate(); void cleanup(Coordination::ZooKeeper & zookeeper); - private: struct Node { @@ -299,4 +193,4 @@ private: Coordination::ACLs default_acls; }; -std::unique_ptr getGenerator(const std::string & name); +std::optional getGenerator(const std::string & name); diff --git a/utils/keeper-bench/Runner.cpp b/utils/keeper-bench/Runner.cpp index 2e3cd911698..2b645ddc6c3 100644 --- a/utils/keeper-bench/Runner.cpp +++ b/utils/keeper-bench/Runner.cpp @@ -13,7 +13,6 @@ namespace DB::ErrorCodes Runner::Runner( std::optional concurrency_, - const std::string & generator_name, const std::string & config_path, const Strings & hosts_strings_, std::optional max_time_, @@ -23,28 +22,10 @@ Runner::Runner( : info(std::make_shared()) { - DB::ConfigurationPtr config = nullptr; + DB::ConfigProcessor config_processor(config_path, true, false); + auto config = config_processor.loadConfig().configuration; - if (!config_path.empty()) - { - DB::ConfigProcessor config_processor(config_path, true, false); - config = config_processor.loadConfig().configuration; - } - - if (!generator_name.empty()) - { - //generator = getGenerator(generator_name); - - if (!generator) - throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Failed to create generator"); - } - else - { - if (!config) - throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "No config file or generator name defined"); - - generator.emplace(*config); - } + generator.emplace(*config); if (!hosts_strings_.empty()) { @@ -60,34 +41,38 @@ Runner::Runner( } std::cout << "---- Run options ---- " << std::endl; + static constexpr uint64_t DEFAULT_CONCURRENCY = 1; if (concurrency_) concurrency = *concurrency_; else - concurrency = config->getUInt64("concurrency", 1); + concurrency = config->getUInt64("concurrency", DEFAULT_CONCURRENCY); std::cout << "Concurrency: " << concurrency << std::endl; + static constexpr uint64_t DEFAULT_ITERATIONS = 0; if (max_iterations_) max_iterations = *max_iterations_; else - max_iterations = config->getUInt64("iterations", 0); + max_iterations = config->getUInt64("iterations", DEFAULT_ITERATIONS); std::cout << "Iterations: " << max_iterations << std::endl; + static constexpr double DEFAULT_DELAY = 1.0; if (delay_) delay = *delay_; else - delay = config->getDouble("report_delay", 1); + delay = config->getDouble("report_delay", DEFAULT_DELAY); std::cout << "Report delay: " << delay << std::endl; + static constexpr double DEFAULT_TIME_LIMIT = 1.0; if (max_time_) max_time = *max_time_; else - max_time = config->getDouble("timelimit", 1.0); + max_time = config->getDouble("timelimit", DEFAULT_TIME_LIMIT); std::cout << "Time limit: " << max_time << std::endl; if (continue_on_error_) continue_on_error = *continue_on_error_; else - continue_on_error = config->getBool("continue_on_error", 1.0); + continue_on_error = config->getBool("continue_on_error", false); std::cout << "Continue on error: " << continue_on_error << std::endl; std::cout << "---- Run options ----\n" << std::endl; diff --git a/utils/keeper-bench/Runner.h b/utils/keeper-bench/Runner.h index ebd2d702019..d85dc9e8658 100644 --- a/utils/keeper-bench/Runner.h +++ b/utils/keeper-bench/Runner.h @@ -35,7 +35,6 @@ class Runner public: Runner( std::optional concurrency_, - const std::string & generator_name, const std::string & config_path, const Strings & hosts_strings_, std::optional max_time_, diff --git a/utils/keeper-bench/main.cpp b/utils/keeper-bench/main.cpp index cb25aa7d0a5..0753d66850f 100644 --- a/utils/keeper-bench/main.cpp +++ b/utils/keeper-bench/main.cpp @@ -34,7 +34,6 @@ int main(int argc, char *argv[]) boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth()); desc.add_options() ("help", "produce help message") - ("generator", value()->default_value(""), "query to execute") ("config", value()->default_value(""), "yaml/xml file containing configuration") ("concurrency,c", value(), "number of parallel queries") ("report-delay,d", value(), "delay between intermediate reports in seconds (set 0 to disable reports)") @@ -56,7 +55,6 @@ int main(int argc, char *argv[]) } Runner runner(valueToOptional(options["concurrency"]), - options["generator"].as(), options["config"].as(), options["hosts"].as(), valueToOptional(options["time-limit"]),