This is an automated email from the ASF dual-hosted git repository. granthenke pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 1d1abbfb6a421df39843d6c3e4f18089b86e632e Author: oclarms <[email protected]> AuthorDate: Fri Jun 14 17:20:56 2019 +0800 [tools] Add get/set extra-configs for CLI tools Change-Id: I90c790bbfe41a59f621157ff6b3f11d2b8f916e7 Reviewed-on: http://gerrit.cloudera.org:8080/13649 Reviewed-by: Andrew Wong <[email protected]> Tested-by: Kudu Jenkins --- src/kudu/tools/kudu-admin-test.cc | 90 +++++++++++++++++++++++++++++++++++++ src/kudu/tools/kudu-tool-test.cc | 2 + src/kudu/tools/tool_action_table.cc | 66 +++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) diff --git a/src/kudu/tools/kudu-admin-test.cc b/src/kudu/tools/kudu-admin-test.cc index 4be0f27..a9a0cc0 100644 --- a/src/kudu/tools/kudu-admin-test.cc +++ b/src/kudu/tools/kudu-admin-test.cc @@ -2251,5 +2251,95 @@ TEST_F(AdminCliTest, TestAuthzResetCacheNotImplemented) { "Not implemented: provider does not have privileges cache"); } +TEST_F(AdminCliTest, TestExtraConfig) { + NO_FATALS(BuildAndStart()); + + string master_address = cluster_->master()->bound_rpc_addr().ToString(); + + // Gets extra-configs when no extra config set. + { + string stdout, stderr; + Status s = RunKuduTool({ + "table", + "get_extra_configs", + master_address, + kTableId + }, &stdout, &stderr); + ASSERT_TRUE(s.ok()) << ToolRunInfo(s, stdout, stderr); + ASSERT_EQ(stdout, " Configuration | Value\n" + "---------------+-------\n"); + } + + // Sets "kudu.table.history_max_age_sec" to 3600. + { + ASSERT_TOOL_OK( + "table", + "set_extra_config", + master_address, + kTableId, + "kudu.table.history_max_age_sec", + "3600" + ); + } + + // Gets all extra-configs. + { + string stdout, stderr; + Status s = RunKuduTool({ + "table", + "get_extra_configs", + master_address, + kTableId, + }, &stdout, &stderr); + ASSERT_TRUE(s.ok()) << ToolRunInfo(s, stdout, stderr); + ASSERT_STR_CONTAINS(stdout, "kudu.table.history_max_age_sec | 3600"); + } + + // Gets the specified extra-config, the configuration exists. + { + string stdout, stderr; + Status s = RunKuduTool({ + "table", + "get_extra_configs", + master_address, + kTableId, + "-config_names=kudu.table.history_max_age_sec" + }, &stdout, &stderr); + ASSERT_TRUE(s.ok()) << ToolRunInfo(s, stdout, stderr); + ASSERT_STR_CONTAINS(stdout, "kudu.table.history_max_age_sec | 3600"); + } + + // Gets the duplicate extra-configs, the configuration exists. + { + string stdout, stderr; + Status s = RunKuduTool({ + "table", + "get_extra_configs", + master_address, + kTableId, + "-config_names=kudu.table.history_max_age_sec,kudu.table.history_max_age_sec" + }, &stdout, &stderr); + ASSERT_TRUE(s.ok()) << ToolRunInfo(s, stdout, stderr); + ASSERT_EQ(stdout, " Configuration | Value\n" + "--------------------------------+-------\n" + " kudu.table.history_max_age_sec | 3600\n"); + } + + // Gets the specified extra-config, the configuration doesn't exists. + { + string stdout, stderr; + Status s = RunKuduTool({ + "table", + "get_extra_configs", + master_address, + kTableId, + "-config_names=foobar" + }, &stdout, &stderr); + ASSERT_TRUE(s.ok()) << ToolRunInfo(s, stdout, stderr); + ASSERT_EQ(stdout, " Configuration | Value\n" + "---------------+-------\n"); + } +} + } // namespace tools } // namespace kudu diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc index be454f6..5ac2c4a 100644 --- a/src/kudu/tools/kudu-tool-test.cc +++ b/src/kudu/tools/kudu-tool-test.cc @@ -1107,6 +1107,8 @@ TEST_F(ToolTest, TestModeHelp) { "list.*List tables", "scan.*Scan rows from a table", "copy.*Copy table data to another table", + "set_extra_config.*Change a extra configuration value on a table", + "get_extra_configs.*Get the extra configuration properties for a table" }; NO_FATALS(RunTestHelp("table", kTableModeRegexes)); } diff --git a/src/kudu/tools/tool_action_table.cc b/src/kudu/tools/tool_action_table.cc index 8502dc8..6ca7373 100644 --- a/src/kudu/tools/tool_action_table.cc +++ b/src/kudu/tools/tool_action_table.cc @@ -18,9 +18,12 @@ #include <algorithm> #include <cstdint> #include <iostream> +#include <map> #include <memory> +#include <set> #include <string> #include <unordered_map> +#include <utility> #include <vector> #include <boost/optional/optional.hpp> @@ -62,6 +65,7 @@ using kudu::client::internal::ReplicaController; using std::cerr; using std::cout; using std::endl; +using std::set; using std::string; using std::unique_ptr; using std::vector; @@ -81,6 +85,9 @@ DEFINE_bool(list_tablets, false, DEFINE_bool(modify_external_catalogs, true, "Whether to modify external catalogs, such as the Hive Metastore, " "when renaming or dropping a table."); +DEFINE_string(config_names, "", + "Comma-separated list of configurations to display. " + "An empty value displays all configs."); DECLARE_bool(show_values); DECLARE_string(tables); @@ -138,6 +145,8 @@ const char* const kNewTableNameArg = "new_table_name"; const char* const kColumnNameArg = "column_name"; const char* const kNewColumnNameArg = "new_column_name"; const char* const kKeyArg = "primary_key"; +const char* const kConfigNameArg = "config_name"; +const char* const kConfigValueArg = "config_value"; Status DeleteTable(const RunnerContext& context) { const string& table_name = FindOrDie(context.required_args, kTableNameArg); @@ -418,6 +427,43 @@ Status CopyTable(const RunnerContext& context) { return scanner.StartCopy(); } +Status SetExtraConfig(const RunnerContext& context) { + const string& table_name = FindOrDie(context.required_args, kTableNameArg); + const string& config_name = FindOrDie(context.required_args, kConfigNameArg); + const string& config_value = FindOrDie(context.required_args, kConfigValueArg); + + client::sp::shared_ptr<KuduClient> client; + RETURN_NOT_OK(CreateKuduClient(context, &client)); + unique_ptr<KuduTableAlterer> alterer(client->NewTableAlterer(table_name)); + alterer->AlterExtraConfig({ { config_name, config_value} }); + return alterer->Alter(); +} + +Status GetExtraConfigs(const RunnerContext& context) { + const string& table_name = FindOrDie(context.required_args, kTableNameArg); + set<string> config_names = strings::Split(FLAGS_config_names, ",", strings::SkipEmpty()); + + client::sp::shared_ptr<KuduClient> client; + RETURN_NOT_OK(CreateKuduClient(context, &client)); + client::sp::shared_ptr<KuduTable> table; + RETURN_NOT_OK(client->OpenTable(table_name, &table)); + + DataTable data_table({ "Configuration", "Value" }); + if (config_names.empty()) { + for (const auto& extra_config : table->extra_configs()) { + data_table.AddRow({ extra_config.first, extra_config.second }); + } + } else { + for (const auto& config_name : config_names) { + const string* config_value = FindOrNull(table->extra_configs(), config_name); + if (config_value) { + data_table.AddRow({ config_name, *config_value }); + } + } + } + return data_table.PrintTo(cout); +} + } // anonymous namespace unique_ptr<Mode> BuildTableMode() { @@ -513,6 +559,24 @@ unique_ptr<Mode> BuildTableMode() { .AddOptionalParameter("write_type") .Build(); + unique_ptr<Action> set_extra_config = + ActionBuilder("set_extra_config", &SetExtraConfig) + .Description("Change a extra configuration value on a table") + .AddRequiredParameter({ kMasterAddressesArg, kMasterAddressesArgDesc }) + .AddRequiredParameter({ kTableNameArg, "Name of the table to alter" }) + .AddRequiredParameter({ kConfigNameArg, "Name of the configuration" }) + .AddRequiredParameter({ kConfigValueArg, "New value for the configuration" }) + .Build(); + + unique_ptr<Action> get_extra_configs = + ActionBuilder("get_extra_configs", &GetExtraConfigs) + .Description("Get the extra configuration properties for a table") + .AddRequiredParameter({ kMasterAddressesArg, kMasterAddressesArgDesc }) + .AddRequiredParameter({ kTableNameArg, + "Name of the table for which to get extra configurations" }) + .AddOptionalParameter("config_names") + .Build(); + return ModeBuilder("table") .Description("Operate on Kudu tables") .AddAction(std::move(delete_table)) @@ -523,6 +587,8 @@ unique_ptr<Mode> BuildTableMode() { .AddAction(std::move(rename_table)) .AddAction(std::move(scan_table)) .AddAction(std::move(copy_table)) + .AddAction(std::move(set_extra_config)) + .AddAction(std::move(get_extra_configs)) .Build(); }
