Skip to content

Commit

Permalink
modify tiflash default config
Browse files Browse the repository at this point in the history
  • Loading branch information
hehechen committed Nov 9, 2021
1 parent 13e1cf3 commit 933ec28
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion contrib/tiflash-proxy
8 changes: 8 additions & 0 deletions dbms/src/Core/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@

#define PLATFORM_NOT_SUPPORTED "The only supported platforms are x86_64 and AArch64 (work in progress)"

#define DEFAULT_MARK_CACHE_SIZE 5368709120

#define DEFAULT_METRICS_PORT 8234

#define DEFAULT_PROXY_ADDR "127.0.0.1:20170"

#define DEFAULT_HTTP_PORT 8123

#if !defined(__x86_64__) && !defined(__aarch64__)
// #error PLATFORM_NOT_SUPPORTED
#endif
2 changes: 1 addition & 1 deletion dbms/src/Server/HTTPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ HTTPHandler::HTTPHandler(IServer & server_)
: server(server_)
, log(&Poco::Logger::get("HTTPHandler"))
{
server_display_name = server.config().getString("display_name", getFQDNOrHostName());
server_display_name = server.config().getString("display_name", "TiFlash");
}


Expand Down
23 changes: 8 additions & 15 deletions dbms/src/Server/MetricsPrometheus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,18 @@ MetricsPrometheus::MetricsPrometheus(
}
}

if (conf.hasOption(status_metrics_port))
auto metrics_port = conf.getString(status_metrics_port, DB::toString(DEFAULT_METRICS_PORT));
if (security_config.has_tls_config)
{
auto metrics_port = conf.getString(status_metrics_port);
if (security_config.has_tls_config)
{
server = getHTTPServer(security_config, tiflash_metrics.registry, metrics_port);
server->start();
LOG_INFO(log, "Enable prometheus secure pull mode; Metrics Port = " << metrics_port);
}
else
{
exposer = std::make_shared<prometheus::Exposer>(metrics_port);
exposer->RegisterCollectable(tiflash_metrics.registry);
LOG_INFO(log, "Enable prometheus pull mode; Metrics Port = " << metrics_port);
}
server = getHTTPServer(security_config, tiflash_metrics.registry, metrics_port);
server->start();
LOG_INFO(log, "Enable prometheus secure pull mode; Metrics Port = " << metrics_port);
}
else
{
LOG_INFO(log, "Disable prometheus pull mode");
exposer = std::make_shared<prometheus::Exposer>(metrics_port);
exposer->RegisterCollectable(tiflash_metrics.registry);
LOG_INFO(log, "Enable prometheus pull mode; Metrics Port = " << metrics_port);
}

timer.scheduleAtFixedRate(
Expand Down
38 changes: 20 additions & 18 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ struct TiFlashProxyConfig
const char * engine_store_address = "engine-addr";
const char * engine_store_advertise_address = "advertise-engine-addr";
const char * pd_endpoints = "pd-endpoints";
const char * addr = "addr";

explicit TiFlashProxyConfig(Poco::Util::LayeredConfiguration & config)
{
Expand All @@ -239,6 +240,7 @@ struct TiFlashProxyConfig
args_map[pd_endpoints] = config.getString("raft.pd_addr");
args_map[engine_store_version] = TiFlashBuildInfo::getReleaseVersion();
args_map[engine_store_git_hash] = TiFlashBuildInfo::getGitHash();
args_map[addr] = config.getString("flash.proxy.addr", DEFAULT_PROXY_ADDR);
if (!args_map.count(engine_store_address))
args_map[engine_store_address] = config.getString("flash.service_addr");
else
Expand Down Expand Up @@ -627,23 +629,6 @@ class Server::TcpHttpServersHolder
/// For testing purposes, user may omit tcp_port or http_port or https_port in configuration file.
try
{
/// HTTP
if (config.has("http_port"))
{
if (security_config.has_tls_config)
{
throw Exception("tls config is set but https_port is not set ", ErrorCodes::INVALID_CONFIG_PARAMETER);
}
Poco::Net::ServerSocket socket;
auto address = socket_bind_listen(socket, listen_host, config.getInt("http_port"));
socket.setReceiveTimeout(settings.http_receive_timeout);
socket.setSendTimeout(settings.http_send_timeout);
servers.emplace_back(
new HTTPServer(new HTTPHandlerFactory(server, "HTTPHandler-factory"), server_pool, socket, http_params));

LOG_INFO(log, "Listening http://" + address.toString());
}

/// HTTPS
if (config.has("https_port"))
{
Expand Down Expand Up @@ -681,6 +666,23 @@ class Server::TcpHttpServersHolder
ErrorCodes::SUPPORT_IS_DISABLED};
#endif
}
else
{
/// HTTP
if (security_config.has_tls_config)
{
throw Exception("tls config is set but https_port is not set ", ErrorCodes::INVALID_CONFIG_PARAMETER);
}
Poco::Net::ServerSocket socket;
auto address = socket_bind_listen(socket, listen_host, config.getInt("http_port", DEFAULT_HTTP_PORT));
socket.setReceiveTimeout(settings.http_receive_timeout);
socket.setSendTimeout(settings.http_send_timeout);
servers.emplace_back(
new HTTPServer(new HTTPHandlerFactory(server, "HTTPHandler-factory"), server_pool, socket, http_params));

LOG_INFO(log, "Listening http://" + address.toString());
}


/// TCP
if (config.has("tcp_port"))
Expand Down Expand Up @@ -1159,7 +1161,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
Settings & settings = global_context->getSettingsRef();

/// Size of cache for marks (index of MergeTree family of tables). It is necessary.
size_t mark_cache_size = config().getUInt64("mark_cache_size");
size_t mark_cache_size = config().getUInt64("mark_cache_size", DEFAULT_MARK_CACHE_SIZE);
if (mark_cache_size)
global_context->setMarkCache(mark_cache_size);

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Server/TCPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TCPHandler : public Poco::Net::TCPServerConnection
, connection_context(server.context())
, query_context(server.context())
{
server_display_name = server.config().getString("display_name", getFQDNOrHostName());
server_display_name = server.config().getString("display_name", "TiFlash");
}

void run();
Expand Down
6 changes: 3 additions & 3 deletions libs/libdaemon/src/BaseDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ void BaseDaemon::buildLoggers(Poco::Util::AbstractConfiguration & config)
return;
config_logger = current_logger;

bool is_daemon = config.getBool("application.runAsDaemon", false);
bool is_daemon = config.getBool("application.runAsDaemon", true);

// Split log and error log.
Poco::AutoPtr<Poco::ReloadableSplitterChannel> split = new Poco::ReloadableSplitterChannel;
Expand All @@ -755,7 +755,7 @@ void BaseDaemon::buildLoggers(Poco::Util::AbstractConfiguration & config)
log_file->setProperty(Poco::FileChannel::PROP_TIMES, "local");
log_file->setProperty(Poco::FileChannel::PROP_ARCHIVE, "timestamp");
log_file->setProperty(Poco::FileChannel::PROP_COMPRESS, /*config.getRawString("logger.compress", "true")*/ "true");
log_file->setProperty(Poco::FileChannel::PROP_PURGECOUNT, config.getRawString("logger.count", "1"));
log_file->setProperty(Poco::FileChannel::PROP_PURGECOUNT, config.getRawString("logger.count", "10"));
log_file->setProperty(Poco::FileChannel::PROP_FLUSH, config.getRawString("logger.flush", "true"));
log_file->setProperty(Poco::FileChannel::PROP_ROTATEONOPEN, config.getRawString("logger.rotateOnOpen", "false"));
log->setChannel(log_file);
Expand All @@ -779,7 +779,7 @@ void BaseDaemon::buildLoggers(Poco::Util::AbstractConfiguration & config)
error_log_file->setProperty(Poco::FileChannel::PROP_TIMES, "local");
error_log_file->setProperty(Poco::FileChannel::PROP_ARCHIVE, "timestamp");
error_log_file->setProperty(Poco::FileChannel::PROP_COMPRESS, /*config.getRawString("logger.compress", "true")*/ "true");
error_log_file->setProperty(Poco::FileChannel::PROP_PURGECOUNT, config.getRawString("logger.count", "1"));
error_log_file->setProperty(Poco::FileChannel::PROP_PURGECOUNT, config.getRawString("logger.count", "10"));
error_log_file->setProperty(Poco::FileChannel::PROP_FLUSH, config.getRawString("logger.flush", "true"));
error_log_file->setProperty(Poco::FileChannel::PROP_ROTATEONOPEN, config.getRawString("logger.rotateOnOpen", "false"));
errorlog->setChannel(error_log_file);
Expand Down
16 changes: 14 additions & 2 deletions libs/libdaemon/src/tests/gtest_daemon_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void verifyChannelConfig(Poco::Channel & channel, Poco::Util::AbstractCon
{
Poco::TiFlashLogFileChannel * fileChannel = dynamic_cast<Poco::TiFlashLogFileChannel *>(&channel);
ASSERT_EQ(fileChannel->getProperty(Poco::FileChannel::PROP_ROTATION), config.getRawString("logger.size", "100M"));
ASSERT_EQ(fileChannel->getProperty(Poco::FileChannel::PROP_PURGECOUNT), config.getRawString("logger.count", "1"));
ASSERT_EQ(fileChannel->getProperty(Poco::FileChannel::PROP_PURGECOUNT), config.getRawString("logger.count", "10"));
return;
}
if (typeid(channel) == typeid(Poco::LevelFilterChannel))
Expand All @@ -68,6 +68,19 @@ try
{
DB::Strings tests = {
R"(
[application]
runAsDaemon = false
[profiles]
[profiles.default]
max_rows_in_set = 455
dt_page_gc_low_write_prob = 0.2
[logger]
errorlog = "./tmp/log/tiflash_error.log"
level = "debug"
log = "./tmp/log/tiflash.log"
size = "1K"
)",
R"(
[profiles]
[profiles.default]
max_rows_in_set = 455
Expand All @@ -87,7 +100,6 @@ runAsDaemon = false
max_rows_in_set = 455
dt_page_gc_low_write_prob = 0.2
[logger]
count = 10
errorlog = "./tmp/log/tiflash_error.log"
level = "debug"
log = "./tmp/log/tiflash.log"
Expand Down
2 changes: 1 addition & 1 deletion libs/libpocoext/src/ReloadableSplitterChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void ReloadableSplitterChannel::setPropertiesRecursively(Channel & channel, Util
{
TiFlashLogFileChannel * fileChannel = dynamic_cast<TiFlashLogFileChannel *>(&channel);
fileChannel->setProperty(FileChannel::PROP_ROTATION, config.getRawString("logger.size", "100M"));
fileChannel->setProperty(FileChannel::PROP_PURGECOUNT, config.getRawString("logger.count", "1"));
fileChannel->setProperty(FileChannel::PROP_PURGECOUNT, config.getRawString("logger.count", "10"));
return;
}
if (typeid(channel) == typeid(LevelFilterChannel))
Expand Down

0 comments on commit 933ec28

Please sign in to comment.