You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ba...@apache.org on 2021/04/19 18:55:20 UTC
[kudu] branch master updated: [mini-cluster] Refactor to expose
flags of ExternalMaster
This is an automated email from the ASF dual-hosted git repository.
bankim pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new a354ce3 [mini-cluster] Refactor to expose flags of ExternalMaster
a354ce3 is described below
commit a354ce3dd7ed8aca88a372ba9a8b6b6f5d60979c
Author: Bankim Bhavsar <ba...@cloudera.com>
AuthorDate: Thu Apr 1 05:35:43 2021 -0700
[mini-cluster] Refactor to expose flags of ExternalMaster
Flags for starting a daemon in ExternalMiniCluster
were embedded in Start() functions and not available outside.
For a subsequent change need to supply flags to start
a master without using the ExternalMiniCluster.
Change-Id: Ibeff3b0d6bc0021ce2aa50e8022542fb32250e07
Reviewed-on: http://gerrit.cloudera.org:8080/17266
Tested-by: Kudu Jenkins
Reviewed-by: Andrew Wong <aw...@cloudera.com>
Reviewed-by: Alexey Serbin <as...@cloudera.com>
---
src/kudu/mini-cluster/external_mini_cluster.cc | 167 ++++++++++++++-----------
src/kudu/mini-cluster/external_mini_cluster.h | 13 +-
2 files changed, 106 insertions(+), 74 deletions(-)
diff --git a/src/kudu/mini-cluster/external_mini_cluster.cc b/src/kudu/mini-cluster/external_mini_cluster.cc
index 26109ce..bca138b 100644
--- a/src/kudu/mini-cluster/external_mini_cluster.cc
+++ b/src/kudu/mini-cluster/external_mini_cluster.cc
@@ -986,61 +986,50 @@ ExternalDaemon::ExternalDaemon(ExternalDaemonOptions opts)
ExternalDaemon::~ExternalDaemon() {
}
-Status ExternalDaemon::StartProcess(const vector<string>& user_flags) {
- CHECK(!process_);
- const auto this_tid = std::this_thread::get_id();
- CHECK_EQ(parent_tid_, this_tid)
- << "Process being started from thread " << this_tid << " which is different"
- << " from the instantiating thread " << parent_tid_;
-
- RETURN_NOT_OK(env_util::CreateDirsRecursively(Env::Default(), log_dir()));
- const string info_path = JoinPathSegments(data_dirs()[0], "info.pb");
-
- vector<string> argv = {
- // First the exe for argv[0].
- opts_.exe,
-
- // Basic flags for Kudu server.
- "--fs_wal_dir=" + wal_dir(),
- "--fs_data_dirs=" + JoinStrings(data_dirs(), ","),
- "--block_manager=" + opts_.block_manager_type,
- "--webserver_interface=localhost",
-
- // Disable fsync to dramatically speed up runtime. This is safe as no tests
- // rely on forcefully cutting power to a machine or equivalent.
- "--never_fsync",
-
- // Disable minidumps by default since many tests purposely inject faults.
- "--enable_minidumps=false",
-
- // Disable redaction of the information in logs and Web UI.
- "--redact=none",
-
- // Enable metrics logging.
- "--metrics_log_interval_ms=1000",
-
- // Even if we are logging to stderr, metrics logs and minidumps end up being
- // written based on -log_dir. So, we have to set that too.
- "--log_dir=" + log_dir(),
-
- // Tell the server to dump its port information so we can pick it up.
- "--server_dump_info_path=" + info_path,
- "--server_dump_info_format=pb",
-
- // We use ephemeral ports in many tests. They don't work for production,
- // but are OK in unit tests.
- "--rpc_server_allow_ephemeral_ports",
-
- // Allow unsafe and experimental flags from tests, since we often use
- // fault injection, etc.
- "--unlock_experimental_flags",
- "--unlock_unsafe_flags",
+std::vector<std::string> ExternalDaemon::GetDaemonFlags(const ExternalDaemonOptions& opts) {
+ const string info_path = JoinPathSegments(opts.data_dirs[0], "info.pb");
+ vector<string> flags = {
+ // Basic flags for a Kudu server.
+ "--fs_wal_dir=" + opts.wal_dir,
+ "--fs_data_dirs=" + JoinStrings(opts.data_dirs, ","),
+ "--block_manager=" + opts.block_manager_type,
+ "--webserver_interface=localhost",
+
+ // Disable fsync to dramatically speed up runtime. This is safe as no tests
+ // rely on forcefully cutting power to a machine or equivalent.
+ "--never_fsync",
+
+ // Disable minidumps by default since many tests purposely inject faults.
+ "--enable_minidumps=false",
+
+ // Disable redaction of the information in logs and Web UI.
+ "--redact=none",
+
+ // Enable metrics logging.
+ "--metrics_log_interval_ms=1000",
+
+ // Even if we are logging to stderr, metrics logs and minidumps end up being
+ // written based on -log_dir. So, we have to set that too.
+ "--log_dir=" + opts.log_dir,
+
+ // Tell the server to dump its port information so we can pick it up.
+ "--server_dump_info_path=" + info_path,
+ "--server_dump_info_format=pb",
+
+ // We use ephemeral ports in many tests. They don't work for production,
+ // but are OK in unit tests.
+ "--rpc_server_allow_ephemeral_ports",
+
+ // Allow unsafe and experimental flags from tests, since we often use
+ // fault injection, etc.
+ "--unlock_experimental_flags",
+ "--unlock_unsafe_flags",
};
- if (opts_.logtostderr) {
+ if (opts.logtostderr) {
// Ensure that logging goes to the test output and doesn't get buffered.
- argv.emplace_back("--logtostderr");
- argv.emplace_back("--logbuflevel=-1");
+ flags.emplace_back("--logtostderr");
+ flags.emplace_back("--logbuflevel=-1");
}
// If large keys are not enabled.
@@ -1052,14 +1041,32 @@ Status ExternalDaemon::StartProcess(const vector<string>& user_flags) {
// since we are using strong/high TLS v1.2 cipher suites, so the minimum
// size of TLS-related RSA key is 768 bits (due to the usage of
// the ECDHE-RSA-AES256-GCM-SHA384 suite).
- argv.emplace_back("--ipki_server_key_size=768");
+ flags.emplace_back("--ipki_server_key_size=768");
// The RSA key of 768 bits is too short if OpenSSL security level is set to
// 1 or higher (applicable for OpenSSL 1.1.0 and newer). Lowering the
// security level to 0 makes possible ot use shorter keys in such cases.
- argv.emplace_back("--openssl_security_level_override=0");
+ flags.emplace_back("--openssl_security_level_override=0");
}
+ return flags;
+}
+
+Status ExternalDaemon::StartProcess(const vector<string>& user_flags) {
+ CHECK(!process_);
+ const auto this_tid = std::this_thread::get_id();
+ CHECK_EQ(parent_tid_, this_tid)
+ << "Process being started from thread " << this_tid << " which is different"
+ << " from the instantiating thread " << parent_tid_;
+
+ RETURN_NOT_OK(env_util::CreateDirsRecursively(Env::Default(), log_dir()));
+ const string info_path = JoinPathSegments(data_dirs()[0], "info.pb");
+
+ vector<string> argv = { /* First the exe for argv[0] */ opts_.exe };
+ vector<string> flags = GetDaemonFlags(opts_);
+ argv.insert(argv.end(), std::make_move_iterator(flags.begin()),
+ std::make_move_iterator(flags.end()));
+
// Add all the flags coming from the minicluster framework.
argv.insert(argv.end(), user_flags.begin(), user_flags.end());
@@ -1415,10 +1422,10 @@ ExternalMaster::~ExternalMaster() {
}
Status ExternalMaster::Start() {
- vector<string> flags(GetCommonFlags());
- flags.push_back(Substitute("--rpc_bind_addresses=$0", rpc_bind_address().ToString()));
- flags.push_back(Substitute("--webserver_interface=$0", rpc_bind_address().host()));
- flags.emplace_back("--webserver_port=0");
+ vector<string> flags { "master", "run" };
+ auto common_flags = GetCommonFlags(rpc_bind_address());
+ flags.insert(flags.end(), std::make_move_iterator(common_flags.begin()),
+ std::make_move_iterator(common_flags.end()));
return StartProcess(flags);
}
@@ -1428,16 +1435,10 @@ Status ExternalMaster::Restart() {
return Status::IllegalState("Master cannot be restarted. Must call Shutdown() first.");
}
- vector<string> flags(GetCommonFlags());
- flags.push_back(Substitute("--rpc_bind_addresses=$0", bound_rpc_.ToString()));
- if (bound_http_.Initialized()) {
- flags.push_back(Substitute("--webserver_interface=$0", bound_http_.host()));
- flags.push_back(Substitute("--webserver_port=$0", bound_http_.port()));
- } else {
- flags.push_back(Substitute("--webserver_interface=$0", bound_rpc_.host()));
- flags.emplace_back("--webserver_port=0");
- }
-
+ vector<string> flags { "master", "run" };
+ auto common_flags = GetCommonFlags(bound_rpc_, bound_http_);
+ flags.insert(flags.end(), std::make_move_iterator(common_flags.begin()),
+ std::make_move_iterator(common_flags.end()));
return StartProcess(flags);
}
@@ -1486,17 +1487,37 @@ Status ExternalMaster::WaitForCatalogManager(WaitMode wait_mode) {
return Status::OK();
}
-const vector<string>& ExternalMaster::GetCommonFlags() {
- static vector<string> kFlags { "master", "run" };
+vector<string> ExternalMaster::GetCommonFlags(const HostPort& rpc_bind_addr,
+ const HostPort& http_addr) {
+ vector<string> flags;
if (!UseLargeKeys()) {
// See the in-line comment for "--ipki_server_key_size" flag in
// ExternalDaemon::StartProcess() method.
- kFlags.emplace_back("--ipki_ca_key_size=768");
+ flags.emplace_back("--ipki_ca_key_size=768");
// As for the TSK keys, 512 bits is the minimum since we are using
// SHA256 digest for token signing/verification.
- kFlags.emplace_back("--tsk_num_rsa_bits=512");
+ flags.emplace_back("--tsk_num_rsa_bits=512");
}
- return kFlags;
+
+ flags.emplace_back(Substitute("--rpc_bind_addresses=$0", rpc_bind_addr.ToString()));
+
+ if (http_addr.Initialized()) {
+ flags.emplace_back(Substitute("--webserver_interface=$0", http_addr.host()));
+ flags.emplace_back(Substitute("--webserver_port=$0", http_addr.port()));
+ } else {
+ flags.emplace_back(Substitute("--webserver_interface=$0", rpc_bind_addr.host()));
+ flags.emplace_back("--webserver_port=0");
+ }
+
+ return flags;
+}
+
+vector<string> ExternalMaster::GetMasterFlags(const ExternalDaemonOptions& opts) {
+ vector<string> flags(ExternalDaemon::GetDaemonFlags(opts));
+ auto common_flags = GetCommonFlags(opts.rpc_bind_address);
+ flags.insert(flags.end(), std::make_move_iterator(common_flags.begin()),
+ std::make_move_iterator(common_flags.end()));
+ return flags;
}
//------------------------------------------------------------
diff --git a/src/kudu/mini-cluster/external_mini_cluster.h b/src/kudu/mini-cluster/external_mini_cluster.h
index 369d9d0..0823384 100644
--- a/src/kudu/mini-cluster/external_mini_cluster.h
+++ b/src/kudu/mini-cluster/external_mini_cluster.h
@@ -658,6 +658,10 @@ class ExternalDaemon : public RefCountedThreadSafe<ExternalDaemon> {
// LOG(FATAL) if there are any leaks.
void CheckForLeaks();
+ // Get flags for an ExternalDaemon from the supplied 'opts'.
+ // It does not include executable or any positional arguments.
+ static std::vector<std::string> GetDaemonFlags(const ExternalDaemonOptions& opts);
+
// Get RPC bind address for daemon.
const HostPort& rpc_bind_address() const {
return opts_.rpc_bind_address;
@@ -727,9 +731,16 @@ class ExternalMaster : public ExternalDaemon {
Status WaitForCatalogManager(
WaitMode wait_mode = DONT_WAIT_FOR_LEADERSHIP) WARN_UNUSED_RESULT;
+ // Get all flags for a master from the supplied 'opts'.
+ // It does not include executable or any positional arguments like "master run".
+ static std::vector<std::string> GetMasterFlags(const ExternalDaemonOptions& opts);
private:
friend class RefCountedThreadSafe<ExternalMaster>;
- static const std::vector<std::string>& GetCommonFlags();
+ // Get flags specific to ExternalMaster where 'rpc_bind_addr' and 'http_addr' are
+ // the RPC and HTTP addresses to bind in case of start or the corresponding bound
+ // addresses in case of restart.
+ static std::vector<std::string> GetCommonFlags(const HostPort& rpc_bind_addr,
+ const HostPort& http_addr = HostPort());
virtual ~ExternalMaster();
};