summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/distributor_bucket_space_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'storage/src/tests/distributor/distributor_bucket_space_test.cpp')
-rw-r--r--storage/src/tests/distributor/distributor_bucket_space_test.cpp152
1 files changed, 74 insertions, 78 deletions
diff --git a/storage/src/tests/distributor/distributor_bucket_space_test.cpp b/storage/src/tests/distributor/distributor_bucket_space_test.cpp
index e206308618f..8db7955b8a7 100644
--- a/storage/src/tests/distributor/distributor_bucket_space_test.cpp
+++ b/storage/src/tests/distributor/distributor_bucket_space_test.cpp
@@ -16,6 +16,8 @@ namespace {
std::shared_ptr<ClusterState> stable_state(std::make_shared<ClusterState>("distributor:4 storage:4 bits:8"));
std::shared_ptr<ClusterState> node_1_down_state(std::make_shared<ClusterState>("distributor:4 .1.s:d storage:4 .1.s:d bits:8"));
+std::shared_ptr<ClusterState> node_1_retired_state(std::make_shared<ClusterState>("distributor:4 .1.s:d storage:4 .1.s:r bits:8"));
+std::shared_ptr<ClusterState> node_1_maintenance_state(std::make_shared<ClusterState>("distributor:4 .1.s:d storage:4 .1.s:m bits:8"));
std::shared_ptr<Distribution> distribution_r1(std::make_shared<Distribution>(Distribution::getDefaultDistributionConfig(1, 4)));
std::shared_ptr<Distribution> distribution_r2(std::make_shared<Distribution>(Distribution::getDefaultDistributionConfig(2, 4)));
@@ -33,70 +35,59 @@ struct DistributorBucketSpaceTest : public ::testing::Test
{
}
~DistributorBucketSpaceTest() = default;
+
+ // make normal buckets
+ std::vector<BucketId> make_normal_buckets();
+
+ // make deep split buckets. Ideal service layer nodes for a bucket changes for each split level when bucket used bits > 33.
+ std::vector<BucketId> make_deep_split_buckets(std::function<bool(BucketId)> owned);
+
// Count normal buckets using this distributor
- uint32_t count_distributor_buckets();
+ uint32_t count_distributor_buckets(const std::vector<BucketId>& buckets);
// Count normal buckets using service layer node 0.
- uint32_t count_storage_buckets();
- // Count deep split buckets using this distributor
- uint32_t count_deep_split_distributor_buckets();
- // Count deep split buckets using service layer node 0. Ideal nodes for a bucket changes for each split level when bucket used bits > 33.
- uint32_t count_deep_split_storage_buckets();
+ CountVector count_service_layer_buckets(const std::vector<BucketId>& buckets);
// Count normal buckets using this distributor and service layer node 0
CountVector count_buckets();
// Count deep split buckets using this distributor and service layer node 0.
CountVector count_deep_split_buckets();
};
-uint32_t
-DistributorBucketSpaceTest::count_distributor_buckets()
+std::vector<BucketId>
+DistributorBucketSpaceTest::make_normal_buckets()
{
- uint32_t owned_buckets = 0;
+ std::vector<BucketId> buckets;
uint16_t distribution_bits = bucket_space.getClusterState().getDistributionBitCount();
for (uint32_t i = 0; i < (1u << distribution_bits); ++i) {
- BucketId bucket(distribution_bits, i);
- bool owned = bucket_space.check_ownership_in_pending_and_current_state(bucket).isOwned();
- if (owned) {
- ++owned_buckets;
- }
+ buckets.emplace_back(distribution_bits, i);
}
- return owned_buckets;
+ return buckets;
}
-uint32_t
-DistributorBucketSpaceTest::count_storage_buckets()
+std::vector<BucketId>
+DistributorBucketSpaceTest::make_deep_split_buckets(std::function<bool(BucketId)> owned)
{
- uint32_t owned_buckets = 0;
- uint16_t distribution_bits = bucket_space.getClusterState().getDistributionBitCount();
- for (uint32_t i = 0; i < (1u << distribution_bits); ++i) {
- BucketId bucket(distribution_bits, i);
- auto ideal_nodes = bucket_space.get_ideal_nodes(bucket);
- auto check_ideal_nodes = bucket_space.get_ideal_nodes_fallback(bucket);
- EXPECT_EQ(check_ideal_nodes, ideal_nodes);
- for (auto node : ideal_nodes) {
- if (node == 0u) {
- ++owned_buckets;
- }
- }
- }
- return owned_buckets;
-}
-
-uint32_t
-DistributorBucketSpaceTest::count_deep_split_distributor_buckets()
-{
- uint32_t owned_buckets = 0;
+ std::vector<BucketId> buckets;
uint16_t distribution_bits = bucket_space.getClusterState().getDistributionBitCount();
uint32_t bias = 0;
uint32_t bias_max = std::min(1u << distribution_bits, 1000u);
for (; bias < bias_max; ++bias) {
BucketId bucket(distribution_bits, bias);
- if (bucket_space.check_ownership_in_pending_and_current_state(bucket).isOwned()) {
+ if (owned(bucket)) {
break;
}
}
assert(bias < bias_max);
for (uint32_t i = 0; i < 100; ++i) {
- BucketId bucket(42u, i * (1ul << 32) + bias);
+ buckets.emplace_back(42u, i * (1ul << 32) + bias);
+ }
+ return buckets;
+}
+
+uint32_t
+DistributorBucketSpaceTest::count_distributor_buckets(const std::vector<BucketId>& buckets)
+{
+ uint32_t owned_buckets = 0;
+ for (auto& bucket : buckets) {
bool owned = bucket_space.check_ownership_in_pending_and_current_state(bucket).isOwned();
if (owned) {
++owned_buckets;
@@ -105,47 +96,45 @@ DistributorBucketSpaceTest::count_deep_split_distributor_buckets()
return owned_buckets;
}
-uint32_t
-DistributorBucketSpaceTest::count_deep_split_storage_buckets()
+DistributorBucketSpaceTest::CountVector
+DistributorBucketSpaceTest::count_service_layer_buckets(const std::vector<BucketId>& buckets)
{
- uint32_t owned_buckets = 0;
- uint16_t distribution_bits = bucket_space.getClusterState().getDistributionBitCount();
- uint32_t bias = 0;
- uint32_t bias_max = std::min(1u << distribution_bits, 1000u);
- for (; bias < bias_max; ++bias) {
- BucketId bucket(distribution_bits, bias);
- auto ideal_nodes = bucket_space.get_ideal_nodes(bucket);
- bool found = false;
- for (auto node : ideal_nodes) {
- if (node == 0u) {
- found = true;
+ CountVector result(3);
+ std::vector<uint16_t> ideal_nodes;
+ for (auto& bucket : buckets) {
+ auto &ideal_nodes_bundle = bucket_space.get_ideal_service_layer_nodes_bundle(bucket);
+ for (uint32_t i = 0; i < 3; ++i) {
+ switch (i) {
+ case 0:
+ ideal_nodes = ideal_nodes_bundle.get_available_nodes();
+ break;
+ case 1:
+ ideal_nodes = ideal_nodes_bundle.get_available_nonretired_nodes();
+ break;
+ case 2:
+ ideal_nodes = ideal_nodes_bundle.get_available_nonretired_or_maintenance_nodes();
+ break;
+ default:
+ ;
}
- }
- if (found) {
- break;
- }
- }
- assert(bias < bias_max);
- for (uint32_t i = 0; i < 100; ++i) {
- BucketId bucket(42u, i * (1ul << 32) + bias);
- auto ideal_nodes = bucket_space.get_ideal_nodes(bucket);
- auto check_ideal_nodes = bucket_space.get_ideal_nodes_fallback(bucket);
- EXPECT_EQ(check_ideal_nodes, ideal_nodes);
- for (auto node : ideal_nodes) {
- if (node == 0u) {
- ++owned_buckets;
+ for (auto node : ideal_nodes) {
+ if (node == 0u) {
+ ++result[i];
+ }
}
}
}
- return owned_buckets;
+ return result;
}
DistributorBucketSpaceTest::CountVector
DistributorBucketSpaceTest::count_buckets()
{
CountVector result;
- result.push_back(count_distributor_buckets());
- result.push_back(count_storage_buckets());
+ auto buckets = make_normal_buckets();
+ result.push_back(count_distributor_buckets(buckets));
+ auto service_layer_result = count_service_layer_buckets(buckets);
+ result.insert(result.end(), service_layer_result.cbegin(), service_layer_result.cend());
return result;
}
@@ -153,8 +142,10 @@ DistributorBucketSpaceTest::CountVector
DistributorBucketSpaceTest::count_deep_split_buckets()
{
CountVector result;
- result.push_back(count_deep_split_distributor_buckets());
- result.push_back(count_deep_split_storage_buckets());
+ auto buckets = make_deep_split_buckets([this](BucketId bucket) { return bucket_space.check_ownership_in_pending_and_current_state(bucket).isOwned(); });
+ result.push_back(count_distributor_buckets(buckets));
+ auto service_layer_result = count_service_layer_buckets(buckets);
+ result.insert(result.end(), service_layer_result.cbegin(), service_layer_result.cend());
return result;
}
@@ -162,19 +153,24 @@ TEST_F(DistributorBucketSpaceTest, check_owned_buckets)
{
bucket_space.setDistribution(distribution_r1);
bucket_space.setClusterState(stable_state);
- EXPECT_EQ((CountVector{64u, 64u}), count_buckets());
+ EXPECT_EQ((CountVector{64u, 64u, 64u, 64u}), count_buckets());
bucket_space.set_pending_cluster_state(node_1_down_state);
- EXPECT_EQ((CountVector{64u, 64u}), count_buckets());
+ EXPECT_EQ((CountVector{64u, 64u, 64u, 64u}), count_buckets());
bucket_space.setClusterState(node_1_down_state);
bucket_space.set_pending_cluster_state({});
- EXPECT_EQ((CountVector{86u, 86u}), count_buckets());
+ EXPECT_EQ((CountVector{86u, 86u, 86u, 86u}), count_buckets());
bucket_space.set_pending_cluster_state(stable_state);
- EXPECT_EQ((CountVector{64u, 86u}), count_buckets());
+ EXPECT_EQ((CountVector{64u, 86u, 86u, 86u}), count_buckets());
bucket_space.setClusterState(stable_state);
bucket_space.set_pending_cluster_state({});
- EXPECT_EQ((CountVector{64u, 64u}), count_buckets());
+ EXPECT_EQ((CountVector{64u, 64u, 64u, 64u}), count_buckets());
bucket_space.setDistribution(distribution_r2);
- EXPECT_EQ((CountVector{64u, 125u}), count_buckets());
+ EXPECT_EQ((CountVector{64u, 125u, 125u, 125u}), count_buckets());
+ bucket_space.setClusterState(node_1_maintenance_state);
+ bucket_space.setDistribution(distribution_r1);
+ EXPECT_EQ((CountVector{86u, 86u, 86u, 64u}), count_buckets());
+ bucket_space.setClusterState(node_1_retired_state);
+ EXPECT_EQ((CountVector{86u, 64u, 86u, 86u}), count_buckets());
}
TEST_F(DistributorBucketSpaceTest, check_available_nodes)
@@ -198,7 +194,7 @@ TEST_F(DistributorBucketSpaceTest, check_owned_deep_split_buckets)
{
bucket_space.setDistribution(distribution_r1);
bucket_space.setClusterState(stable_state);
- EXPECT_EQ((CountVector{100u, 19u}), count_deep_split_buckets());
+ EXPECT_EQ((CountVector{100u, 19u, 19u, 19u}), count_deep_split_buckets());
}
}