MCPcopy Create free account
hub / github.com/apache/impala / ComputeRandomKrpcForAggregation

Method ComputeRandomKrpcForAggregation

be/src/scheduling/scheduler.cc:398–492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396typedef vector<pair<int, int>> InstanceToAggPairs;
397
398void Scheduler::ComputeRandomKrpcForAggregation(const ExecutorConfig& executor_config,
399 ScheduleState* state, FragmentScheduleState* src_state, int num_filters_per_host) {
400 if (num_filters_per_host <= 1) return;
401 // src_state->instance_states organize fragment instances as one dimension vector
402 // where instances scheduled in same host is placed in adjacent indices.
403 // Group instance indices from common host to 'instance_groups' by comparing
404 // krpc address between adjacent element of instance_states.
405 const NetworkAddressPB& coord_address = executor_config.coord_desc.krpc_address();
406 vector<InstanceToAggPairs> instance_groups;
407 InstanceToAggPairs coordinator_instances;
408 for (int i = 0; i < src_state->instance_states.size(); ++i) {
409 const NetworkAddressPB& krpc_address = src_state->instance_states[i].krpc_host;
410 if (KrpcAddressEqual(krpc_address, coord_address)) {
411 coordinator_instances.emplace_back(i, 0);
412 } else {
413 if (i == 0
414 || !KrpcAddressEqual(
415 krpc_address, src_state->instance_states[i - 1].krpc_host)) {
416 // This is the first fragment instance scheduled in a host.
417 // Append empty InstanceToAggPairs to 'instance_groups'.
418 instance_groups.emplace_back();
419 }
420 instance_groups.back().emplace_back(i, 0);
421 }
422 }
423
424 int num_non_coordinator_host = instance_groups.size();
425 if (num_non_coordinator_host == 0) return;
426
427 // Select number of intermediate aggregator so that each aggregator will receive
428 // runtime filter update from at most 'num_filters_per_host' executors.
429 int num_agg = (int)ceil((double)num_non_coordinator_host / num_filters_per_host);
430 DCHECK_GT(num_agg, 0);
431
432 if (UNLIKELY(FLAGS_sort_runtime_filter_aggregator_candidates)) {
433 sort(instance_groups.begin(), instance_groups.end(),
434 [src_state](InstanceToAggPairs a, InstanceToAggPairs b) {
435 int idx_a = a[0].first;
436 int idx_b = b[0].first;
437 return CompareNetworkAddressPB(src_state->instance_states[idx_a].krpc_host,
438 src_state->instance_states[idx_b].krpc_host)
439 < 0;
440 });
441 } else {
442 std::shuffle(instance_groups.begin(), instance_groups.end(), *state->rng());
443 }
444 if (coordinator_instances.size() > 0) {
445 // Put coordinator group behind so that coordinator won't be selected as intermediate
446 // aggregator.
447 instance_groups.push_back(coordinator_instances);
448 }
449
450 RuntimeFilterAggregatorInfoPB* agg_info =
451 src_state->exec_params->mutable_filter_agg_info();
452 agg_info->set_num_aggregators(num_agg);
453
454 int group_idx = 0;
455 int agg_idx = -1;

Callers

nothing calls this directly

Calls 10

KrpcAddressEqualFunction · 0.85
sortFunction · 0.85
CompareNetworkAddressPBFunction · 0.85
shuffleFunction · 0.85
IsResolvedAddressFunction · 0.85
rngMethod · 0.80
push_backMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected