2017-01-20 17:58:07 +00:00
|
|
|
#include <common/config_common.h>
|
2017-01-27 20:00:02 +00:00
|
|
|
#if USE_TCMALLOC
|
2016-12-28 00:47:46 +00:00
|
|
|
#include <gperftools/malloc_extension.h>
|
|
|
|
#endif
|
2016-10-25 12:14:27 +00:00
|
|
|
#include "Server.h"
|
|
|
|
#include "LocalServer.h"
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/StringUtils.h>
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2016-10-31 19:54:49 +00:00
|
|
|
/// Universal executable for various clickhouse applications
|
2016-11-11 17:01:02 +00:00
|
|
|
int mainEntryClickHouseServer(int argc, char ** argv);
|
2017-03-24 15:05:54 +00:00
|
|
|
int mainEntryClickHouseClient(int argc, char ** argv);
|
|
|
|
int mainEntryClickHouseLocal(int argc, char ** argv);
|
|
|
|
int mainEntryClickHouseBenchmark(int argc, char ** argv);
|
2017-09-06 02:19:52 +00:00
|
|
|
int mainEntryClickHousePerformanceTest(int argc, char ** argv);
|
2017-03-24 15:05:54 +00:00
|
|
|
int mainEntryClickHouseExtractFromConfig(int argc, char ** argv);
|
2017-09-20 14:12:12 +00:00
|
|
|
int mainEntryClickHouseCompressor(int argc, char ** argv);
|
2016-10-25 12:14:27 +00:00
|
|
|
|
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[] =
|
|
|
|
{
|
|
|
|
{"local", mainEntryClickHouseLocal},
|
|
|
|
{"client", mainEntryClickHouseClient},
|
|
|
|
{"benchmark", mainEntryClickHouseBenchmark},
|
|
|
|
{"server", mainEntryClickHouseServer},
|
|
|
|
{"performance-test", mainEntryClickHousePerformanceTest},
|
|
|
|
{"extract-from-config", mainEntryClickHouseExtractFromConfig},
|
2017-09-20 14:12:12 +00:00
|
|
|
{"compressor", mainEntryClickHouseCompressor}
|
2017-09-20 13:41:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int printHelp(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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_)
|
|
|
|
{
|
2017-01-27 20:00:02 +00:00
|
|
|
#if USE_TCMALLOC
|
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
|
|
|
}
|