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

Method Add

src/brpc/policy/weighted_randomized_load_balancer.cpp:35–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35bool WeightedRandomizedLoadBalancer::Add(Servers& bg, const ServerId& id) {
36 if (bg.server_list.capacity() < 128) {
37 bg.server_list.reserve(128);
38 }
39 uint32_t weight = 0;
40 if (!butil::StringToUint(id.tag, &weight) || weight <= 0) {
41 if (FLAGS_default_weight_of_wlb > 0) {
42 LOG(WARNING) << "Invalid weight is set: " << id.tag
43 << ". Now, 'weight' has been set to "
44 "FLAGS_default_weight_of_wlb by default.";
45 weight = FLAGS_default_weight_of_wlb;
46 } else {
47 LOG(ERROR) << "Invalid weight is set: " << id.tag;
48 return false;
49 }
50 }
51 bool insert_server =
52 bg.server_map.emplace(id.id, bg.server_list.size()).second;
53 if (insert_server) {
54 uint64_t current_weight_sum = bg.weight_sum + weight;
55 bg.server_list.emplace_back(id.id, weight, current_weight_sum);
56 bg.weight_sum = current_weight_sum;
57 return true;
58 }
59 return false;
60}
61
62bool WeightedRandomizedLoadBalancer::Remove(Servers& bg, const ServerId& id) {
63 typedef std::map<SocketId, size_t>::iterator MapIter_t;

Callers

nothing calls this directly

Calls 4

StringToUintFunction · 0.85
capacityMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected