/Users/deen/code/yugabyte-db/src/yb/integration-tests/load_balancer_test_util.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/integration-tests/load_balancer_test_util.h" |
15 | | |
16 | | #include <glog/logging.h> |
17 | | |
18 | | namespace yb { |
19 | | namespace integration_tests { |
20 | | |
21 | 20 | bool AreLoadsBalanced(const std::vector<uint32_t>& tserver_loads) { |
22 | 20 | if (tserver_loads.empty()) { |
23 | 0 | return true; |
24 | 0 | } |
25 | 20 | auto min_load = tserver_loads[0]; |
26 | 20 | auto max_load = min_load; |
27 | 46 | for (size_t i = 1; i < tserver_loads.size(); ++i26 ) { |
28 | 26 | if (tserver_loads[i] < min_load) { |
29 | 6 | min_load = tserver_loads[i]; |
30 | 20 | } else if (tserver_loads[i] > max_load) { |
31 | 5 | max_load = tserver_loads[i]; |
32 | 5 | } |
33 | 26 | } |
34 | 20 | return (max_load - min_load) < 2; |
35 | 20 | } |
36 | | |
37 | | bool AreLoadsAsExpected(const std::unordered_map<TabletServerId, int>& tserver_loads, |
38 | 9 | const std::unordered_set<TabletServerId>& zero_load_tservers) { |
39 | 9 | std::vector<uint32_t> non_zero_loads; |
40 | 9 | bool is_zero_load_non_zero = false; |
41 | 27 | for (const auto& load : tserver_loads) { |
42 | 27 | LOG(INFO) << "Load of ts: " << load.first << ", load: " << load.second; |
43 | 27 | if (zero_load_tservers.count(load.first)) { |
44 | 12 | is_zero_load_non_zero = load.second > 0; |
45 | 15 | } else { |
46 | 15 | non_zero_loads.push_back(load.second); |
47 | 15 | } |
48 | 27 | } |
49 | | |
50 | 9 | return !is_zero_load_non_zero && AreLoadsBalanced(non_zero_loads); |
51 | 9 | } |
52 | | |
53 | | } // namespace integration_tests |
54 | | } // namespace yb |