Skip to content

Commit c15c567

Browse files
committed
whee
1 parent 1d22ea6 commit c15c567

File tree

14 files changed

+138
-162
lines changed

14 files changed

+138
-162
lines changed

src/core/load_balancing/health_check_client.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ void HealthProducer::OnConnectivityStateChange(grpc_connectivity_state state,
412412
}
413413
state_ = state;
414414
status_ = status;
415-
for (const auto& p : health_checkers_) {
416-
p.second->OnConnectivityStateChangeLocked(state, status);
415+
for (const auto& [_, health_checker] : health_checkers_) {
416+
health_checker->OnConnectivityStateChangeLocked(state, status);
417417
}
418418
for (HealthWatcher* watcher : non_health_watchers_) {
419419
watcher->Notify(state, status);

src/core/load_balancing/outlier_detection/outlier_detection.cc

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ absl::Status OutlierDetectionLb::UpdateLocked(UpdateArgs args) {
632632
<< "[outlier_detection_lb " << this << "] starting timer";
633633
ejection_timer_ = MakeOrphanable<EjectionTimer>(
634634
RefAsSubclass<OutlierDetectionLb>(), Timestamp::Now());
635-
for (const auto& p : endpoint_state_map_) {
636-
p.second->RotateBucket(); // Reset call counters.
635+
for (const auto& [_, endpoint_state] : endpoint_state_map_) {
636+
endpoint_state->RotateBucket(); // Reset call counters.
637637
}
638638
} else if (old_config->outlier_detection_config().interval !=
639639
config_->outlier_detection_config().interval) {
@@ -865,8 +865,7 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
865865
double success_rate_sum = 0;
866866
auto time_now = Timestamp::Now();
867867
auto& config = parent_->config_->outlier_detection_config();
868-
for (auto& state : parent_->endpoint_state_map_) {
869-
auto* endpoint_state = state.second.get();
868+
for (auto& [_, endpoint_state] : parent_->endpoint_state_map_) {
870869
// For each address, swap the call counter's buckets in that address's
871870
// map entry.
872871
endpoint_state->RotateBucket();
@@ -884,14 +883,15 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
884883
uint64_t request_volume = host_success_rate_and_volume->second;
885884
if (config.success_rate_ejection.has_value()) {
886885
if (request_volume >= config.success_rate_ejection->request_volume) {
887-
success_rate_ejection_candidates[endpoint_state] = success_rate;
886+
success_rate_ejection_candidates[endpoint_state.get()] = success_rate;
888887
success_rate_sum += success_rate;
889888
}
890889
}
891890
if (config.failure_percentage_ejection.has_value()) {
892891
if (request_volume >=
893892
config.failure_percentage_ejection->request_volume) {
894-
failure_percentage_ejection_candidates[endpoint_state] = success_rate;
893+
failure_percentage_ejection_candidates[endpoint_state.get()] =
894+
success_rate;
895895
}
896896
}
897897
}
@@ -917,8 +917,8 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
917917
// (success_rate_ejection.stdev_factor / 1000))
918918
double mean = success_rate_sum / success_rate_ejection_candidates.size();
919919
double variance = 0;
920-
for (const auto& p : success_rate_ejection_candidates) {
921-
variance += std::pow(p.second - mean, 2);
920+
for (const auto& [_, success_rate] : success_rate_ejection_candidates) {
921+
variance += std::pow(success_rate - mean, 2);
922922
}
923923
variance /= success_rate_ejection_candidates.size();
924924
double stdev = std::sqrt(variance);
@@ -928,12 +928,13 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
928928
GRPC_TRACE_LOG(outlier_detection_lb, INFO)
929929
<< "[outlier_detection_lb " << parent_.get() << "] stdev=" << stdev
930930
<< ", ejection_threshold=" << ejection_threshold;
931-
for (auto& candidate : success_rate_ejection_candidates) {
931+
for (auto& [endpoint_state, success_rate] :
932+
success_rate_ejection_candidates) {
932933
GRPC_TRACE_LOG(outlier_detection_lb, INFO)
933934
<< "[outlier_detection_lb " << parent_.get()
934-
<< "] checking candidate " << candidate.first
935-
<< ": success_rate=" << candidate.second;
936-
if (candidate.second < ejection_threshold) {
935+
<< "] checking candidate " << endpoint_state
936+
<< ": success_rate=" << success_rate;
937+
if (success_rate < ejection_threshold) {
937938
uint32_t random_key = absl::Uniform(bit_gen_, 1, 100);
938939
double current_percent =
939940
100.0 * ejected_host_count / parent_->endpoint_state_map_.size();
@@ -950,7 +951,7 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
950951
GRPC_TRACE_LOG(outlier_detection_lb, INFO)
951952
<< "[outlier_detection_lb " << parent_.get()
952953
<< "] ejecting candidate";
953-
candidate.first->Eject(time_now);
954+
endpoint_state->Eject(time_now);
954955
++ejected_host_count;
955956
}
956957
}
@@ -966,15 +967,16 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
966967
<< config.failure_percentage_ejection->threshold
967968
<< ", enforcement_percentage="
968969
<< config.failure_percentage_ejection->enforcement_percentage;
969-
for (auto& candidate : failure_percentage_ejection_candidates) {
970+
for (auto& [endpoint_state, success_rate] :
971+
failure_percentage_ejection_candidates) {
970972
GRPC_TRACE_LOG(outlier_detection_lb, INFO)
971973
<< "[outlier_detection_lb " << parent_.get()
972-
<< "] checking candidate " << candidate.first
973-
<< ": success_rate=" << candidate.second;
974+
<< "] checking candidate " << endpoint_state
975+
<< ": success_rate=" << success_rate;
974976
// Extra check to make sure success rate algorithm didn't already
975977
// eject this backend.
976-
if (candidate.first->ejection_time().has_value()) continue;
977-
if ((100.0 - candidate.second) >
978+
if (endpoint_state->ejection_time().has_value()) continue;
979+
if ((100.0 - success_rate) >
978980
config.failure_percentage_ejection->threshold) {
979981
uint32_t random_key = absl::Uniform(bit_gen_, 1, 100);
980982
double current_percent =
@@ -993,7 +995,7 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
993995
GRPC_TRACE_LOG(outlier_detection_lb, INFO)
994996
<< "[outlier_detection_lb " << parent_.get()
995997
<< "] ejecting candidate";
996-
candidate.first->Eject(time_now);
998+
endpoint_state->Eject(time_now);
997999
++ejected_host_count;
9981000
}
9991001
}
@@ -1005,14 +1007,13 @@ void OutlierDetectionLb::EjectionTimer::OnTimerLocked() {
10051007
// current time is after ejection_timestamp + min(base_ejection_time *
10061008
// multiplier, max(base_ejection_time, max_ejection_time)), un-eject the
10071009
// address.
1008-
for (auto& state : parent_->endpoint_state_map_) {
1009-
auto* endpoint_state = state.second.get();
1010+
for (auto& [address_set, endpoint_state] : parent_->endpoint_state_map_) {
10101011
const bool unejected = endpoint_state->MaybeUneject(
10111012
config.base_ejection_time.millis(), config.max_ejection_time.millis());
10121013
if (unejected && GRPC_TRACE_FLAG_ENABLED(outlier_detection_lb)) {
10131014
LOG(INFO) << "[outlier_detection_lb " << parent_.get()
1014-
<< "] unejected endpoint " << state.first.ToString() << " ("
1015-
<< endpoint_state << ")";
1015+
<< "] unejected endpoint " << address_set.ToString() << " ("
1016+
<< endpoint_state.get() << ")";
10161017
}
10171018
}
10181019
parent_->ejection_timer_ =

src/core/load_balancing/priority/priority.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void PriorityLb::ExitIdleLocked() {
318318
}
319319

320320
void PriorityLb::ResetBackoffLocked() {
321-
for (const auto& p : children_) p.second->ResetBackoffLocked();
321+
for (const auto& [_, child] : children_) child->ResetBackoffLocked();
322322
}
323323

324324
absl::Status PriorityLb::UpdateLocked(UpdateArgs args) {
@@ -334,9 +334,7 @@ absl::Status PriorityLb::UpdateLocked(UpdateArgs args) {
334334
// Check all existing children against the new config.
335335
update_in_progress_ = true;
336336
std::vector<std::string> errors;
337-
for (const auto& p : children_) {
338-
const std::string& child_name = p.first;
339-
auto& child = p.second;
337+
for (const auto& [child_name, child] : children_) {
340338
auto config_it = config_->children().find(child_name);
341339
if (config_it == config_->children().end()) {
342340
// Existing child not found in new config. Deactivate it.

src/core/load_balancing/ring_hash/ring_hash.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ class RingHash final : public LoadBalancingPolicy {
249249
endpoints_(ring_hash_->endpoints_.size()),
250250
resolution_note_(ring_hash_->resolution_note_),
251251
request_hash_header_(ring_hash_->request_hash_header_) {
252-
for (const auto& p : ring_hash_->endpoint_map_) {
253-
endpoints_[p.second->index()] = p.second->GetInfoForPicker();
254-
if (endpoints_[p.second->index()].state == GRPC_CHANNEL_CONNECTING) {
252+
for (const auto& [_, endpoint] : ring_hash_->endpoint_map_) {
253+
endpoints_[endpoint->index()] = endpoint->GetInfoForPicker();
254+
if (endpoints_[endpoint->index()].state == GRPC_CHANNEL_CONNECTING) {
255255
has_endpoint_in_connecting_state_ = true;
256256
}
257257
}
@@ -694,8 +694,8 @@ void RingHash::ShutdownLocked() {
694694
}
695695

696696
void RingHash::ResetBackoffLocked() {
697-
for (const auto& p : endpoint_map_) {
698-
p.second->ResetBackoffLocked();
697+
for (const auto& [_, endpoint] : endpoint_map_) {
698+
endpoint->ResetBackoffLocked();
699699
}
700700
}
701701

@@ -708,10 +708,10 @@ absl::Status RingHash::UpdateLocked(UpdateArgs args) {
708708
std::map<EndpointAddressSet, size_t> endpoint_indices;
709709
(*args.addresses)->ForEach([&](const EndpointAddresses& endpoint) {
710710
const EndpointAddressSet key(endpoint.addresses());
711-
auto p = endpoint_indices.emplace(key, endpoints_.size());
712-
if (!p.second) {
711+
auto [it, inserted] = endpoint_indices.emplace(key, endpoints_.size());
712+
if (!inserted) {
713713
// Duplicate endpoint. Combine weights and skip the dup.
714-
EndpointAddresses& prev_endpoint = endpoints_[p.first->second];
714+
EndpointAddresses& prev_endpoint = endpoints_[it->second];
715715
int weight_arg =
716716
endpoint.args().GetInt(GRPC_ARG_ADDRESS_WEIGHT).value_or(1);
717717
int prev_weight_arg =
@@ -794,8 +794,8 @@ void RingHash::UpdateAggregatedConnectivityStateLocked(
794794
size_t num_connecting = 0;
795795
size_t num_ready = 0;
796796
size_t num_transient_failure = 0;
797-
for (const auto& p : endpoint_map_) {
798-
switch (p.second->connectivity_state()) {
797+
for (const auto& [_, endpoint] : endpoint_map_) {
798+
switch (endpoint->connectivity_state()) {
799799
case GRPC_CHANNEL_READY:
800800
++num_ready;
801801
break;

src/core/load_balancing/rls/rls.cc

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,16 @@ class RlsLb final : public LoadBalancingPolicy {
288288
template <typename H>
289289
friend H AbslHashValue(H h, const RequestKey& key) {
290290
std::hash<std::string> string_hasher;
291-
for (auto& kv : key.key_map) {
292-
h = H::combine(std::move(h), string_hasher(kv.first),
293-
string_hasher(kv.second));
291+
for (auto& [key, value] : key.key_map) {
292+
h = H::combine(std::move(h), string_hasher(key), string_hasher(value));
294293
}
295294
return h;
296295
}
297296

298297
size_t Size() const {
299298
size_t size = sizeof(RequestKey);
300-
for (auto& kv : key_map) {
301-
size += kv.first.length() + kv.second.length();
299+
for (auto& [key, value] : key_map) {
300+
size += key.length() + value.length();
302301
}
303302
return size;
304303
}
@@ -993,9 +992,7 @@ std::map<std::string, std::string> BuildKeyMap(
993992
// Construct key map using key builder.
994993
std::map<std::string, std::string> key_map;
995994
// Add header keys.
996-
for (const auto& p : key_builder->header_keys) {
997-
const std::string& key = p.first;
998-
const std::vector<std::string>& header_names = p.second;
995+
for (const auto& [key, header_names] : key_builder->header_keys) {
999996
for (const std::string& header_name : header_names) {
1000997
std::string buffer;
1001998
absl::optional<absl::string_view> value =
@@ -1431,17 +1428,17 @@ void RlsLb::Cache::Resize(size_t bytes,
14311428
}
14321429

14331430
void RlsLb::Cache::ResetAllBackoff() {
1434-
for (auto& p : map_) {
1435-
p.second->ResetBackoff();
1431+
for (auto& [_, entry] : map_) {
1432+
entry->ResetBackoff();
14361433
}
14371434
lb_policy_->UpdatePickerAsync();
14381435
}
14391436

14401437
std::vector<RefCountedPtr<RlsLb::ChildPolicyWrapper>> RlsLb::Cache::Shutdown() {
14411438
std::vector<RefCountedPtr<ChildPolicyWrapper>>
14421439
child_policy_wrappers_to_delete;
1443-
for (auto& entry : map_) {
1444-
entry.second->TakeChildPolicyWrappers(&child_policy_wrappers_to_delete);
1440+
for (auto& [_, entry] : map_) {
1441+
entry->TakeChildPolicyWrappers(&child_policy_wrappers_to_delete);
14451442
}
14461443
map_.clear();
14471444
lru_list_.clear();
@@ -1880,10 +1877,10 @@ grpc_byte_buffer* RlsLb::RlsRequest::MakeRequestProto() {
18801877
grpc_lookup_v1_RouteLookupRequest_new(arena.ptr());
18811878
grpc_lookup_v1_RouteLookupRequest_set_target_type(
18821879
req, upb_StringView_FromDataAndSize(kGrpc, sizeof(kGrpc) - 1));
1883-
for (const auto& kv : key_.key_map) {
1880+
for (const auto& [key, value] : key_.key_map) {
18841881
grpc_lookup_v1_RouteLookupRequest_key_map_set(
1885-
req, upb_StringView_FromDataAndSize(kv.first.data(), kv.first.size()),
1886-
upb_StringView_FromDataAndSize(kv.second.data(), kv.second.size()),
1882+
req, upb_StringView_FromDataAndSize(key.data(), key.size()),
1883+
upb_StringView_FromDataAndSize(value.data(), value.size()),
18871884
arena.ptr());
18881885
}
18891886
grpc_lookup_v1_RouteLookupRequest_set_reason(req, reason_);
@@ -2055,8 +2052,8 @@ absl::Status RlsLb::UpdateLocked(UpdateArgs args) {
20552052
if (update_child_policies) {
20562053
GRPC_TRACE_LOG(rls_lb, INFO)
20572054
<< "[rlslb " << this << "] starting child policy updates";
2058-
for (auto& p : child_policy_map_) {
2059-
p.second->StartUpdate(&child_policy_to_delete);
2055+
for (auto& [_, child] : child_policy_map_) {
2056+
child->StartUpdate(&child_policy_to_delete);
20602057
}
20612058
} else if (created_default_child) {
20622059
GRPC_TRACE_LOG(rls_lb, INFO)
@@ -2069,11 +2066,11 @@ absl::Status RlsLb::UpdateLocked(UpdateArgs args) {
20692066
if (update_child_policies) {
20702067
GRPC_TRACE_LOG(rls_lb, INFO)
20712068
<< "[rlslb " << this << "] finishing child policy updates";
2072-
for (auto& p : child_policy_map_) {
2073-
absl::Status status = p.second->MaybeFinishUpdate();
2069+
for (auto& [name, child] : child_policy_map_) {
2070+
absl::Status status = child->MaybeFinishUpdate();
20742071
if (!status.ok()) {
20752072
errors.emplace_back(
2076-
absl::StrCat("target ", p.first, ": ", status.ToString()));
2073+
absl::StrCat("target ", name, ": ", status.ToString()));
20772074
}
20782075
}
20792076
} else if (created_default_child) {
@@ -2117,8 +2114,8 @@ absl::Status RlsLb::UpdateLocked(UpdateArgs args) {
21172114

21182115
void RlsLb::ExitIdleLocked() {
21192116
MutexLock lock(&mu_);
2120-
for (auto& child_entry : child_policy_map_) {
2121-
child_entry.second->ExitIdleLocked();
2117+
for (auto& [_, child] : child_policy_map_) {
2118+
child->ExitIdleLocked();
21222119
}
21232120
}
21242121

@@ -2128,8 +2125,8 @@ void RlsLb::ResetBackoffLocked() {
21282125
rls_channel_->ResetBackoff();
21292126
cache_.ResetAllBackoff();
21302127
}
2131-
for (auto& child : child_policy_map_) {
2132-
child.second->ResetBackoffLocked();
2128+
for (auto& [_, child] : child_policy_map_) {
2129+
child->ResetBackoffLocked();
21332130
}
21342131
}
21352132

@@ -2191,10 +2188,10 @@ void RlsLb::UpdatePickerLocked() {
21912188
{
21922189
MutexLock lock(&mu_);
21932190
if (is_shutdown_) return;
2194-
for (auto& p : child_policy_map_) {
2195-
grpc_connectivity_state child_state = p.second->connectivity_state();
2191+
for (auto& [_, child] : child_policy_map_) {
2192+
grpc_connectivity_state child_state = child->connectivity_state();
21962193
GRPC_TRACE_LOG(rls_lb, INFO)
2197-
<< "[rlslb " << this << "] target " << p.second->target()
2194+
<< "[rlslb " << this << "] target " << child->target()
21982195
<< " in state " << ConnectivityStateName(child_state);
21992196
if (child_state == GRPC_CHANNEL_READY) {
22002197
state = GRPC_CHANNEL_READY;
@@ -2389,9 +2386,9 @@ struct GrpcKeyBuilder {
23892386
duplicate_key_check_func(header.key,
23902387
absl::StrCat(".headers[", i, "].key"));
23912388
}
2392-
for (const auto& p : constant_keys) {
2393-
duplicate_key_check_func(
2394-
p.first, absl::StrCat(".constantKeys[\"", p.first, "\"]"));
2389+
for (const auto& [key, value] : constant_keys) {
2390+
duplicate_key_check_func(key,
2391+
absl::StrCat(".constantKeys[\"", key, "\"]"));
23952392
}
23962393
if (extra_keys.host_key.has_value()) {
23972394
duplicate_key_check_func(*extra_keys.host_key, ".extraKeys.host");

src/core/load_balancing/weighted_target/weighted_target.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void WeightedTargetLb::ShutdownLocked() {
300300
}
301301

302302
void WeightedTargetLb::ResetBackoffLocked() {
303-
for (auto& p : targets_) p.second->ResetBackoffLocked();
303+
for (auto& [_, child] : targets_) child->ResetBackoffLocked();
304304
}
305305

306306
absl::Status WeightedTargetLb::UpdateLocked(UpdateArgs args) {
@@ -311,9 +311,7 @@ absl::Status WeightedTargetLb::UpdateLocked(UpdateArgs args) {
311311
// Update config.
312312
config_ = args.config.TakeAsSubclass<WeightedTargetLbConfig>();
313313
// Deactivate the targets not in the new config.
314-
for (const auto& p : targets_) {
315-
const std::string& name = p.first;
316-
WeightedChild* child = p.second.get();
314+
for (const auto& [name, child] : targets_) {
317315
if (config_->target_map().find(name) == config_->target_map().end()) {
318316
child->DeactivateLocked();
319317
}
@@ -322,9 +320,7 @@ absl::Status WeightedTargetLb::UpdateLocked(UpdateArgs args) {
322320
absl::StatusOr<HierarchicalAddressMap> address_map =
323321
MakeHierarchicalAddressMap(args.addresses);
324322
std::vector<std::string> errors;
325-
for (const auto& p : config_->target_map()) {
326-
const std::string& name = p.first;
327-
const WeightedTargetLbConfig::ChildConfig& config = p.second;
323+
for (const auto& [name, config] : config_->target_map()) {
328324
auto& target = targets_[name];
329325
// Create child if it does not already exist.
330326
if (target == nullptr) {
@@ -392,9 +388,7 @@ void WeightedTargetLb::UpdateStateLocked() {
392388
// the aggregated state.
393389
size_t num_connecting = 0;
394390
size_t num_idle = 0;
395-
for (const auto& p : targets_) {
396-
const std::string& child_name = p.first;
397-
const WeightedChild* child = p.second.get();
391+
for (const auto& [child_name, child] : targets_) {
398392
// Skip the targets that are not in the latest update.
399393
if (config_->target_map().find(child_name) == config_->target_map().end()) {
400394
continue;

0 commit comments

Comments
 (0)