diff --git a/configure.py b/configure.py index ec8a37fff7..8a34d933f3 100755 --- a/configure.py +++ b/configure.py @@ -569,8 +569,6 @@ raft_tests = set([ apps = set([ 'scylla', 'test/tools/cql_repl', - 'tools/scylla-types', - 'tools/scylla-sstable', ]) tests = scylla_tests | perf_tests | raft_tests @@ -1147,12 +1145,11 @@ scylla_tests_dependencies = scylla_core + idls + scylla_tests_generic_dependenci scylla_raft_dependencies = scylla_raft_core + ['utils/uuid.cc'] +scylla_tools = ['tools/scylla-types.cc', 'tools/scylla-sstable.cc', 'tools/schema_loader.cc'] + deps = { - 'scylla': idls + ['main.cc'] + scylla_core + api + alternator + redis, + 'scylla': idls + ['main.cc'] + scylla_core + api + alternator + redis + scylla_tools, 'test/tools/cql_repl': idls + ['test/tools/cql_repl.cc'] + scylla_core + scylla_tests_generic_dependencies, - #FIXME: we don't need all of scylla_core here, only the types module, need to modularize scylla_core. - 'tools/scylla-types': idls + ['tools/scylla-types.cc'] + scylla_core, - 'tools/scylla-sstable': idls + ['tools/scylla-sstable.cc', 'tools/schema_loader.cc'] + scylla_core, } pure_boost_tests = set([ diff --git a/main.cc b/main.cc index 98ae78c338..f3c6259d58 100644 --- a/main.cc +++ b/main.cc @@ -96,6 +96,7 @@ #include "service/storage_proxy.hh" #include "alternator/controller.hh" #include "alternator/ttl.hh" +#include "tools/entry_point.hh" #include "service/raft/raft_group_registry.hh" @@ -399,7 +400,7 @@ sharded* the_database; sharded *the_stream_manager; } -int main(int ac, char** av) { +static int scylla_main(int ac, char** av) { // Allow core dumps. The would be disabled by default if // CAP_SYS_NICE was added to the binary, as is suggested by the // epoll backend. @@ -410,14 +411,24 @@ int main(int ac, char** av) { } try { - // early check to avoid triggering - if (!cpu_sanity()) { - _exit(71); - } runtime::init_uptime(); std::setvbuf(stdout, nullptr, _IOLBF, 1000); app_template::config app_cfg; app_cfg.name = "Scylla"; + app_cfg.description = +R"(scylla - NoSQL data store using the seastar framework, compatible with Apache Cassandra + +For more information, see https://github.com/scylladb/scylla. + +The scylla executable hosts multiple apps: +* server (default) - the scylla server itself. +* types - a command-line tool to examine values belonging to scylla types. +* sstable - a multifunctional command-line tool to examine the content of sstables. + +Usage: scylla {app_name} [...] + +For more information about individual apps, run: scylla {app_name} --help +)"; app_cfg.default_task_quota = 500us; app_cfg.auto_handle_sigint_sigterm = false; app_cfg.max_networking_aio_io_control_blocks = 50000; @@ -1457,3 +1468,40 @@ int main(int ac, char** av) { return 7; // 1 has a special meaning for upstart } } + +int main(int ac, char** av) { + // early check to avoid triggering + if (!cpu_sanity()) { + _exit(71); + } + + std::function main_func; + + std::string exec_name; + if (ac >= 2) { + exec_name = av[1]; + } + + bool recognized = true; + if (exec_name == "server") { + main_func = scylla_main; + } else if (exec_name == "types") { + main_func = tools::scylla_types_main; + } else if (exec_name == "sstable") { + main_func = tools::scylla_sstable_main; + } else { + fmt::print("Unrecognized or missing app name (argv[1]={}), assuming server\n", exec_name); + main_func = scylla_main; + recognized = false; + } + + if (recognized) { + // shift args to consume the recognized app name + --ac; + for (int i = 1; i < ac; ++i) { + std::swap(av[i], av[i + 1]); + } + } + + return main_func(ac, av); +} diff --git a/tools/entry_point.hh b/tools/entry_point.hh new file mode 100644 index 0000000000..3ecd5c48a5 --- /dev/null +++ b/tools/entry_point.hh @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021-present ScyllaDB + */ + +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +namespace tools { + +int scylla_types_main(int argc, char** argv); +int scylla_sstable_main(int argc, char** argv); + +} // namespace tools diff --git a/tools/scylla-sstable.cc b/tools/scylla-sstable.cc index 72af395210..68ab8427cc 100644 --- a/tools/scylla-sstable.cc +++ b/tools/scylla-sstable.cc @@ -1110,7 +1110,9 @@ const std::vector operations{ } // anonymous namespace -int main(int argc, char** argv) { +namespace tools { + +int scylla_sstable_main(int argc, char** argv) { app_template::config app_cfg; app_cfg.name = app_name; @@ -1243,3 +1245,5 @@ $ scylla-sstable --validate /path/to/md-123456-big-Data.db /path/to/md-123457-bi }); }); } + +} // namespace tools diff --git a/tools/scylla-types.cc b/tools/scylla-types.cc index c06e304500..f3a199dcf8 100644 --- a/tools/scylla-types.cc +++ b/tools/scylla-types.cc @@ -167,7 +167,9 @@ const std::vector action_handlers = { } -int main(int argc, char** argv) { +namespace tools { + +int scylla_types_main(int argc, char** argv) { namespace bpo = boost::program_options; app_template::config app_cfg; @@ -254,3 +256,5 @@ $ scylla-types --print --prefix-compound -t TimeUUIDType -t Int32Type 0010d00819 return make_ready_future<>(); }); } + +} // namespace tools