This is an automated email from the ASF dual-hosted git repository. laiyingchun pushed a commit to branch branch-1.17.x in repository https://gitbox.apache.org/repos/asf/kudu.git
commit a54ec2e54a2eff971cf6c6b3b44a696dd0b2affd Author: Attila Bukor <[email protected]> AuthorDate: Mon Aug 14 14:02:48 2023 +0200 KUDU-3503 Allow extra JVM arguments This commit introduces a new flag to provide extra JVM arguments to the Ranger subprocess. Its test also test the new behavior of crashing the master when a subprocess dies introduced with KUDU-3504. Change-Id: I60f82e8a2fe106b267da3d2acd71a61e5a46a759 Reviewed-on: http://gerrit.cloudera.org:8080/20347 Tested-by: Kudu Jenkins Reviewed-by: Alexey Serbin <[email protected]> (cherry picked from commit 0a9c9e7f81d9e0e63501fc98652027a8ea2dae69) Reviewed-on: http://gerrit.cloudera.org:8080/20415 Reviewed-by: Yingchun Lai <[email protected]> --- src/kudu/ranger/ranger_client-test.cc | 31 +++++++++++++++++++++++++++++++ src/kudu/ranger/ranger_client.cc | 14 +++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/kudu/ranger/ranger_client-test.cc b/src/kudu/ranger/ranger_client-test.cc index 486ab820d..878a47820 100644 --- a/src/kudu/ranger/ranger_client-test.cc +++ b/src/kudu/ranger/ranger_client-test.cc @@ -54,6 +54,7 @@ DECLARE_string(log_dir); DECLARE_string(ranger_config_path); DECLARE_string(ranger_log_config_dir); DECLARE_string(ranger_log_level); +DECLARE_string(ranger_java_extra_args); DECLARE_bool(ranger_logtostdout); DECLARE_bool(ranger_overwrite_log_config); @@ -344,6 +345,7 @@ class RangerClientTestBase : public KuduTest { : test_dir_(GetTestDataDirectory()) {} void SetUp() override { + SKIP_IF_SLOW_NOT_ALLOWED(); metric_entity_ = METRIC_ENTITY_server.Instantiate(&metric_registry_, "ranger_client-test"); FLAGS_ranger_log_level = "debug"; FLAGS_ranger_logtostdout = true; @@ -382,6 +384,35 @@ class RangerClientTestBase : public KuduTest { std::unique_ptr<RangerClient> client_; }; +class RangerClientTestExtraJVMArgs : public RangerClientTestBase { + public: + void SetUp() override { + SKIP_IF_SLOW_NOT_ALLOWED(); + metric_entity_ = METRIC_ENTITY_server.Instantiate(&metric_registry_, "ranger_client-test"); + FLAGS_ranger_log_level = "debug"; + FLAGS_ranger_logtostdout = true; + FLAGS_ranger_config_path = test_dir_; + FLAGS_ranger_log_config_dir = JoinPathSegments(test_dir_, "log_conf"); + FLAGS_log_dir = JoinPathSegments(test_dir_, "logs"); + ASSERT_OK(env_->CreateDir(FLAGS_log_dir)); + } +}; + +TEST_F(RangerClientTestExtraJVMArgs, SmokeTest) { + FLAGS_ranger_java_extra_args = "-Xmx1G -XX:+UseG1GC"; + ASSERT_OK(InitializeRanger()); + + bool authorized; + ASSERT_OK(client_->AuthorizeAction("user", ActionPB::METADATA, "db", "table", /*is_owner=*/false, + /*requires_delegate_admin=*/false, &authorized)); + ASSERT_TRUE(authorized); +} + +TEST_F(RangerClientTestExtraJVMArgs, TestCrashOnInvalidArguments) { + FLAGS_ranger_java_extra_args = "-XX:+InvalidArgumentHopeTheyWontChooseThisNameForAFLag"; + ASSERT_DEATH(InitializeRanger(), "The subprocess has exited with status 1"); +} + namespace { // Looks in --log_dir and returns the full Kudu Ranger subprocess log filename diff --git a/src/kudu/ranger/ranger_client.cc b/src/kudu/ranger/ranger_client.cc index 3046358f4..53be4c182 100644 --- a/src/kudu/ranger/ranger_client.cc +++ b/src/kudu/ranger/ranger_client.cc @@ -32,6 +32,7 @@ #include "kudu/gutil/macros.h" #include "kudu/gutil/map-util.h" #include "kudu/gutil/strings/join.h" +#include "kudu/gutil/strings/split.h" #include "kudu/gutil/strings/substitute.h" #include "kudu/ranger/ranger.pb.h" #include "kudu/security/init.h" @@ -62,6 +63,9 @@ DEFINE_string(ranger_java_path, "", "is used. If $JAVA_HOME is not found, Kudu will attempt to " "find 'java' in the Kudu user's PATH."); +DEFINE_string(ranger_java_extra_args, "", + "Extra JVM arguments to be passed to the Ranger subprocess."); + DEFINE_string(ranger_jar_path, "", "Path to the JAR file containing the Ranger subprocess. If " "not specified, the default JAR file path is expected to be " @@ -352,8 +356,16 @@ Status BuildArgv(const string& fifo_path, const string& log_properties_path, JavaPath(), Substitute("-Djava.security.krb5.conf=$0", GetKrb5ConfigFile()), Substitute("-Dlog4j2.configurationFile=$0", log_properties_path), - "-cp", JavaClasspath(), kMainClass, }; + if (!FLAGS_ranger_java_extra_args.empty()) { + vector<string> args = strings::Split(FLAGS_ranger_java_extra_args, " ", strings::SkipEmpty()); + for (auto& arg : args) { + ret.emplace_back(std::move(arg)); + } + } + ret.emplace_back("-cp"); + ret.emplace_back(JavaClasspath()); + ret.emplace_back(kMainClass); // When Kerberos is enabled in Kudu, pass both Kudu principal and keytab file // to the Ranger subprocess. if (!FLAGS_keytab_file.empty()) {
