kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ale...@apache.org
Subject kudu git commit: [tools] small fix on RebalancingAlgo::GetNextMoves()
Date Tue, 26 Jun 2018 16:20:49 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 985c6698a -> b174d6e53


[tools] small fix on RebalancingAlgo::GetNextMoves()

Fix on short-circuiting in case of empty input for
RebalancingAlgo::GetNextMoves().  Added consistency check for the
'cluster_info' input parameter and corresponding unit test.

Change-Id: Iad7a7bc5bee939ce92d18845d6e43bcadccac5a2
Reviewed-on: http://gerrit.cloudera.org:8080/10819
Reviewed-by: Mike Percy <mpercy@apache.org>
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/b174d6e5
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/b174d6e5
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/b174d6e5

Branch: refs/heads/master
Commit: b174d6e538cb1a1df47f662640aadfb0d1236c1c
Parents: 985c669
Author: Alexey Serbin <aserbin@cloudera.com>
Authored: Mon Jun 25 17:57:42 2018 -0700
Committer: Alexey Serbin <aserbin@cloudera.com>
Committed: Tue Jun 26 14:26:49 2018 +0000

----------------------------------------------------------------------
 src/kudu/tools/rebalance_algo-test.cc | 26 ++++++++++++++++++++++++--
 src/kudu/tools/rebalance_algo.cc      | 14 ++++++++++++--
 2 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/b174d6e5/src/kudu/tools/rebalance_algo-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/rebalance_algo-test.cc b/src/kudu/tools/rebalance_algo-test.cc
index 42b1665..cd6adbd 100644
--- a/src/kudu/tools/rebalance_algo-test.cc
+++ b/src/kudu/tools/rebalance_algo-test.cc
@@ -18,6 +18,7 @@
 #include "kudu/tools/rebalance_algo.h"
 
 #include <cstddef>
+#include <cstdint>
 #include <iostream>
 #include <iterator>
 #include <map>
@@ -191,16 +192,37 @@ string TestClusterConfigToDebugString(const TestClusterConfig& cfg)
{
 // Test the behavior of the algorithm when no input information is given.
 TEST(RebalanceAlgoUnitTest, EmptyClusterBalanceInfoGetNextMoves) {
   vector<TableReplicaMove> moves;
-  ClusterBalanceInfo info;
+  const ClusterBalanceInfo info;
   ASSERT_OK(TwoDimensionalGreedyAlgo().GetNextMoves(info, 0, &moves));
   EXPECT_TRUE(moves.empty());
 }
 
+// Test the behavior of the algorithm when no tablet skew information
+// is provided in the ClusterBalanceInfo structure.
+TEST(RebalanceAlgoUnitTest, NoTableSkewInClusterBalanceInfoGetNextMoves) {
+  {
+    vector<TableReplicaMove> moves;
+    const ClusterBalanceInfo info = { {}, { { 0, "ts_0" } } };
+    ASSERT_OK(TwoDimensionalGreedyAlgo().GetNextMoves(info, 0, &moves));
+    EXPECT_TRUE(moves.empty());
+  }
+
+  {
+    vector<TableReplicaMove> moves;
+    const ClusterBalanceInfo info = { {}, { { 1, "ts_0" }, } };
+    const auto s = TwoDimensionalGreedyAlgo().GetNextMoves(info, 0, &moves);
+    ASSERT_TRUE(s.IsInvalidArgument()) << s.ToString();
+    ASSERT_STR_MATCHES(s.ToString(),
+        "non-zero table count .* on tablet server .* while no table "
+        "skew information in ClusterBalanceInfo");
+  }
+}
+
 // Test the behavior of the internal (non-public) algorithm's method
 // GetNextMove() when no input information is given.
 TEST(RebalanceAlgoUnitTest, EmptyClusterBalanceInfoGetNextMove) {
   boost::optional<TableReplicaMove> move;
-  ClusterBalanceInfo info;
+  const ClusterBalanceInfo info;
   const auto s = TwoDimensionalGreedyAlgo().GetNextMove(info, &move);
   ASSERT_TRUE(s.IsInvalidArgument()) << s.ToString();
   EXPECT_EQ(boost::none, move);

http://git-wip-us.apache.org/repos/asf/kudu/blob/b174d6e5/src/kudu/tools/rebalance_algo.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/rebalance_algo.cc b/src/kudu/tools/rebalance_algo.cc
index 7f3cba6..ca05eb8 100644
--- a/src/kudu/tools/rebalance_algo.cc
+++ b/src/kudu/tools/rebalance_algo.cc
@@ -118,8 +118,18 @@ Status RebalancingAlgo::GetNextMoves(const ClusterBalanceInfo& cluster_info,
     max_moves_num = std::numeric_limits<decltype(max_moves_num)>::max();
   }
   moves->clear();
-  if (cluster_info.table_info_by_skew.empty() &&
-      cluster_info.servers_by_total_replica_count.empty()) {
+
+  if (cluster_info.table_info_by_skew.empty()) {
+    // Check for the consistency of the 'cluster_info' parameter: if no
+    // information is given on the table skew, table count for all the tablet
+    // servers should be 0.
+    for (const auto& elem : cluster_info.servers_by_total_replica_count) {
+      if (elem.first != 0) {
+        return Status::InvalidArgument(Substitute(
+            "non-zero table count ($0) on tablet server ($1) while no table "
+            "skew information in ClusterBalanceInfo", elem.first, elem.second));
+      }
+    }
     // Nothing to balance: cluster is empty. Leave 'moves' empty and return.
     return Status::OK();
   }


Mime
View raw message