Repository: kudu
Updated Branches:
  refs/heads/master 6c68e64d8 -> b2c642890


[tools] --report_only option for 'kudu cluster rebalance'

Added --report_only option for the 'kudu cluster rebalance' CLI tool
along with corresponding test.

Change-Id: Id8a81448a31ba76bb651b13e052f2c508cd0acd6
Reviewed-on: http://gerrit.cloudera.org:8080/11097
Reviewed-by: Will Berkeley <wdberke...@gmail.com>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/85a1808c
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/85a1808c
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/85a1808c

Branch: refs/heads/master
Commit: 85a1808c530f4cf857b4fe7fc5be2f7c00c6ed82
Parents: 6c68e64
Author: Alexey Serbin <aser...@cloudera.com>
Authored: Tue Jul 31 16:55:13 2018 -0700
Committer: Alexey Serbin <aser...@cloudera.com>
Committed: Wed Aug 1 19:33:53 2018 +0000

----------------------------------------------------------------------
 src/kudu/tools/kudu-admin-test.cc     | 38 ++++++++++++++++++++++++++++++
 src/kudu/tools/tool_action_cluster.cc |  9 +++++++
 2 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/85a1808c/src/kudu/tools/kudu-admin-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-admin-test.cc 
b/src/kudu/tools/kudu-admin-test.cc
index 0408e35..04c5af9 100644
--- a/src/kudu/tools/kudu-admin-test.cc
+++ b/src/kudu/tools/kudu-admin-test.cc
@@ -1339,6 +1339,44 @@ static string ToolRunInfo(const Status& s, const string& 
out, const string& err)
   return str.str();
 }
 
+TEST_F(AdminCliTest, RebalancerReportOnly) {
+  static const char kReferenceOutput[] =
+    R"***(Per-server replica distribution summary:
+       Statistic       |  Value
+-----------------------+----------
+ Minimum Replica Count | 0
+ Maximum Replica Count | 1
+ Average Replica Count | 0.600000
+
+Per-table replica distribution summary:
+ Replica Skew |  Value
+--------------+----------
+ Minimum      | 1
+ Maximum      | 1
+ Average      | 1.000000)***";
+
+  FLAGS_num_tablet_servers = 5;
+  NO_FATALS(BuildAndStart());
+
+  string out;
+  string err;
+  Status s = RunKuduTool({
+    "cluster",
+    "rebalance",
+    cluster_->master()->bound_rpc_addr().ToString(),
+    "--report_only",
+  }, &out, &err);
+  ASSERT_TRUE(s.ok()) << ToolRunInfo(s, out, err);
+  // The rebalancer should report on tablet replica distribution. The output
+  // should match the reference report: the distribution of the replicas
+  // is 100% repeatable given the number of tables created by the test,
+  // the replication factor and the number of tablet servers.
+  ASSERT_STR_CONTAINS(out, kReferenceOutput);
+  // The actual rebalancing should not run.
+  ASSERT_STR_NOT_CONTAINS(out, "rebalancing is complete:")
+      << ToolRunInfo(s, out, err);
+}
+
 // Make sure the rebalancer doesn't start if a tablet server is down.
 class RebalanceStartCriteriaTest :
     public AdminCliTest,

http://git-wip-us.apache.org/repos/asf/kudu/blob/85a1808c/src/kudu/tools/tool_action_cluster.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_cluster.cc 
b/src/kudu/tools/tool_action_cluster.cc
index e420518..8fccd84 100644
--- a/src/kudu/tools/tool_action_cluster.cc
+++ b/src/kudu/tools/tool_action_cluster.cc
@@ -99,6 +99,10 @@ DEFINE_bool(output_replica_distribution_details, false,
             "Whether to output details on per-table and per-server "
             "replica distribution");
 
+DEFINE_bool(report_only, false,
+            "Whether to report on table- and cluster-wide replica distribution 
"
+            "skew and exit without doing any actual rebalancing");
+
 static bool ValidateMoveSingleReplicas(const char* flag_name,
                                        const string& flag_value) {
   const vector<string> allowed_values = { "auto", "enabled", "disabled" };
@@ -263,6 +267,10 @@ Status RunRebalance(const RunnerContext& context) {
   // Print info on pre-rebalance distribution of replicas.
   RETURN_NOT_OK(rebalancer.PrintStats(cout));
 
+  if (FLAGS_report_only) {
+    return Status::OK();
+  }
+
   Rebalancer::RunStatus result_status;
   size_t moves_count;
   RETURN_NOT_OK(rebalancer.Run(&result_status, &moves_count));
@@ -345,6 +353,7 @@ unique_ptr<Mode> BuildClusterMode() {
         .AddOptionalParameter("max_staleness_interval_sec")
         .AddOptionalParameter("move_single_replicas")
         .AddOptionalParameter("output_replica_distribution_details")
+        .AddOptionalParameter("report_only")
         .AddOptionalParameter("tables")
         .Build();
     builder.AddAction(std::move(rebalance));

Reply via email to