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/06/27 17:33:08 UTC
kudu git commit: [rebalance-test] fix running the test on Ubuntu 18.04
Repository: kudu
Updated Branches:
refs/heads/master e0a4c6cfa -> 9c89c2a9a
[rebalance-test] fix running the test on Ubuntu 18.04
Updated custom equality operators for TableBalanceInfo and
ClusterBalanceInfo. With this update, the operator compares just the
contents of corresponding sub-fields of the ServersByCountMap type
(which is map<int32_t, string>), disregarding the order of elements for
the same key. That's the exact behavior desired: the ordering of
elements in the ServersByCountMap is not important in all scenarios
of the rebalance-test.
The motivation for this change is the fact that the test fails on
Ubuntu 18.04 without this patch. Implicitly, the reference results
relied on the order of elements in hash dictionary container used in
the implementation of the Rebalancer::KsckResultsToClusterBalanceInfo()
method. It seems the implementation of std::unordered_map in libstdc++
shipped with Ubuntu 18.04 has changed compared with older Linux distro
versions.
Change-Id: Ie4dc5d22bab86f6ab61f18f05e45a063bbf38eba
Reviewed-on: http://gerrit.cloudera.org:8080/10812
Tested-by: Alexey Serbin <as...@cloudera.com>
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/9c89c2a9
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/9c89c2a9
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/9c89c2a9
Branch: refs/heads/master
Commit: 9c89c2a9aad6956c39f04454467789fa6d8288ef
Parents: e0a4c6c
Author: Alexey Serbin <as...@cloudera.com>
Authored: Mon Jun 25 11:11:20 2018 -0700
Committer: Alexey Serbin <as...@cloudera.com>
Committed: Wed Jun 27 17:32:03 2018 +0000
----------------------------------------------------------------------
src/kudu/tools/rebalance-test.cc | 71 +++++++++++++++++++++++++++++++----
1 file changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/9c89c2a9/src/kudu/tools/rebalance-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/rebalance-test.cc b/src/kudu/tools/rebalance-test.cc
index 271dab1..3f3f6f3 100644
--- a/src/kudu/tools/rebalance-test.cc
+++ b/src/kudu/tools/rebalance-test.cc
@@ -20,9 +20,8 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
-#include <limits>
+#include <iterator>
#include <map>
-#include <set>
#include <string>
#include <utility>
#include <vector>
@@ -35,11 +34,11 @@
#include "kudu/tools/rebalance_algo.h"
#include "kudu/util/test_macros.h"
-using std::numeric_limits;
+using std::inserter;
using std::ostream;
-using std::set;
using std::sort;
using std::string;
+using std::transform;
using std::vector;
using strings::Substitute;
@@ -121,16 +120,74 @@ KsckResults GenerateKsckResults(KsckResultsInput input) {
return results;
}
+// The order of the key-value pairs whose keys compare equivalent is the order
+// of insertion and does not change. Since the insertion order is not
+// important for the comparison with the reference results, this comparison
+// operator normalizes both the 'lhs' and 'rhs', so the comparison operator
+// compares only the contents of the 'servers_by_replica_count', not the order
+// of the elements.
+bool HasSameContents(const ServersByCountMap& lhs,
+ const ServersByCountMap& rhs) {
+ if (lhs.size() != rhs.size()) {
+ return false;
+ }
+
+ auto it_lhs = lhs.begin();
+ auto it_rhs = rhs.begin();
+ for (; it_lhs != lhs.end() && it_rhs != rhs.end(); ) {
+ auto key_lhs = it_lhs->first;
+ auto key_rhs = it_rhs->first;
+ if (key_lhs != key_rhs) {
+ return false;
+ }
+
+ auto eq_range_lhs = lhs.equal_range(key_lhs);
+ auto eq_range_rhs = rhs.equal_range(key_rhs);
+
+ vector<string> lhs_values;
+ {
+ transform(eq_range_lhs.first, eq_range_lhs.second,
+ inserter(lhs_values, lhs_values.begin()),
+ [](const ServersByCountMap::value_type& elem) {
+ return elem.second;
+ });
+ sort(lhs_values.begin(), lhs_values.end());
+ }
+
+ vector<string> rhs_values;
+ {
+ transform(eq_range_rhs.first, eq_range_rhs.second,
+ inserter(rhs_values, rhs_values.begin()),
+ [](const ServersByCountMap::value_type& elem) {
+ return elem.second;
+ });
+ sort(rhs_values.begin(), rhs_values.end());
+ }
+
+ if (lhs_values != rhs_values) {
+ return false;
+ }
+
+ // Advance the iterators to continue with next key.
+ it_lhs = eq_range_lhs.second;
+ it_rhs = eq_range_rhs.second;
+ }
+
+ return true;
+}
+
} // anonymous namespace
bool operator==(const TableBalanceInfo& lhs, const TableBalanceInfo& rhs) {
- return lhs.servers_by_replica_count == rhs.servers_by_replica_count;
+ return HasSameContents(lhs.servers_by_replica_count,
+ rhs.servers_by_replica_count);
}
bool operator==(const ClusterBalanceInfo& lhs, const ClusterBalanceInfo& rhs) {
return
lhs.table_info_by_skew == rhs.table_info_by_skew &&
- lhs.servers_by_total_replica_count == rhs.servers_by_total_replica_count;
+ HasSameContents(lhs.servers_by_total_replica_count,
+ rhs.servers_by_total_replica_count);
}
ostream& operator<<(ostream& s, const ClusterBalanceInfo& info) {
@@ -159,7 +216,7 @@ TEST(KuduKsckRebalanceTest, KsckResultsToClusterBalanceInfo) {
{},
{}
},
- // Simple one tserver, one table, one tablet, RF=1.
+ // One tserver, one table, one tablet, RF=1.
{
{
{ { "ts_0" }, },