MCPcopy Create free account
hub / github.com/apache/brpc / ValidateWeightTree

Function ValidateWeightTree

test/brpc_load_balancer_unittest.cpp:335–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333typedef brpc::policy::LocalityAwareLoadBalancer LALB;
334
335static void ValidateWeightTree(
336 std::vector<LALB::ServerInfo> & weight_tree) {
337 std::vector<int64_t> weight_sum;
338 weight_sum.resize(weight_tree.size());
339 for (ssize_t i = weight_tree.size() - 1; i >= 0; --i) {
340 const size_t left_child = i * 2 + 1;
341 const size_t right_child = i * 2 + 2;
342 weight_sum[i] = weight_tree[i].weight->volatile_value();
343 if (left_child < weight_sum.size()) {
344 weight_sum[i] += weight_sum[left_child];
345 }
346 if (right_child < weight_sum.size()) {
347 weight_sum[i] += weight_sum[right_child];
348 }
349 }
350 for (size_t i = 0; i < weight_tree.size(); ++i) {
351 const int64_t left = weight_tree[i].left->load(butil::memory_order_relaxed);
352 size_t left_child = i * 2 + 1;
353 if (left_child < weight_tree.size()) {
354 ASSERT_EQ(weight_sum[left_child], left) << "i=" << i;
355 } else {
356 ASSERT_EQ(0, left);
357 }
358 }
359}
360
361static void ValidateLALB(LALB& lalb, size_t N) {
362 LALB::Servers* d = lalb._db_servers._data;

Callers 1

ValidateLALBFunction · 0.85

Calls 4

volatile_valueMethod · 0.80
resizeMethod · 0.45
sizeMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected