2019-03-12 19:30:59 +00:00
|
|
|
#include <new>
|
2018-04-05 19:28:07 +00:00
|
|
|
#include <iostream>
|
2018-04-05 14:27:39 +00:00
|
|
|
#include <vector>
|
2018-04-05 19:28:07 +00:00
|
|
|
#include <string>
|
2018-11-26 00:56:50 +00:00
|
|
|
#include <utility> /// pair
|
2017-11-12 12:58:40 +00:00
|
|
|
|
2018-06-19 18:09:09 +00:00
|
|
|
#if __has_include("config_tools.h")
|
|
|
|
#include "config_tools.h"
|
|
|
|
#endif
|
|
|
|
#if __has_include(<common/config_common.h>) /// "Arcadia" build system lacks configure files.
|
|
|
|
#include <common/config_common.h>
|
|
|
|
#endif
|
2019-06-24 11:17:15 +00:00
|
|
|
#if __has_include("config_core.h")
|
|
|
|
#include "config_core.h"
|
2018-06-19 18:09:09 +00:00
|
|
|
#endif
|
|
|
|
|
2017-01-27 20:00:02 +00:00
|
|
|
#if USE_TCMALLOC
|
2019-06-05 11:52:39 +00:00
|
|
|
#include <gperftools/malloc_extension.h>
|
2016-12-28 00:47:46 +00:00
|
|
|
#endif
|
2017-11-12 12:58:40 +00:00
|
|
|
|
2018-01-15 19:07:47 +00:00
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2019-07-24 15:26:23 +00:00
|
|
|
#include <common/phdr_cache.h>
|
|
|
|
|
|
|
|
|
2016-10-31 19:54:49 +00:00
|
|
|
/// Universal executable for various clickhouse applications
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_SERVER || !defined(ENABLE_CLICKHOUSE_SERVER)
|
2016-11-11 17:01:02 +00:00
|
|
|
int mainEntryClickHouseServer(int argc, char ** argv);
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_CLIENT || !defined(ENABLE_CLICKHOUSE_CLIENT)
|
2017-03-24 15:05:54 +00:00
|
|
|
int mainEntryClickHouseClient(int argc, char ** argv);
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_LOCAL || !defined(ENABLE_CLICKHOUSE_LOCAL)
|
2017-03-24 15:05:54 +00:00
|
|
|
int mainEntryClickHouseLocal(int argc, char ** argv);
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_BENCHMARK || !defined(ENABLE_CLICKHOUSE_BENCHMARK)
|
2017-03-24 15:05:54 +00:00
|
|
|
int mainEntryClickHouseBenchmark(int argc, char ** argv);
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2019-03-04 17:47:31 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_PERFORMANCE_TEST || !defined(ENABLE_CLICKHOUSE_PERFORMANCE_TEST)
|
2017-09-06 02:19:52 +00:00
|
|
|
int mainEntryClickHousePerformanceTest(int argc, char ** argv);
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_EXTRACT_FROM_CONFIG || !defined(ENABLE_CLICKHOUSE_EXTRACT_FROM_CONFIG)
|
2017-03-24 15:05:54 +00:00
|
|
|
int mainEntryClickHouseExtractFromConfig(int argc, char ** argv);
|
2018-06-05 20:09:51 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_COMPRESSOR || !defined(ENABLE_CLICKHOUSE_COMPRESSOR)
|
2017-09-20 14:12:12 +00:00
|
|
|
int mainEntryClickHouseCompressor(int argc, char ** argv);
|
2018-06-05 20:09:51 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_FORMAT || !defined(ENABLE_CLICKHOUSE_FORMAT)
|
2017-11-11 01:04:14 +00:00
|
|
|
int mainEntryClickHouseFormat(int argc, char ** argv);
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_COPIER || !defined(ENABLE_CLICKHOUSE_COPIER)
|
2017-10-13 19:13:41 +00:00
|
|
|
int mainEntryClickHouseClusterCopier(int argc, char ** argv);
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-12-27 14:30:48 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_OBFUSCATOR || !defined(ENABLE_CLICKHOUSE_OBFUSCATOR)
|
2018-06-16 00:27:59 +00:00
|
|
|
int mainEntryClickHouseObfuscator(int argc, char ** argv);
|
|
|
|
#endif
|
2018-08-07 17:57:44 +00:00
|
|
|
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2017-11-12 12:58:40 +00:00
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
int mainEntryClickHouseClang(int argc, char ** argv);
|
|
|
|
int mainEntryClickHouseLLD(int argc, char ** argv);
|
|
|
|
#endif
|
|
|
|
|
2017-09-20 13:41:13 +00:00
|
|
|
namespace
|
2016-10-25 12:14:27 +00:00
|
|
|
{
|
2016-10-31 19:54:49 +00:00
|
|
|
|
2017-09-20 13:41:13 +00:00
|
|
|
using MainFunc = int (*)(int, char**);
|
|
|
|
|
|
|
|
|
|
|
|
/// Add an item here to register new application
|
|
|
|
std::pair<const char *, MainFunc> clickhouse_applications[] =
|
|
|
|
{
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_LOCAL || !defined(ENABLE_CLICKHOUSE_LOCAL)
|
2017-09-20 13:41:13 +00:00
|
|
|
{"local", mainEntryClickHouseLocal},
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_CLIENT || !defined(ENABLE_CLICKHOUSE_CLIENT)
|
2017-09-20 13:41:13 +00:00
|
|
|
{"client", mainEntryClickHouseClient},
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_BENCHMARK || !defined(ENABLE_CLICKHOUSE_BENCHMARK)
|
2017-09-20 13:41:13 +00:00
|
|
|
{"benchmark", mainEntryClickHouseBenchmark},
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_SERVER || !defined(ENABLE_CLICKHOUSE_SERVER)
|
2017-09-20 13:41:13 +00:00
|
|
|
{"server", mainEntryClickHouseServer},
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2019-03-04 17:47:31 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_PERFORMANCE_TEST || !defined(ENABLE_CLICKHOUSE_PERFORMANCE_TEST)
|
2017-09-20 13:41:13 +00:00
|
|
|
{"performance-test", mainEntryClickHousePerformanceTest},
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_EXTRACT_FROM_CONFIG || !defined(ENABLE_CLICKHOUSE_EXTRACT_FROM_CONFIG)
|
2017-09-20 13:41:13 +00:00
|
|
|
{"extract-from-config", mainEntryClickHouseExtractFromConfig},
|
2018-06-06 16:05:53 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_COMPRESSOR || !defined(ENABLE_CLICKHOUSE_COMPRESSOR)
|
2017-11-11 01:04:14 +00:00
|
|
|
{"compressor", mainEntryClickHouseCompressor},
|
2018-06-06 16:05:53 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_FORMAT || !defined(ENABLE_CLICKHOUSE_FORMAT)
|
2017-11-12 12:58:40 +00:00
|
|
|
{"format", mainEntryClickHouseFormat},
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-06-19 18:09:09 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_COPIER || !defined(ENABLE_CLICKHOUSE_COPIER)
|
2018-01-11 20:51:30 +00:00
|
|
|
{"copier", mainEntryClickHouseClusterCopier},
|
2018-02-15 20:57:08 +00:00
|
|
|
#endif
|
2018-12-27 14:30:48 +00:00
|
|
|
#if ENABLE_CLICKHOUSE_OBFUSCATOR || !defined(ENABLE_CLICKHOUSE_OBFUSCATOR)
|
2018-06-16 00:27:59 +00:00
|
|
|
{"obfuscator", mainEntryClickHouseObfuscator},
|
|
|
|
#endif
|
2018-08-07 17:57:44 +00:00
|
|
|
|
2017-11-12 12:58:40 +00:00
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
{"clang", mainEntryClickHouseClang},
|
2018-02-14 17:27:14 +00:00
|
|
|
{"clang++", mainEntryClickHouseClang},
|
2017-11-12 12:58:40 +00:00
|
|
|
{"lld", mainEntryClickHouseLLD},
|
|
|
|
#endif
|
2017-09-20 13:41:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
int printHelp(int, char **)
|
2017-09-20 13:41:13 +00:00
|
|
|
{
|
|
|
|
std::cerr << "Use one of the following commands:" << std::endl;
|
|
|
|
for (auto & application : clickhouse_applications)
|
|
|
|
std::cerr << "clickhouse " << application.first << " [args] " << std::endl;
|
|
|
|
return -1;
|
2018-08-26 01:14:00 +00:00
|
|
|
}
|
2017-09-20 13:41:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool isClickhouseApp(const std::string & app_suffix, std::vector<char *> & argv)
|
|
|
|
{
|
|
|
|
/// Use app if the first arg 'app' is passed (the arg should be quietly removed)
|
|
|
|
if (argv.size() >= 2)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-09-20 13:41:13 +00:00
|
|
|
auto first_arg = argv.begin() + 1;
|
2016-10-31 19:54:49 +00:00
|
|
|
|
2017-09-20 13:41:13 +00:00
|
|
|
/// 'clickhouse --client ...' and 'clickhouse client ...' are Ok
|
|
|
|
if (*first_arg == "--" + app_suffix || *first_arg == app_suffix)
|
|
|
|
{
|
|
|
|
argv.erase(first_arg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Use app if clickhouse binary is run through symbolic link with name clickhouse-app
|
2017-09-20 13:41:13 +00:00
|
|
|
std::string app_name = "clickhouse-" + app_suffix;
|
|
|
|
return !argv.empty() && (app_name == argv[0] || endsWith(argv[0], "/" + app_name));
|
|
|
|
}
|
2016-10-30 18:02:56 +00:00
|
|
|
|
2016-10-31 19:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc_, char ** argv_)
|
|
|
|
{
|
2019-03-12 19:30:59 +00:00
|
|
|
/// Reset new handler to default (that throws std::bad_alloc)
|
|
|
|
/// It is needed because LLVM library clobbers it.
|
|
|
|
std::set_new_handler(nullptr);
|
|
|
|
|
2019-07-24 15:26:23 +00:00
|
|
|
/// PHDR cache is required for query profiler to work reliably
|
|
|
|
/// It also speed up exception handling, but exceptions from dynamically loaded libraries (dlopen) won't work.
|
2019-07-25 19:54:16 +00:00
|
|
|
updatePHDRCache();
|
2019-07-24 15:26:23 +00:00
|
|
|
|
2017-11-12 12:58:40 +00:00
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
if (argc_ >= 2 && 0 == strcmp(argv_[1], "-cc1"))
|
|
|
|
return mainEntryClickHouseClang(argc_, argv_);
|
|
|
|
#endif
|
|
|
|
|
2017-01-27 20:00:02 +00:00
|
|
|
#if USE_TCMALLOC
|
2017-11-11 01:04:14 +00:00
|
|
|
/** Without this option, tcmalloc returns memory to OS too frequently for medium-sized memory allocations
|
|
|
|
* (like IO buffers, column vectors, hash tables, etc.),
|
|
|
|
* that lead to page faults and significantly hurts performance.
|
|
|
|
*/
|
2017-04-01 07:20:54 +00:00
|
|
|
MallocExtension::instance()->SetNumericProperty("tcmalloc.aggressive_memory_decommit", false);
|
2016-12-28 00:47:46 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::vector<char *> argv(argv_, argv_ + argc_);
|
2016-10-31 19:54:49 +00:00
|
|
|
|
2017-09-20 13:41:13 +00:00
|
|
|
/// Print a basic help if nothing was matched
|
|
|
|
MainFunc main_func = printHelp;
|
|
|
|
|
|
|
|
for (auto & application : clickhouse_applications)
|
|
|
|
{
|
|
|
|
if (isClickhouseApp(application.first, argv))
|
|
|
|
{
|
|
|
|
main_func = application.second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-28 17:38:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return main_func(static_cast<int>(argv.size()), argv.data());
|
2016-10-25 12:14:27 +00:00
|
|
|
}
|