diff --git a/contrib/tiflash-proxy b/contrib/tiflash-proxy index fdae830d7c9..defbe27e00a 160000 --- a/contrib/tiflash-proxy +++ b/contrib/tiflash-proxy @@ -1 +1 @@ -Subproject commit fdae830d7c930063a571688d99f373250e450e12 +Subproject commit defbe27e00ac7b40c4987bb58f265099effda83f diff --git a/dbms/src/Common/Timer.h b/dbms/src/Common/Timer.h index 12192b5d932..40d6d421664 100644 --- a/dbms/src/Common/Timer.h +++ b/dbms/src/Common/Timer.h @@ -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) {} diff --git a/dbms/src/Core/Defines.h b/dbms/src/Core/Defines.h index c9e292f5e5a..b593860705c 100644 --- a/dbms/src/Core/Defines.h +++ b/dbms/src/Core/Defines.h @@ -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 + #if !defined(__x86_64__) && !defined(__aarch64__) // #error PLATFORM_NOT_SUPPORTED #endif diff --git a/dbms/src/Server/HTTPHandler.cpp b/dbms/src/Server/HTTPHandler.cpp index 5f820999892..5fa58e2720f 100644 --- a/dbms/src/Server/HTTPHandler.cpp +++ b/dbms/src/Server/HTTPHandler.cpp @@ -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"); } diff --git a/dbms/src/Server/MetricsPrometheus.cpp b/dbms/src/Server/MetricsPrometheus.cpp index f31b203f60c..a79105e39c3 100644 --- a/dbms/src/Server/MetricsPrometheus.cpp +++ b/dbms/src/Server/MetricsPrometheus.cpp @@ -90,7 +90,12 @@ std::shared_ptr getHTTPServer( const std::weak_ptr & 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 check_common_name = [&](const Poco::Crypto::X509Certificate & cert) { if (security_config.allowed_common_names.empty()) @@ -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); if (metrics_interval < 5) { @@ -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!"); @@ -174,9 +182,11 @@ MetricsPrometheus::MetricsPrometheus( } } - if (conf.hasOption(status_metrics_port)) + // Usually TiFlash enables Prometheus pull mode when deployed by TiUP/TiDB-Operator. + // Enable pull mode by default when push mode is disabled. + 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); @@ -244,8 +254,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); } diff --git a/dbms/src/Server/RaftConfigParser.cpp b/dbms/src/Server/RaftConfigParser.cpp index e80ae35b7f5..65c3e0697b9 100644 --- a/dbms/src/Server/RaftConfigParser.cpp +++ b/dbms/src/Server/RaftConfigParser.cpp @@ -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) @@ -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; } @@ -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(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(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(res.engine) - << "] [snapshot.method=" << applyMethodToString(res.snapshot_apply_method) << "]"); + LOG_INFO(log, fmt::format("Default storage engine [type={}] [snapshot.method={}]", static_cast(res.engine), applyMethodToString(res.snapshot_apply_method))); return res; } diff --git a/dbms/src/Server/Server.cpp b/dbms/src/Server/Server.cpp index 1dd55305ad6..78dc7a71dab 100644 --- a/dbms/src/Server/Server.cpp +++ b/dbms/src/Server/Server.cpp @@ -216,11 +216,12 @@ struct TiFlashProxyConfig std::unordered_map 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) { @@ -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 @@ -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")) { @@ -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")) @@ -1159,7 +1161,7 @@ int Server::main(const std::vector & /*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); diff --git a/dbms/src/Server/TCPHandler.h b/dbms/src/Server/TCPHandler.h index 53ef2d0d4bd..a7c7c2abe9c 100644 --- a/dbms/src/Server/TCPHandler.h +++ b/dbms/src/Server/TCPHandler.h @@ -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(); diff --git a/etc/config-template.toml b/etc/config-template.toml index 01975844d93..63af9761e22 100644 --- a/etc/config-template.toml +++ b/etc/config-template.toml @@ -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" @@ -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" @@ -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 @@ -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. @@ -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 \ No newline at end of file +# redact_info_log = false diff --git a/libs/libdaemon/src/BaseDaemon.cpp b/libs/libdaemon/src/BaseDaemon.cpp index 3028e497546..7ec32b1ae91 100644 --- a/libs/libdaemon/src/BaseDaemon.cpp +++ b/libs/libdaemon/src/BaseDaemon.cpp @@ -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 split = new Poco::ReloadableSplitterChannel; @@ -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); @@ -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); diff --git a/libs/libdaemon/src/tests/gtest_daemon_config.cpp b/libs/libdaemon/src/tests/gtest_daemon_config.cpp index 6fe6ecb03a7..50f04ead350 100644 --- a/libs/libdaemon/src/tests/gtest_daemon_config.cpp +++ b/libs/libdaemon/src/tests/gtest_daemon_config.cpp @@ -47,7 +47,7 @@ static void verifyChannelConfig(Poco::Channel & channel, Poco::Util::AbstractCon { Poco::TiFlashLogFileChannel * fileChannel = dynamic_cast(&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)) @@ -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 @@ -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" diff --git a/libs/libpocoext/src/ReloadableSplitterChannel.cpp b/libs/libpocoext/src/ReloadableSplitterChannel.cpp index 2b6b47d71fb..6e31bdfccce 100644 --- a/libs/libpocoext/src/ReloadableSplitterChannel.cpp +++ b/libs/libpocoext/src/ReloadableSplitterChannel.cpp @@ -11,7 +11,7 @@ void ReloadableSplitterChannel::setPropertiesRecursively(Channel & channel, Util { TiFlashLogFileChannel * fileChannel = dynamic_cast(&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))