| 33 | } |
| 34 | |
| 35 | bool 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 | |
| 62 | bool WeightedRandomizedLoadBalancer::Remove(Servers& bg, const ServerId& id) { |
| 63 | typedef std::map<SocketId, size_t>::iterator MapIter_t; |
nothing calls this directly
no test coverage detected