Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify tiflash default config #3414

Merged
merged 12 commits into from
Nov 18, 2021
4 changes: 2 additions & 2 deletions dbms/src/Common/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace DB
{
struct Timer : Poco::Util::Timer
struct Timer : public Poco::Util::Timer
{
Timer(const char * name)
explicit Timer(const char * name)
: thread_worker_name(name)
{}

Expand Down
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 (5ULL * 1024 * 1024 * 1024)

#define DEFAULT_METRICS_PORT 8234

#define DEFAULT_PROXY_ADDR "127.0.0.1:20170"

#define DEFAULT_HTTP_PORT 8123

Comment on lines +91 to +98
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can define these constants near where we use them instead of in the Defines.h? If we change them one day, it would make a lot of files need to be re-compiled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can define these constants near where we use them instead of in the Defines.h? If we change them one day, it would make a lot of files need to be re-compiled.

I think it’s better to put the define of the default configuration together, just like the other default configurations in Defines.h.

#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");
hehechen marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down
18 changes: 13 additions & 5 deletions dbms/src/Server/MetricsPrometheus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ std::shared_ptr<Poco::Net::HTTPServer> getHTTPServer(
const std::weak_ptr<prometheus::Collectable> & collectable,
const String & metrics_port)
{
Poco::Net::Context::Ptr context = new Poco::Net::Context(Poco::Net::Context::TLSV1_2_SERVER_USE, security_config.key_path, security_config.cert_path, security_config.ca_path, Poco::Net::Context::VerificationMode::VERIFY_STRICT);
Poco::Net::Context::Ptr context = new Poco::Net::Context(
Poco::Net::Context::TLSV1_2_SERVER_USE,
security_config.key_path,
security_config.cert_path,
security_config.ca_path,
Poco::Net::Context::VerificationMode::VERIFY_STRICT);

std::function<bool(const Poco::Crypto::X509Certificate &)> check_common_name = [&](const Poco::Crypto::X509Certificate & cert) {
if (security_config.allowed_common_names.empty())
Expand Down Expand Up @@ -127,6 +132,8 @@ MetricsPrometheus::MetricsPrometheus(
auto & tiflash_metrics = TiFlashMetrics::instance();
auto & conf = context.getConfigRef();

// Interval to collect `ProfileEvents::Event`/`CurrentMetrics::Metric`/`AsynchronousMetrics`
// When push mode is enabled, it also define the interval that Prometheus client push to pushgateway.
metrics_interval = conf.getInt(status_metrics_interval, 15);
hehechen marked this conversation as resolved.
Show resolved Hide resolved
if (metrics_interval < 5)
{
Expand All @@ -140,6 +147,7 @@ MetricsPrometheus::MetricsPrometheus(
}
LOG_INFO(log, "Config: " << status_metrics_interval << " = " << metrics_interval);

// Usually TiFlash disable prometheus push mode when deployed by TiUP/TiDB-Operator
if (!conf.hasOption(status_metrics_addr))
{
LOG_INFO(log, "Disable prometheus push mode, cause " << status_metrics_addr << " is not set!");
Expand Down Expand Up @@ -174,9 +182,10 @@ MetricsPrometheus::MetricsPrometheus(
}
}

if (conf.hasOption(status_metrics_port))
// Usually TiFlash enable prometheus pull mode when deployed by TiUP/TiDB-Operator
hehechen marked this conversation as resolved.
Show resolved Hide resolved
if (conf.hasOption(status_metrics_port) || !conf.hasOption(status_metrics_addr))
{
auto metrics_port = conf.getString(status_metrics_port);
auto metrics_port = conf.getString(status_metrics_port, DB::toString(DEFAULT_METRICS_PORT));
if (security_config.has_tls_config)
{
server = getHTTPServer(security_config, tiflash_metrics.registry, metrics_port);
Expand Down Expand Up @@ -244,8 +253,7 @@ void MetricsPrometheus::run()

if (gateway != nullptr)
{
auto return_code = gateway->Push();
if (return_code != 200)
if (auto return_code = gateway->Push(); return_code != 200)
{
LOG_WARNING(log, "Failed to push metrics to gateway, return code is " << return_code);
}
Expand Down
37 changes: 19 additions & 18 deletions dbms/src/Server/RaftConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ TiFlashRaftConfig TiFlashRaftConfig::parseSettings(Poco::Util::LayeredConfigurat
{
if (config.has(disable_bg_flush_conf) && config.getBool(disable_bg_flush_conf))
throw Exception("Illegal arguments: disable background flush while using engine " + MutableSupport::txn_storage_name,
ErrorCodes::INVALID_CONFIG_PARAMETER);
ErrorCodes::INVALID_CONFIG_PARAMETER);
res.disable_bg_flush = false;
}
else if (res.engine == ::TiDB::StorageEngine::DT)
Expand All @@ -86,7 +86,7 @@ TiFlashRaftConfig TiFlashRaftConfig::parseSettings(Poco::Util::LayeredConfigurat
/// Which means that we may get the wrong result with outdated schema.
if (config.has(disable_bg_flush_conf) && !config.getBool(disable_bg_flush_conf))
throw Exception("Illegal arguments: enable background flush while using engine " + MutableSupport::delta_tree_storage_name,
ErrorCodes::INVALID_CONFIG_PARAMETER);
ErrorCodes::INVALID_CONFIG_PARAMETER);
res.disable_bg_flush = true;
}

Expand All @@ -108,31 +108,32 @@ TiFlashRaftConfig TiFlashRaftConfig::parseSettings(Poco::Util::LayeredConfigurat
{
res.snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Directory;
}
#if 0
// Not generally available for this file format
else if (snapshot_method == "file2")
{
res.snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Single;
}
#endif
}
switch (res.snapshot_apply_method)
{
case TiDB::SnapshotApplyMethod::DTFile_Directory:
case TiDB::SnapshotApplyMethod::DTFile_Single:
if (res.engine != TiDB::StorageEngine::DT)
{
throw Exception(
"Illegal arguments: can not use DTFile to store snapshot data when the storage engine is not DeltaTree, [engine="
+ DB::toString(static_cast<Int32>(res.engine))
+ "] [snapshot method=" + applyMethodToString(res.snapshot_apply_method) + "]",
ErrorCodes::INVALID_CONFIG_PARAMETER);
}
break;
default:
break;
case TiDB::SnapshotApplyMethod::DTFile_Directory:
case TiDB::SnapshotApplyMethod::DTFile_Single:
if (res.engine != TiDB::StorageEngine::DT)
{
throw Exception(
"Illegal arguments: can not use DTFile to store snapshot data when the storage engine is not DeltaTree, [engine="
+ DB::toString(static_cast<Int32>(res.engine))
+ "] [snapshot method=" + applyMethodToString(res.snapshot_apply_method) + "]",
ErrorCodes::INVALID_CONFIG_PARAMETER);
}
break;
default:
break;
}

LOG_INFO(log,
"Default storage engine [type=" << static_cast<Int64>(res.engine)
<< "] [snapshot.method=" << applyMethodToString(res.snapshot_apply_method) << "]");
LOG_INFO(log, fmt::format("Default storage engine [type={}] [snapshot.method={}]", static_cast<Int64>(res.engine), applyMethodToString(res.snapshot_apply_method)));

return res;
}
Expand Down
48 changes: 25 additions & 23 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ struct TiFlashProxyConfig
std::unordered_map<std::string, std::string> val_map;
bool is_proxy_runnable = false;

const char * engine_store_version = "engine-version";
const char * engine_store_git_hash = "engine-git-hash";
const char * engine_store_address = "engine-addr";
const char * engine_store_advertise_address = "advertise-engine-addr";
const char * pd_endpoints = "pd-endpoints";
const String engine_store_version = "engine-version";
const String engine_store_git_hash = "engine-git-hash";
const String engine_store_address = "engine-addr";
const String engine_store_advertise_address = "advertise-engine-addr";
const String pd_endpoints = "pd-endpoints";
const String 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
55 changes: 30 additions & 25 deletions etc/config-template.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# display_name = "TiFlash"

## The listening host for supporting services such as TPC/HTTP. It is recommended to configure it as "0.0.0.0", which means to listen on all IP addresses of this machine.
# listen_host = "0.0.0.0"
## The cache size limit of the metadata of a data block. Generally, you do not need to change this value.
# mark_cache_size = 5368709120
## The cache size limit of the min-max index of a data block. Generally, you do not need to change this value.
# minmax_index_cache_size = 5368709120
## The TiFlash TCP service port.
# tcp_port = 9000
## The TiFlash HTTP service port.
# http_port = 8123
## The cache size limit of the metadata of a data block. Generally, you do not need to change this value.
# mark_cache_size = 5368709120
## The cache size limit of the min-max index of a data block. Generally, you do not need to change this value.
# minmax_index_cache_size = 5368709120

## The path in which the TiFlash temporary files are stored. By default it is the first directory in storage.latest.dir appended with "/tmp".
# tmp_path = "/tidb-data/tiflash-9000/tmp"
Expand Down Expand Up @@ -90,34 +88,36 @@
[flash]
# tidb_status_addr = "tidb0:10080"
# service_addr = "0.0.0.0:3930"
# compact_log_min_period = "120"
# compact_log_min_rows = "40960"
# compact_log_min_bytes = "33554432"
# replica_read_max_thread = "1"
# batch_read_index_timeout_ms = "10000"
# wait_index_timeout_ms = "300000"
# wait_region_ready_timeout_sec = "1200"
# compact_log_min_period = 120
# overlap_threshold = 0.6
# compact_log_min_rows = 40960
# compact_log_min_bytes = 33554432
# replica_read_max_thread = 1
# batch_read_index_timeout_ms = 10000
# wait_index_timeout_ms = 300000
# wait_region_ready_timeout_sec = 1200
[flash.flash_cluster]
# update_rule_interval = 5
# update_rule_interval = 10
# master_ttl = 60
# cluster_manager_path = "./flash_cluster_manager"
# log = "[tmp_path]/flash_cluster_manager.log"
[flash.proxy]
# addr = "0.0.0.0:20170"
# advertise-addr = "tiflash0:20170"
# data-dir = "/data"
# config = "/proxy.toml"
# log-file = "/log/proxy.log"
# engine-addr = "tiflash0:3930"
# log-level = "info"
# status-addr = "0.0.0.0:20181"
# advertise-status-addr = "tiflash0:20181"
# engine-addr = "tiflash0:3930"

[logger]
# count = 10
# errorlog = "/tmp/tiflash/log/error.log"
# size = "1000M"
# log = "/tmp/tiflash/log/server.log"
# level = "trace"

[application]
# runAsDaemon = true
# level = "debug"
# errorlog = "/tmp/tiflash/log/error.log"
# size = "100M"
# count = 10

[raft]
# pd_addr = "pd0:2379"
Expand All @@ -127,9 +127,14 @@

[raft.snapshot]
# The way to apply snapshot data
# The value is one of "block" / "file1" / "file2".
# The value is one of "block" / "file1"
# method = "file1"

[status]
# The port through which Prometheus pulls metrics information.
# metrics_port = 8234
# metrics_interval = 15

[profiles]
[profiles.default]
## The default value is true. This parameter determines whether the segment
Expand All @@ -147,8 +152,8 @@
# cop_pool_size = 0
## New in v5.0. This item specifies the maximum number of batch requests that TiFlash Coprocessor executes at the same time. If the number of requests exceeds the specified value, the exceeded requests will queue. If the configuration value is set to 0 or not set, the default value is used, which is twice the number of physical cores.
# batch_cop_pool_size = 0
## Security settings take effect starting from v4.0.5.

## Security settings take effect starting from v4.0.5.
[security]
## Path of the file that contains a list of trusted SSL CAs. If set, the following settings
## cert_path and key_path are also needed.
Expand All @@ -160,4 +165,4 @@
## New in v5.0. This configuration item enables or disables log redaction. If the configuration value
## is set to true, all user data in the log will be replaced by ?.
## Note that you also need to set security.redact-info-log for tiflash-learner's logging in tiflash-learner.toml.
# redact_info_log = false
# redact_info_log = false
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);
hehechen marked this conversation as resolved.
Show resolved Hide resolved

// 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"));
hehechen marked this conversation as resolved.
Show resolved Hide resolved
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
Loading