You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2018/10/29 23:09:33 UTC

[2/4] kudu git commit: [rebalancer] location-aware rebalancer (part 2/n)

[rebalancer] location-aware rebalancer (part 2/n)

Small refactoring on tools::Rebalancer: renamed
Rebalancer::ResetKsck() into Rebalancer::RefreshKsckResults()
and made the actual ksck utility run as a part of the renamed
method.

Change-Id: Ia1bdd4ee13d0522e49467b8b6e4e3a76ec560b26
Reviewed-on: http://gerrit.cloudera.org:8080/11743
Tested-by: Alexey Serbin <as...@cloudera.com>
Reviewed-by: Will Berkeley <wd...@gmail.com>


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

Branch: refs/heads/master
Commit: fd507235b531419f6bc2447263278eee315177ab
Parents: 81d0109
Author: Alexey Serbin <as...@cloudera.com>
Authored: Fri Oct 19 15:52:33 2018 -0700
Committer: Alexey Serbin <as...@cloudera.com>
Committed: Mon Oct 29 23:05:31 2018 +0000

----------------------------------------------------------------------
 src/kudu/tools/rebalancer.cc | 23 +++++++++++------------
 src/kudu/tools/rebalancer.h  | 11 ++---------
 2 files changed, 13 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/fd507235/src/kudu/tools/rebalancer.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/rebalancer.cc b/src/kudu/tools/rebalancer.cc
index 9dae39c..09af4bd 100644
--- a/src/kudu/tools/rebalancer.cc
+++ b/src/kudu/tools/rebalancer.cc
@@ -100,8 +100,7 @@ Rebalancer::Rebalancer(const Config& config)
 
 Status Rebalancer::PrintStats(std::ostream& out) {
   // First, report on the current balance state of the cluster.
-  RETURN_NOT_OK(ResetKsck());
-  ignore_result(ksck_->Run());
+  RETURN_NOT_OK(RefreshKsckResults());
   const KsckResults& results = ksck_->results();
 
   ClusterBalanceInfo cbi;
@@ -314,7 +313,7 @@ Status Rebalancer::Run(RunStatus* result_status, size_t* moves_count) {
 // moves recommended at prior steps are still in progress.
 Status Rebalancer::KsckResultsToClusterBalanceInfo(
     const KsckResults& ksck_info,
-    const MovesInProgress& pending_moves,
+    const MovesInProgress& moves_in_progress,
     ClusterBalanceInfo* cbi) const {
   DCHECK(cbi);
 
@@ -360,7 +359,7 @@ Status Rebalancer::KsckResultsToClusterBalanceInfo(
     // Check if it's one of the tablets which are currently being rebalanced.
     // If so, interpret the move as successfully completed, updating the
     // replica counts correspondingly.
-    const auto it_pending_moves = pending_moves.find(tablet.id);
+    const auto it_pending_moves = moves_in_progress.find(tablet.id);
 
     for (const auto& ri : tablet.replicas) {
       // Increment total count of replicas at the tablet server.
@@ -375,7 +374,7 @@ Status Rebalancer::KsckResultsToClusterBalanceInfo(
         continue;
       }
       bool do_count_replica = true;
-      if (it_pending_moves != pending_moves.end() &&
+      if (it_pending_moves != moves_in_progress.end() &&
           tablet.result == KsckCheckResult::RECOVERING) {
         const auto& move_info = it_pending_moves->second;
         bool is_target_replica_present = false;
@@ -453,10 +452,9 @@ Status Rebalancer::KsckResultsToClusterBalanceInfo(
 // Run one step of the rebalancer. Due to the inherent restrictions of the
 // rebalancing engine, no more than one replica per tablet is moved during
 // one step of the rebalancing.
-Status Rebalancer::GetNextMoves(const MovesInProgress& pending_moves,
+Status Rebalancer::GetNextMoves(const MovesInProgress& moves_in_progress,
                                 vector<ReplicaMove>* replica_moves) {
-  RETURN_NOT_OK(ResetKsck());
-  ignore_result(ksck_->Run());
+  RETURN_NOT_OK(RefreshKsckResults());
   const auto& ksck_info = ksck_->results();
 
   // For simplicity, allow to run the rebalancing only when all tablet servers
@@ -480,8 +478,8 @@ Status Rebalancer::GetNextMoves(const MovesInProgress& pending_moves,
   vector<TableReplicaMove> moves;
   {
     ClusterBalanceInfo cbi;
-    RETURN_NOT_OK(KsckResultsToClusterBalanceInfo(ksck_info, pending_moves, &cbi));
-    RETURN_NOT_OK(algo_.GetNextMoves(std::move(cbi), max_moves, &moves));
+    RETURN_NOT_OK(KsckResultsToClusterBalanceInfo(ksck_info, moves_in_progress, &cbi));
+    RETURN_NOT_OK(algo_.GetNextMoves(cbi, max_moves, &moves));
   }
   if (moves.empty()) {
     // No suitable moves were found: the cluster described by 'cbi' is balanced,
@@ -489,7 +487,7 @@ Status Rebalancer::GetNextMoves(const MovesInProgress& pending_moves,
     return Status::OK();
   }
   unordered_set<string> tablets_in_move;
-  std::transform(pending_moves.begin(), pending_moves.end(),
+  std::transform(moves_in_progress.begin(), moves_in_progress.end(),
                  inserter(tablets_in_move, tablets_in_move.begin()),
                  [](const MovesInProgress::value_type& elem) {
                    return elem.first;
@@ -618,13 +616,14 @@ Status Rebalancer::FindReplicas(const TableReplicaMove& move,
   return Status::OK();
 }
 
-Status Rebalancer::ResetKsck() {
+Status Rebalancer::RefreshKsckResults() {
   shared_ptr<KsckCluster> cluster;
   RETURN_NOT_OK_PREPEND(
       RemoteKsckCluster::Build(config_.master_addresses, &cluster),
       "unable to build KsckCluster");
   ksck_.reset(new Ksck(cluster));
   ksck_->set_table_filters(config_.table_filters);
+  ignore_result(ksck_->Run());
   return Status::OK();
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/fd507235/src/kudu/tools/rebalancer.h
----------------------------------------------------------------------
diff --git a/src/kudu/tools/rebalancer.h b/src/kudu/tools/rebalancer.h
index a6e4caf..3c038aa 100644
--- a/src/kudu/tools/rebalancer.h
+++ b/src/kudu/tools/rebalancer.h
@@ -36,12 +36,6 @@
 #include "kudu/util/status.h"
 
 namespace kudu {
-namespace tools {
-struct TabletsPlacementInfo;
-}  // namespace tools
-}  // namespace kudu
-
-namespace kudu {
 
 namespace client {
 class KuduClient;
@@ -50,7 +44,6 @@ class KuduClient;
 namespace tools {
 
 class Ksck;
-struct KsckResults;
 
 // Sub-set of fields from KsckResult which are relevant to the rebalancing.
 struct ClusterRawInfo {
@@ -281,8 +274,8 @@ class Rebalancer {
                       const KsckResults& ksck_info,
                       std::vector<std::string>* tablet_ids) const;
 
-  // Reset ksck-related fields, preparing for a fresh ksck run.
-  Status ResetKsck();
+  // Reset ksck-related fields and run ksck against the cluster.
+  Status RefreshKsckResults();
 
   // Filter out move operations at the tablets which already have operations
   // in progress. The 'replica_moves' cannot be null.