You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2016/10/31 16:06:03 UTC
[1/3] incubator-impala git commit: IMPALA-4314: Standardize on
MT-related data structures
Repository: incubator-impala
Updated Branches:
refs/heads/master 29faca568 -> 9b507b6ed
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/scheduling/simple-scheduler.cc
----------------------------------------------------------------------
diff --git a/be/src/scheduling/simple-scheduler.cc b/be/src/scheduling/simple-scheduler.cc
index bc500c8..9ffc273 100644
--- a/be/src/scheduling/simple-scheduler.cc
+++ b/be/src/scheduling/simple-scheduler.cc
@@ -31,7 +31,6 @@
#include "common/logging.h"
#include "util/metrics.h"
#include "runtime/exec-env.h"
-#include "runtime/coordinator.h"
#include "service/impala-server.h"
#include "statestore/statestore-subscriber.h"
@@ -290,55 +289,17 @@ SimpleScheduler::BackendConfigPtr SimpleScheduler::GetBackendConfig() const {
return backend_config;
}
-void SimpleScheduler::SetBackendConfig(const BackendConfigPtr& backend_config)
-{
+void SimpleScheduler::SetBackendConfig(const BackendConfigPtr& backend_config) {
lock_guard<mutex> l(backend_config_lock_);
backend_config_ = backend_config;
}
-Status SimpleScheduler::ComputeScanRangeAssignment(const TQueryExecRequest& exec_request,
- QuerySchedule* schedule) {
- map<TPlanNodeId, vector<TScanRangeLocations>>::const_iterator entry;
- RuntimeProfile::Counter* total_assignment_timer =
- ADD_TIMER(schedule->summary_profile(), "ComputeScanRangeAssignmentTimer");
-
- BackendConfigPtr backend_config = GetBackendConfig();
-
- for (entry = exec_request.per_node_scan_ranges.begin();
- entry != exec_request.per_node_scan_ranges.end(); ++entry) {
- const TPlanNodeId node_id = entry->first;
- FragmentIdx fragment_idx = schedule->GetFragmentIdx(node_id);
- const TPlanFragment& fragment = exec_request.fragments[fragment_idx];
- bool exec_at_coord = (fragment.partition.type == TPartitionType::UNPARTITIONED);
-
- const TPlanNode& node = fragment.plan.nodes[schedule->GetNodeIdx(node_id)];
- DCHECK_EQ(node.node_id, node_id);
-
- const TReplicaPreference::type* node_replica_preference = node.__isset.hdfs_scan_node
- && node.hdfs_scan_node.__isset.replica_preference
- ? &node.hdfs_scan_node.replica_preference : NULL;
-
- bool node_random_replica = node.__isset.hdfs_scan_node
- && node.hdfs_scan_node.__isset.random_replica
- && node.hdfs_scan_node.random_replica;
-
- FragmentScanRangeAssignment* assignment =
- &(*schedule->exec_params())[fragment_idx].scan_range_assignment;
- RETURN_IF_ERROR(ComputeScanRangeAssignment(*backend_config,
- node_id, node_replica_preference, node_random_replica, entry->second,
- exec_request.host_list, exec_at_coord, schedule->query_options(),
- total_assignment_timer, assignment));
- schedule->IncNumScanRanges(entry->second.size());
- }
- return Status::OK();
-}
-
-Status SimpleScheduler::MtComputeScanRangeAssignment(QuerySchedule* schedule) {
+Status SimpleScheduler::ComputeScanRangeAssignment(QuerySchedule* schedule) {
RuntimeProfile::Counter* total_assignment_timer =
ADD_TIMER(schedule->summary_profile(), "ComputeScanRangeAssignmentTimer");
BackendConfigPtr backend_config = GetBackendConfig();
const TQueryExecRequest& exec_request = schedule->request();
- for (const TPlanExecInfo& plan_exec_info: exec_request.mt_plan_exec_info) {
+ for (const TPlanExecInfo& plan_exec_info: exec_request.plan_exec_info) {
for (const auto& entry: plan_exec_info.per_node_scan_ranges) {
const TPlanNodeId node_id = entry.first;
const TPlanFragment& fragment = schedule->GetContainingFragment(node_id);
@@ -366,38 +327,34 @@ Status SimpleScheduler::MtComputeScanRangeAssignment(QuerySchedule* schedule) {
return Status::OK();
}
-void SimpleScheduler::MtComputeFragmentExecParams(QuerySchedule* schedule) {
+void SimpleScheduler::ComputeFragmentExecParams(QuerySchedule* schedule) {
const TQueryExecRequest& exec_request = schedule->request();
// for each plan, compute the FInstanceExecParams for the tree of fragments
- for (const TPlanExecInfo& plan_exec_info: exec_request.mt_plan_exec_info) {
+ for (const TPlanExecInfo& plan_exec_info: exec_request.plan_exec_info) {
// set instance_id, host, per_node_scan_ranges
- MtComputeFragmentExecParams(
- plan_exec_info,
+ ComputeFragmentExecParams(plan_exec_info,
schedule->GetFragmentExecParams(plan_exec_info.fragments[0].idx),
schedule);
// Set destinations, per_exch_num_senders, sender_id.
- // fragments[f] sends its output to fragments[dest_fragment_idx[f-1]];
- // fragments[0] is an endpoint.
- for (int i = 0; i < plan_exec_info.dest_fragment_idx.size(); ++i) {
- int dest_idx = plan_exec_info.dest_fragment_idx[i];
+ for (const TPlanFragment& src_fragment: plan_exec_info.fragments) {
+ if (!src_fragment.output_sink.__isset.stream_sink) continue;
+ FragmentIdx dest_idx =
+ schedule->GetFragmentIdx(src_fragment.output_sink.stream_sink.dest_node_id);
DCHECK_LT(dest_idx, plan_exec_info.fragments.size());
const TPlanFragment& dest_fragment = plan_exec_info.fragments[dest_idx];
- DCHECK_LT(i + 1, plan_exec_info.fragments.size());
- const TPlanFragment& src_fragment = plan_exec_info.fragments[i + 1];
- DCHECK(src_fragment.output_sink.__isset.stream_sink);
- MtFragmentExecParams* dest_params =
+ FragmentExecParams* dest_params =
schedule->GetFragmentExecParams(dest_fragment.idx);
- MtFragmentExecParams* src_params =
+ FragmentExecParams* src_params =
schedule->GetFragmentExecParams(src_fragment.idx);
// populate src_params->destinations
src_params->destinations.resize(dest_params->instance_exec_params.size());
- for (int j = 0; j < dest_params->instance_exec_params.size(); ++j) {
- TPlanFragmentDestination& dest = src_params->destinations[j];
- dest.__set_fragment_instance_id(dest_params->instance_exec_params[j].instance_id);
- dest.__set_server(dest_params->instance_exec_params[j].host);
+ for (int i = 0; i < dest_params->instance_exec_params.size(); ++i) {
+ TPlanFragmentDestination& dest = src_params->destinations[i];
+ dest.__set_fragment_instance_id(dest_params->instance_exec_params[i].instance_id);
+ dest.__set_server(dest_params->instance_exec_params[i].host);
}
// enumerate senders consecutively;
@@ -411,26 +368,24 @@ void SimpleScheduler::MtComputeFragmentExecParams(QuerySchedule* schedule) {
int sender_id_base = dest_params->per_exch_num_senders[exch_id];
dest_params->per_exch_num_senders[exch_id] +=
src_params->instance_exec_params.size();
- for (int j = 0; j < src_params->instance_exec_params.size(); ++j) {
- FInstanceExecParams& src_instance_params = src_params->instance_exec_params[j];
- src_instance_params.sender_id = sender_id_base + j;
+ for (int i = 0; i < src_params->instance_exec_params.size(); ++i) {
+ FInstanceExecParams& src_instance_params = src_params->instance_exec_params[i];
+ src_instance_params.sender_id = sender_id_base + i;
}
}
}
}
-void SimpleScheduler::MtComputeFragmentExecParams(
- const TPlanExecInfo& plan_exec_info, MtFragmentExecParams* fragment_params,
+void SimpleScheduler::ComputeFragmentExecParams(
+ const TPlanExecInfo& plan_exec_info, FragmentExecParams* fragment_params,
QuerySchedule* schedule) {
// traverse input fragments
for (FragmentIdx input_fragment_idx: fragment_params->input_fragments) {
- MtComputeFragmentExecParams(
+ ComputeFragmentExecParams(
plan_exec_info, schedule->GetFragmentExecParams(input_fragment_idx), schedule);
}
const TPlanFragment& fragment = fragment_params->fragment;
- // TODO: deal with Union nodes
- DCHECK(!ContainsNode(fragment.plan, TPlanNodeType::UNION_NODE));
// case 1: single instance executed at coordinator
if (fragment.partition.type == TPartitionType::UNPARTITIONED) {
const TNetworkAddress& coord = local_backend_descriptor_.address;
@@ -439,7 +394,7 @@ void SimpleScheduler::MtComputeFragmentExecParams(
? schedule->query_id()
: schedule->GetNextInstanceId();
fragment_params->instance_exec_params.emplace_back(
- instance_id, coord, 0, *fragment_params);
+ instance_id, coord, 0, *fragment_params);
FInstanceExecParams& instance_params = fragment_params->instance_exec_params.back();
// That instance gets all of the scan ranges, if there are any.
@@ -448,25 +403,81 @@ void SimpleScheduler::MtComputeFragmentExecParams(
auto first_entry = fragment_params->scan_range_assignment.begin();
instance_params.per_node_scan_ranges = first_entry->second;
}
+
+ return;
+ }
+
+ if (ContainsNode(fragment.plan, TPlanNodeType::UNION_NODE)) {
+ CreateUnionInstances(fragment_params, schedule);
+ return;
+ }
+
+ PlanNodeId leftmost_scan_id = FindLeftmostScan(fragment.plan);
+ if (leftmost_scan_id != g_ImpalaInternalService_constants.INVALID_PLAN_NODE_ID) {
+ // case 2: leaf fragment with leftmost scan
+ // TODO: check that there's only one scan in this fragment
+ CreateScanInstances(leftmost_scan_id, fragment_params, schedule);
} else {
- PlanNodeId leftmost_scan_id = FindLeftmostScan(fragment.plan);
- if (leftmost_scan_id != g_ImpalaInternalService_constants.INVALID_PLAN_NODE_ID) {
- // case 2: leaf fragment with leftmost scan
- // TODO: check that there's only one scan in this fragment
- MtCreateScanInstances(leftmost_scan_id, fragment_params, schedule);
- } else {
- // case 3: interior fragment without leftmost scan
- // we assign the same hosts as those of our leftmost input fragment (so that a
- // merge aggregation fragment runs on the hosts that provide the input data)
- MtCreateMirrorInstances(fragment_params, schedule);
+ // case 3: interior fragment without leftmost scan
+ // we assign the same hosts as those of our leftmost input fragment (so that a
+ // merge aggregation fragment runs on the hosts that provide the input data)
+ CreateCollocatedInstances(fragment_params, schedule);
+ }
+}
+
+void SimpleScheduler::CreateUnionInstances(
+ FragmentExecParams* fragment_params, QuerySchedule* schedule) {
+ const TPlanFragment& fragment = fragment_params->fragment;
+ DCHECK(ContainsNode(fragment.plan, TPlanNodeType::UNION_NODE));
+
+ // Add hosts of scan nodes.
+ vector<TPlanNodeType::type> scan_node_types {
+ TPlanNodeType::HDFS_SCAN_NODE, TPlanNodeType::HBASE_SCAN_NODE,
+ TPlanNodeType::DATA_SOURCE_NODE, TPlanNodeType::KUDU_SCAN_NODE};
+ vector<TPlanNodeId> scan_node_ids;
+ FindNodes(fragment.plan, scan_node_types, &scan_node_ids);
+ vector<TNetworkAddress> scan_hosts;
+ for (TPlanNodeId id: scan_node_ids) GetScanHosts(id, *fragment_params, &scan_hosts);
+
+ unordered_set<TNetworkAddress> hosts(scan_hosts.begin(), scan_hosts.end());
+
+ // Add hosts of input fragments.
+ for (FragmentIdx idx: fragment_params->input_fragments) {
+ const FragmentExecParams& input_params = *schedule->GetFragmentExecParams(idx);
+ for (const FInstanceExecParams& instance_params: input_params.instance_exec_params) {
+ hosts.insert(instance_params.host);
+ }
+ }
+ DCHECK(!hosts.empty())
+ << "no hosts for fragment " << fragment.idx << " with a UnionNode";
+
+ // create a single instance per host
+ // TODO-MT: figure out how to parallelize Union
+ int per_fragment_idx = 0;
+ for (const TNetworkAddress& host: hosts) {
+ fragment_params->instance_exec_params.emplace_back(
+ schedule->GetNextInstanceId(), host, per_fragment_idx++, *fragment_params);
+ // assign all scan ranges
+ FInstanceExecParams& instance_params = fragment_params->instance_exec_params.back();
+ if (fragment_params->scan_range_assignment.count(host) > 0) {
+ instance_params.per_node_scan_ranges = fragment_params->scan_range_assignment[host];
}
}
}
-void SimpleScheduler::MtCreateScanInstances(
- PlanNodeId leftmost_scan_id, MtFragmentExecParams* fragment_params,
+void SimpleScheduler::CreateScanInstances(
+ PlanNodeId leftmost_scan_id, FragmentExecParams* fragment_params,
QuerySchedule* schedule) {
int max_num_instances = schedule->request().query_ctx.request.query_options.mt_dop;
+ if (max_num_instances == 0) max_num_instances = 1;
+
+ if (fragment_params->scan_range_assignment.empty()) {
+ // this scan doesn't have any scan ranges: run a single instance on the coordinator
+ fragment_params->instance_exec_params.emplace_back(
+ schedule->GetNextInstanceId(), local_backend_descriptor_.address, 0, *fragment_params);
+ return;
+ }
+
for (const auto& assignment_entry: fragment_params->scan_range_assignment) {
// evenly divide up the scan ranges of the leftmost scan between at most
// <dop> instances
@@ -477,9 +488,13 @@ void SimpleScheduler::MtCreateScanInstances(
int64 total_size = 0;
for (const TScanRangeParams& params: params_list) {
- // TODO: implement logic for hbase and kudu
- DCHECK(params.scan_range.__isset.hdfs_file_split);
- total_size += params.scan_range.hdfs_file_split.length;
+ if (params.scan_range.__isset.hdfs_file_split) {
+ total_size += params.scan_range.hdfs_file_split.length;
+ } else {
+ // fake load-balancing for Kudu and Hbase: every split has length 1
+ // TODO: implement more accurate logic for Kudu and Hbase
+ ++total_size;
+ }
}
// try to load-balance scan ranges by assigning just beyond the average number of
@@ -507,7 +522,12 @@ void SimpleScheduler::MtCreateScanInstances(
const TScanRangeParams& scan_range_params = params_list[params_idx];
instance_params.per_node_scan_ranges[leftmost_scan_id].push_back(
scan_range_params);
- total_assigned_bytes += scan_range_params.scan_range.hdfs_file_split.length;
+ if (scan_range_params.scan_range.__isset.hdfs_file_split) {
+ total_assigned_bytes += scan_range_params.scan_range.hdfs_file_split.length;
+ } else {
+ // for Kudu and Hbase every split has length 1
+ ++total_assigned_bytes;
+ }
++params_idx;
}
if (params_idx >= params_list.size()) break; // nothing left to assign
@@ -516,10 +536,10 @@ void SimpleScheduler::MtCreateScanInstances(
}
}
-void SimpleScheduler::MtCreateMirrorInstances(
- MtFragmentExecParams* fragment_params, QuerySchedule* schedule) {
+void SimpleScheduler::CreateCollocatedInstances(
+ FragmentExecParams* fragment_params, QuerySchedule* schedule) {
DCHECK_GE(fragment_params->input_fragments.size(), 1);
- const MtFragmentExecParams* input_fragment_params =
+ const FragmentExecParams* input_fragment_params =
schedule->GetFragmentExecParams(fragment_params->input_fragments[0]);
int per_fragment_instance_idx = 0;
for (const FInstanceExecParams& input_instance_params:
@@ -533,7 +553,7 @@ void SimpleScheduler::MtCreateMirrorInstances(
Status SimpleScheduler::ComputeScanRangeAssignment(
const BackendConfig& backend_config, PlanNodeId node_id,
const TReplicaPreference::type* node_replica_preference, bool node_random_replica,
- const vector<TScanRangeLocations>& locations,
+ const vector<TScanRangeLocationList>& locations,
const vector<TNetworkAddress>& host_list, bool exec_at_coord,
const TQueryOptions& query_options, RuntimeProfile::Counter* timer,
FragmentScanRangeAssignment* assignment) {
@@ -564,11 +584,11 @@ Status SimpleScheduler::ComputeScanRangeAssignment(
AssignmentCtx assignment_ctx(backend_config, total_assignments_,
total_local_assignments_);
- vector<const TScanRangeLocations*> remote_scan_range_locations;
+ vector<const TScanRangeLocationList*> remote_scan_range_locations;
// Loop over all scan ranges, select a backend for those with local impalads and collect
// all others for later processing.
- for (const TScanRangeLocations& scan_range_locations: locations) {
+ for (const TScanRangeLocationList& scan_range_locations: locations) {
TReplicaPreference::type min_distance = TReplicaPreference::REMOTE;
// Select backend host for the current scan range.
@@ -643,7 +663,7 @@ Status SimpleScheduler::ComputeScanRangeAssignment(
} // End of for loop over scan ranges.
// Assign remote scans to backends.
- for (const TScanRangeLocations* scan_range_locations: remote_scan_range_locations) {
+ for (const TScanRangeLocationList* scan_range_locations: remote_scan_range_locations) {
const IpAddr* backend_ip = assignment_ctx.SelectRemoteBackendHost();
TBackendDescriptor backend;
assignment_ctx.SelectBackendOnHost(*backend_ip, &backend);
@@ -656,132 +676,6 @@ Status SimpleScheduler::ComputeScanRangeAssignment(
return Status::OK();
}
-void SimpleScheduler::ComputeFragmentExecParams(const TQueryExecRequest& exec_request,
- QuerySchedule* schedule) {
- vector<FragmentExecParams>* fragment_exec_params = schedule->exec_params();
- // assign instance ids
- int64_t num_fragment_instances = 0;
- for (FragmentExecParams& params: *fragment_exec_params) {
- for (int j = 0; j < params.hosts.size(); ++j, ++num_fragment_instances) {
- params.instance_ids.push_back(
- CreateInstanceId(schedule->query_id(), num_fragment_instances));
- }
- }
-
- // compute destinations and # senders per exchange node
- // (the root fragment doesn't have a destination)
- for (int i = 1; i < fragment_exec_params->size(); ++i) {
- FragmentExecParams& params = (*fragment_exec_params)[i];
- int dest_fragment_idx = exec_request.dest_fragment_idx[i - 1];
- DCHECK_LT(dest_fragment_idx, fragment_exec_params->size());
- FragmentExecParams& dest_params = (*fragment_exec_params)[dest_fragment_idx];
-
- // set # of senders
- DCHECK(exec_request.fragments[i].output_sink.__isset.stream_sink);
- const TDataStreamSink& sink = exec_request.fragments[i].output_sink.stream_sink;
- // we can only handle unpartitioned (= broadcast), random-partitioned or
- // hash-partitioned output at the moment
- DCHECK(sink.output_partition.type == TPartitionType::UNPARTITIONED
- || sink.output_partition.type == TPartitionType::HASH_PARTITIONED
- || sink.output_partition.type == TPartitionType::RANDOM);
- PlanNodeId exch_id = sink.dest_node_id;
- // we might have multiple fragments sending to this exchange node
- // (distributed MERGE), which is why we need to add up the #senders
- params.sender_id_base = dest_params.per_exch_num_senders[exch_id];
- dest_params.per_exch_num_senders[exch_id] += params.hosts.size();
-
- // create one TPlanFragmentDestination per destination host
- params.destinations.resize(dest_params.hosts.size());
- for (int j = 0; j < dest_params.hosts.size(); ++j) {
- TPlanFragmentDestination& dest = params.destinations[j];
- dest.fragment_instance_id = dest_params.instance_ids[j];
- dest.server = dest_params.hosts[j];
- VLOG_RPC << "dest for fragment " << i << ":"
- << " instance_id=" << dest.fragment_instance_id
- << " server=" << dest.server;
- }
- }
-}
-
-void SimpleScheduler::ComputeFragmentHosts(const TQueryExecRequest& exec_request,
- QuerySchedule* schedule) {
- vector<FragmentExecParams>* fragment_exec_params = schedule->exec_params();
- DCHECK_EQ(fragment_exec_params->size(), exec_request.fragments.size());
-
- // compute hosts of producer fragment before those of consumer fragment(s),
- // the latter might inherit the set of hosts from the former
- for (int i = exec_request.fragments.size() - 1; i >= 0; --i) {
- const TPlanFragment& fragment = exec_request.fragments[i];
- FragmentExecParams& params = (*fragment_exec_params)[i];
- if (fragment.partition.type == TPartitionType::UNPARTITIONED) {
- // all single-node fragments run on the coordinator host
- params.hosts.push_back(local_backend_descriptor_.address);
- continue;
- }
-
- // UnionNodes are special because they can consume multiple partitioned inputs,
- // as well as execute multiple scans in the same fragment.
- // Fragments containing a UnionNode are executed on the union of hosts of all
- // scans in the fragment as well as the hosts of all its input fragments (s.t.
- // a UnionNode with partitioned joins or grouping aggregates as children runs on
- // at least as many hosts as the input to those children).
- if (ContainsNode(fragment.plan, TPlanNodeType::UNION_NODE)) {
- vector<TPlanNodeType::type> scan_node_types {
- TPlanNodeType::HDFS_SCAN_NODE, TPlanNodeType::HBASE_SCAN_NODE,
- TPlanNodeType::DATA_SOURCE_NODE, TPlanNodeType::KUDU_SCAN_NODE};
- vector<TPlanNodeId> scan_nodes;
- FindNodes(fragment.plan, scan_node_types, &scan_nodes);
- vector<TPlanNodeId> exch_nodes;
- FindNodes(fragment.plan,
- vector<TPlanNodeType::type>(1, TPlanNodeType::EXCHANGE_NODE),
- &exch_nodes);
-
- // Add hosts of scan nodes.
- vector<TNetworkAddress> scan_hosts;
- for (int j = 0; j < scan_nodes.size(); ++j) {
- GetScanHosts(scan_nodes[j], exec_request, params, &scan_hosts);
- }
- unordered_set<TNetworkAddress> hosts(scan_hosts.begin(), scan_hosts.end());
-
- // Add hosts of input fragments.
- for (int j = 0; j < exch_nodes.size(); ++j) {
- int input_fragment_idx = FindSenderFragment(exch_nodes[j], i, exec_request);
- const vector<TNetworkAddress>& input_fragment_hosts =
- (*fragment_exec_params)[input_fragment_idx].hosts;
- hosts.insert(input_fragment_hosts.begin(), input_fragment_hosts.end());
- }
- DCHECK(!hosts.empty()) << "no hosts for fragment " << i << " with a UnionNode";
-
- params.hosts.assign(hosts.begin(), hosts.end());
- continue;
- }
-
- PlanNodeId leftmost_scan_id = FindLeftmostScan(fragment.plan);
- if (leftmost_scan_id == g_ImpalaInternalService_constants.INVALID_PLAN_NODE_ID) {
- // there is no leftmost scan; we assign the same hosts as those of our
- // leftmost input fragment (so that a partitioned aggregation fragment
- // runs on the hosts that provide the input data)
- int input_fragment_idx = FindLeftmostInputFragment(i, exec_request);
- DCHECK_GE(input_fragment_idx, 0);
- DCHECK_LT(input_fragment_idx, fragment_exec_params->size());
- params.hosts = (*fragment_exec_params)[input_fragment_idx].hosts;
- // TODO: switch to unpartitioned/coord execution if our input fragment
- // is executed that way (could have been downgraded from distributed)
- continue;
- }
-
- // This fragment is executed on those hosts that have scan ranges
- // for the leftmost scan.
- GetScanHosts(leftmost_scan_id, exec_request, params, ¶ms.hosts);
- }
-
- unordered_set<TNetworkAddress> unique_hosts;
- for (const FragmentExecParams& exec_params: *fragment_exec_params) {
- unique_hosts.insert(exec_params.hosts.begin(), exec_params.hosts.end());
- }
- schedule->SetUniqueHosts(unique_hosts);
-}
-
PlanNodeId SimpleScheduler::FindLeftmostNode(
const TPlan& plan, const vector<TPlanNodeType::type>& types) {
// the first node with num_children == 0 is the leftmost node
@@ -827,11 +721,17 @@ void SimpleScheduler::FindNodes(const TPlan& plan,
}
void SimpleScheduler::GetScanHosts(TPlanNodeId scan_id,
- const TQueryExecRequest& exec_request, const FragmentExecParams& params,
- vector<TNetworkAddress>* scan_hosts) {
- map<TPlanNodeId, vector<TScanRangeLocations>>::const_iterator entry =
- exec_request.per_node_scan_ranges.find(scan_id);
- if (entry == exec_request.per_node_scan_ranges.end() || entry->second.empty()) {
+ const FragmentExecParams& params, vector<TNetworkAddress>* scan_hosts) {
+ // Get the list of impalad host from scan_range_assignment_
+ for (const FragmentScanRangeAssignment::value_type& scan_range_assignment:
+ params.scan_range_assignment) {
+ const PerNodeScanRanges& per_node_scan_ranges = scan_range_assignment.second;
+ if (per_node_scan_ranges.find(scan_id) != per_node_scan_ranges.end()) {
+ scan_hosts->push_back(scan_range_assignment.first);
+ }
+ }
+
+ if (scan_hosts->empty()) {
// this scan node doesn't have any scan ranges; run it on the coordinator
// TODO: we'll need to revisit this strategy once we can partition joins
// (in which case this fragment might be executing a right outer join
@@ -839,40 +739,6 @@ void SimpleScheduler::GetScanHosts(TPlanNodeId scan_id,
scan_hosts->push_back(local_backend_descriptor_.address);
return;
}
-
- // Get the list of impalad host from scan_range_assignment_
- for (const FragmentScanRangeAssignment::value_type& scan_range_assignment:
- params.scan_range_assignment) {
- scan_hosts->push_back(scan_range_assignment.first);
- }
-}
-
-int SimpleScheduler::FindLeftmostInputFragment(
- int fragment_idx, const TQueryExecRequest& exec_request) {
- // find the leftmost node, which we expect to be an exchage node
- vector<TPlanNodeType::type> exch_node_type;
- exch_node_type.push_back(TPlanNodeType::EXCHANGE_NODE);
- PlanNodeId exch_id =
- FindLeftmostNode(exec_request.fragments[fragment_idx].plan, exch_node_type);
- if (exch_id == g_ImpalaInternalService_constants.INVALID_PLAN_NODE_ID) {
- return g_ImpalaInternalService_constants.INVALID_PLAN_NODE_ID;
- }
- // find the fragment that sends to this exchange node
- return FindSenderFragment(exch_id, fragment_idx, exec_request);
-}
-
-int SimpleScheduler::FindSenderFragment(TPlanNodeId exch_id, int fragment_idx,
- const TQueryExecRequest& exec_request) {
- for (int i = 0; i < exec_request.dest_fragment_idx.size(); ++i) {
- if (exec_request.dest_fragment_idx[i] != fragment_idx) continue;
- const TPlanFragment& input_fragment = exec_request.fragments[i + 1];
- DCHECK(input_fragment.__isset.output_sink);
- DCHECK(input_fragment.output_sink.__isset.stream_sink);
- if (input_fragment.output_sink.stream_sink.dest_node_id == exch_id) return i + 1;
- }
- // this shouldn't happen
- DCHECK(false) << "no fragment sends to exch id " << exch_id;
- return g_ImpalaInternalService_constants.INVALID_PLAN_NODE_ID;
}
Status SimpleScheduler::Schedule(QuerySchedule* schedule) {
@@ -882,29 +748,26 @@ Status SimpleScheduler::Schedule(QuerySchedule* schedule) {
schedule->set_request_pool(resolved_pool);
schedule->summary_profile()->AddInfoString("Request Pool", resolved_pool);
- bool is_mt_execution = schedule->request().query_ctx.request.query_options.mt_dop > 0;
- if (is_mt_execution) {
- RETURN_IF_ERROR(MtComputeScanRangeAssignment(schedule));
- MtComputeFragmentExecParams(schedule);
-
- // compute unique hosts
- unordered_set<TNetworkAddress> unique_hosts;
- for (const MtFragmentExecParams& f: schedule->mt_fragment_exec_params()) {
- for (const FInstanceExecParams& i: f.instance_exec_params) {
- unique_hosts.insert(i.host);
- }
- }
- schedule->SetUniqueHosts(unique_hosts);
+ RETURN_IF_ERROR(ComputeScanRangeAssignment(schedule));
+ ComputeFragmentExecParams(schedule);
+#ifndef NDEBUG
+ schedule->Validate();
+#endif
- // TODO-MT: call AdmitQuery()
- } else {
- RETURN_IF_ERROR(ComputeScanRangeAssignment(schedule->request(), schedule));
- ComputeFragmentHosts(schedule->request(), schedule);
- ComputeFragmentExecParams(schedule->request(), schedule);
- if (!FLAGS_disable_admission_control) {
- RETURN_IF_ERROR(admission_controller_->AdmitQuery(schedule));
+ // compute unique hosts
+ unordered_set<TNetworkAddress> unique_hosts;
+ for (const FragmentExecParams& f: schedule->fragment_exec_params()) {
+ for (const FInstanceExecParams& i: f.instance_exec_params) {
+ unique_hosts.insert(i.host);
}
}
+ schedule->SetUniqueHosts(unique_hosts);
+
+ // TODO-MT: call AdmitQuery()
+ bool is_mt_execution = schedule->request().query_ctx.request.query_options.mt_dop > 0;
+ if (!is_mt_execution && !FLAGS_disable_admission_control) {
+ RETURN_IF_ERROR(admission_controller_->AdmitQuery(schedule));
+ }
return Status::OK();
}
@@ -1020,7 +883,7 @@ void SimpleScheduler::AssignmentCtx::SelectBackendOnHost(const IpAddr& backend_i
void SimpleScheduler::AssignmentCtx::RecordScanRangeAssignment(
const TBackendDescriptor& backend, PlanNodeId node_id,
const vector<TNetworkAddress>& host_list,
- const TScanRangeLocations& scan_range_locations,
+ const TScanRangeLocationList& scan_range_locations,
FragmentScanRangeAssignment* assignment) {
int64_t scan_range_length = 0;
if (scan_range_locations.scan_range.__isset.hdfs_file_split) {
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/scheduling/simple-scheduler.h
----------------------------------------------------------------------
diff --git a/be/src/scheduling/simple-scheduler.h b/be/src/scheduling/simple-scheduler.h
index 6a9d6db..cc68432 100644
--- a/be/src/scheduling/simple-scheduler.h
+++ b/be/src/scheduling/simple-scheduler.h
@@ -40,8 +40,6 @@
namespace impala {
-class Coordinator;
-
namespace test {
class SchedulerWrapper;
}
@@ -199,7 +197,7 @@ class SimpleScheduler : public Scheduler {
/// scan range and its replica locations.
void RecordScanRangeAssignment(const TBackendDescriptor& backend, PlanNodeId node_id,
const vector<TNetworkAddress>& host_list,
- const TScanRangeLocations& scan_range_locations,
+ const TScanRangeLocationList& scan_range_locations,
FragmentScanRangeAssignment* assignment);
const BackendConfig& backend_config() const { return backend_config_; }
@@ -331,11 +329,11 @@ class SimpleScheduler : public Scheduler {
Status GetRequestPool(const std::string& user, const TQueryOptions& query_options,
std::string* pool) const;
- /// Compute the assignment of scan ranges to hosts for each scan node in 'schedule'.
+ /// Compute the assignment of scan ranges to hosts for each scan node in
+ /// the schedule's TQueryExecRequest.plan_exec_info.
/// Unpartitioned fragments are assigned to the coordinator. Populate the schedule's
/// fragment_exec_params_ with the resulting scan range assignment.
- Status ComputeScanRangeAssignment(const TQueryExecRequest& exec_request,
- QuerySchedule* schedule);
+ Status ComputeScanRangeAssignment(QuerySchedule* schedule);
/// Process the list of scan ranges of a single plan node and compute scan range
/// assignments (returned in 'assignment'). The result is a mapping from hosts to their
@@ -397,50 +395,49 @@ class SimpleScheduler : public Scheduler {
/// assignment: Output parameter, to which new assignments will be added.
Status ComputeScanRangeAssignment(const BackendConfig& backend_config,
PlanNodeId node_id, const TReplicaPreference::type* node_replica_preference,
- bool node_random_replica, const std::vector<TScanRangeLocations>& locations,
+ bool node_random_replica, const std::vector<TScanRangeLocationList>& locations,
const std::vector<TNetworkAddress>& host_list, bool exec_at_coord,
const TQueryOptions& query_options, RuntimeProfile::Counter* timer,
FragmentScanRangeAssignment* assignment);
- /// Populate fragment_exec_params_ in schedule.
- void ComputeFragmentExecParams(const TQueryExecRequest& exec_request,
- QuerySchedule* schedule);
-
- /// Compute the assignment of scan ranges to hosts for each scan node in
- /// the schedule's TQueryExecRequest.mt_plan_exec_info.
- /// Unpartitioned fragments are assigned to the coordinator. Populate the schedule's
- /// mt_fragment_exec_params_ with the resulting scan range assignment.
- Status MtComputeScanRangeAssignment(QuerySchedule* schedule);
-
- /// Compute the MtFragmentExecParams for all plans in the schedule's
- /// TQueryExecRequest.mt_plan_exec_info.
+ /// Compute the FragmentExecParams for all plans in the schedule's
+ /// TQueryExecRequest.plan_exec_info.
/// This includes the routing information (destinations, per_exch_num_senders,
/// sender_id)
- void MtComputeFragmentExecParams(QuerySchedule* schedule);
+ void ComputeFragmentExecParams(QuerySchedule* schedule);
/// Recursively create FInstanceExecParams and set per_node_scan_ranges for
/// fragment_params and its input fragments via a depth-first traversal.
/// All fragments are part of plan_exec_info.
- void MtComputeFragmentExecParams(const TPlanExecInfo& plan_exec_info,
- MtFragmentExecParams* fragment_params, QuerySchedule* schedule);
+ void ComputeFragmentExecParams(const TPlanExecInfo& plan_exec_info,
+ FragmentExecParams* fragment_params, QuerySchedule* schedule);
+
+ /// Create instances of the fragment corresponding to fragment_params, which contains
+ /// a Union node.
+ /// UnionNodes are special because they can consume multiple partitioned inputs,
+ /// as well as execute multiple scans in the same fragment.
+ /// Fragments containing a UnionNode are executed on the union of hosts of all
+ /// scans in the fragment as well as the hosts of all its input fragments (s.t.
+ /// a UnionNode with partitioned joins or grouping aggregates as children runs on
+ /// at least as many hosts as the input to those children).
+ /// TODO: is this really necessary? If not, revise.
+ void CreateUnionInstances(
+ FragmentExecParams* fragment_params, QuerySchedule* schedule);
/// Create instances of the fragment corresponding to fragment_params to run on the
/// selected replica hosts of the scan ranges of the node with id scan_id.
/// The maximum number of instances is the value of query option mt_dop.
- /// This attempts to load balance among instances by computing the average number
- /// of bytes per instances and then in a single pass assigning scan ranges to each
+ /// For HDFS, this attempts to load balance among instances by computing the average
+ /// number of bytes per instances and then in a single pass assigning scan ranges to each
/// instances to roughly meet that average.
- void MtCreateScanInstances(PlanNodeId scan_id,
- MtFragmentExecParams* fragment_params, QuerySchedule* schedule);
-
- /// For each instance of the single input fragment of the fragment corresponding to
- /// fragment_params, create an instance for this fragment.
- void MtCreateMirrorInstances(MtFragmentExecParams* fragment_params,
- QuerySchedule* schedule);
-
- /// For each fragment in exec_request, computes hosts on which to run the instances
- /// and stores result in fragment_exec_params_.hosts.
- void ComputeFragmentHosts(const TQueryExecRequest& exec_request,
+ /// For all other storage mgrs, it load-balances the number of splits per instance.
+ void CreateScanInstances(PlanNodeId scan_id,
+ FragmentExecParams* fragment_params, QuerySchedule* schedule);
+
+ /// For each instance of fragment_params's input fragment, create a collocated
+ /// instance for fragment_params's fragment.
+ /// Expects that fragment_params only has a single input fragment.
+ void CreateCollocatedInstances(FragmentExecParams* fragment_params,
QuerySchedule* schedule);
/// Return the id of the leftmost node of any of the given types in 'plan', or
@@ -450,14 +447,9 @@ class SimpleScheduler : public Scheduler {
/// Same for scan nodes.
PlanNodeId FindLeftmostScan(const TPlan& plan);
- /// Return the index (w/in exec_request.fragments) of fragment that sends its output to
- /// exec_request.fragment[fragment_idx]'s leftmost ExchangeNode.
- /// Return INVALID_PLAN_NODE_ID if the leftmost node is not an exchange node.
- int FindLeftmostInputFragment(int fragment_idx, const TQueryExecRequest& exec_request);
-
/// Add all hosts the given scan is executed on to scan_hosts.
- void GetScanHosts(TPlanNodeId scan_id, const TQueryExecRequest& exec_request,
- const FragmentExecParams& params, std::vector<TNetworkAddress>* scan_hosts);
+ void GetScanHosts(TPlanNodeId scan_id, const FragmentExecParams& params,
+ std::vector<TNetworkAddress>* scan_hosts);
/// Return true if 'plan' contains a node of the given type.
bool ContainsNode(const TPlan& plan, TPlanNodeType::type type);
@@ -466,11 +458,6 @@ class SimpleScheduler : public Scheduler {
void FindNodes(const TPlan& plan, const std::vector<TPlanNodeType::type>& types,
std::vector<TPlanNodeId>* results);
- /// Returns the index (w/in exec_request.fragments) of fragment that sends its output
- /// to the given exchange in the given fragment index.
- int FindSenderFragment(TPlanNodeId exch_id, int fragment_idx,
- const TQueryExecRequest& exec_request);
-
friend class impala::test::SchedulerWrapper;
FRIEND_TEST(SimpleAssignmentTest, ComputeAssignmentDeterministicNonCached);
FRIEND_TEST(SimpleAssignmentTest, ComputeAssignmentRandomNonCached);
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/service/impala-http-handler.cc
----------------------------------------------------------------------
diff --git a/be/src/service/impala-http-handler.cc b/be/src/service/impala-http-handler.cc
index 923c864..b335a29 100644
--- a/be/src/service/impala-http-handler.cc
+++ b/be/src/service/impala-http-handler.cc
@@ -713,7 +713,12 @@ void ImpalaHttpHandler::QuerySummaryHandler(bool include_json_plan, bool include
summary = exec_state->coord()->exec_summary();
}
if (include_json_plan) {
- fragments = exec_state->exec_request().query_exec_request.fragments;
+ for (const TPlanExecInfo& plan_exec_info:
+ exec_state->exec_request().query_exec_request.plan_exec_info) {
+ for (const TPlanFragment& fragment: plan_exec_info.fragments) {
+ fragments.push_back(fragment);
+ }
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/service/impala-server.cc
----------------------------------------------------------------------
diff --git a/be/src/service/impala-server.cc b/be/src/service/impala-server.cc
index 4886bdf..c0eed50 100644
--- a/be/src/service/impala-server.cc
+++ b/be/src/service/impala-server.cc
@@ -1599,7 +1599,11 @@ ImpalaServer::QueryStateRecord::QueryStateRecord(const QueryExecState& exec_stat
}
// Save the query fragments so that the plan can be visualised.
- fragments = exec_state.exec_request().query_exec_request.fragments;
+ for (const TPlanExecInfo& plan_exec_info:
+ exec_state.exec_request().query_exec_request.plan_exec_info) {
+ fragments.insert(fragments.end(),
+ plan_exec_info.fragments.begin(), plan_exec_info.fragments.end());
+ }
all_rows_returned = exec_state.eos();
last_active_time = exec_state.last_active();
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/service/query-exec-state.cc
----------------------------------------------------------------------
diff --git a/be/src/service/query-exec-state.cc b/be/src/service/query-exec-state.cc
index 7c40d37..5cd4c0c 100644
--- a/be/src/service/query-exec-state.cc
+++ b/be/src/service/query-exec-state.cc
@@ -379,8 +379,7 @@ Status ImpalaServer::QueryExecState::ExecLocalCatalogOp(
Status ImpalaServer::QueryExecState::ExecQueryOrDmlRequest(
const TQueryExecRequest& query_exec_request) {
// we always need at least one plan fragment
- DCHECK(query_exec_request.fragments.size() > 0
- || query_exec_request.mt_plan_exec_info.size() > 0);
+ DCHECK(query_exec_request.plan_exec_info.size() > 0);
if (query_exec_request.__isset.query_plan) {
stringstream plan_ss;
@@ -427,11 +426,6 @@ Status ImpalaServer::QueryExecState::ExecQueryOrDmlRequest(
summary_profile_.AddInfoString(TABLES_WITH_CORRUPT_STATS_KEY, ss.str());
}
- bool is_mt_exec = query_exec_request.query_ctx.request.query_options.mt_dop > 0;
- const TPlanFragment& fragment = is_mt_exec
- ? query_exec_request.mt_plan_exec_info[0].fragments[0]
- : query_exec_request.fragments[0];
-
{
lock_guard<mutex> l(lock_);
// Don't start executing the query if Cancel() was called concurrently with Exec().
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/common/thrift/Frontend.thrift
----------------------------------------------------------------------
diff --git a/common/thrift/Frontend.thrift b/common/thrift/Frontend.thrift
index fbbf7be..f6ba35a 100644
--- a/common/thrift/Frontend.thrift
+++ b/common/thrift/Frontend.thrift
@@ -347,15 +347,9 @@ struct TPlanExecInfo {
// it is unpartitioned.
1: required list<Planner.TPlanFragment> fragments
- // Specifies the destination fragment of the output of each fragment.
- // dest_fragment_idx.size() == fragments.size() - 1 and
- // fragments[i] sends its output to fragments[dest_fragment_idx[i-1]]
- // TODO: remove; TPlanFragment.output_sink.dest_node_id is sufficient
- 2: optional list<i32> dest_fragment_idx
-
// A map from scan node ids to a list of scan range locations.
- // The node ids refer to scan nodes in fragments[].plan_tree
- 3: optional map<Types.TPlanNodeId, list<Planner.TScanRangeLocations>>
+ // The node ids refer to scan nodes in fragments[].plan
+ 2: optional map<Types.TPlanNodeId, list<Planner.TScanRangeLocationList>>
per_node_scan_ranges
}
@@ -364,57 +358,39 @@ struct TQueryExecRequest {
// global descriptor tbl for all fragments
1: optional Descriptors.TDescriptorTable desc_tbl
- // fragments[i] may consume the output of fragments[j > i];
- // fragments[0] is the root fragment and also the coordinator fragment, if
- // it is unpartitioned.
- 2: optional list<Planner.TPlanFragment> fragments
-
- // Specifies the destination fragment of the output of each fragment.
- // parent_fragment_idx.size() == fragments.size() - 1 and
- // fragments[i] sends its output to fragments[dest_fragment_idx[i-1]]
- 3: optional list<i32> dest_fragment_idx
-
- // A map from scan node ids to a list of scan range locations.
- // The node ids refer to scan nodes in fragments[].plan_tree
- 4: optional map<Types.TPlanNodeId, list<Planner.TScanRangeLocations>>
- per_node_scan_ranges
-
- // Multi-threaded execution: exec info for all plans; the first one materializes
- // the query result
- // TODO: this will eventually supercede fields fragments, dest_fragment_idx,
- // per_node_scan_ranges
- 14: optional list<TPlanExecInfo> mt_plan_exec_info
+ // exec info for all plans; the first one materializes the query result
+ 2: optional list<TPlanExecInfo> plan_exec_info
// Metadata of the query result set (only for select)
- 5: optional Results.TResultSetMetadata result_set_metadata
+ 3: optional Results.TResultSetMetadata result_set_metadata
// Set if the query needs finalization after it executes
- 6: optional TFinalizeParams finalize_params
+ 4: optional TFinalizeParams finalize_params
- 7: required ImpalaInternalService.TQueryCtx query_ctx
+ 5: required ImpalaInternalService.TQueryCtx query_ctx
// The same as the output of 'explain <query>'
- 8: optional string query_plan
+ 6: optional string query_plan
// The statement type governs when the coordinator can judge a query to be finished.
// DML queries are complete after Wait(), SELECTs may not be. Generally matches
// the stmt_type of the parent TExecRequest, but in some cases (such as CREATE TABLE
// AS SELECT), these may differ.
- 9: required Types.TStmtType stmt_type
+ 7: required Types.TStmtType stmt_type
// Estimated per-host peak memory consumption in bytes. Used for resource management.
- 10: optional i64 per_host_mem_req
+ 8: optional i64 per_host_mem_req
// Estimated per-host CPU requirements in YARN virtual cores.
// Used for resource management.
// TODO: Remove this and associated code in Planner.
- 11: optional i16 per_host_vcores
+ 9: optional i16 per_host_vcores
// List of replica hosts. Used by the host_idx field of TScanRangeLocation.
- 12: required list<Types.TNetworkAddress> host_list
+ 10: required list<Types.TNetworkAddress> host_list
// Column lineage graph
- 13: optional LineageGraph.TLineageGraph lineage_graph
+ 11: optional LineageGraph.TLineageGraph lineage_graph
}
enum TCatalogOpType {
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/common/thrift/Planner.thrift
----------------------------------------------------------------------
diff --git a/common/thrift/Planner.thrift b/common/thrift/Planner.thrift
index 92c8681..766551e 100644
--- a/common/thrift/Planner.thrift
+++ b/common/thrift/Planner.thrift
@@ -77,9 +77,7 @@ struct TScanRangeLocation {
}
// A single scan range plus the hosts that serve it
-// TODO: rename to TScanRangeLocationList, having this differ from the above struct
-// by only a single letter has caused needless confusion
-struct TScanRangeLocations {
+struct TScanRangeLocationList {
1: required PlanNodes.TScanRange scan_range
// non-empty list
2: list<TScanRangeLocation> locations
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/main/java/org/apache/impala/planner/DataSourceScanNode.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/DataSourceScanNode.java b/fe/src/main/java/org/apache/impala/planner/DataSourceScanNode.java
index 1f5665f..307e67e 100644
--- a/fe/src/main/java/org/apache/impala/planner/DataSourceScanNode.java
+++ b/fe/src/main/java/org/apache/impala/planner/DataSourceScanNode.java
@@ -54,7 +54,7 @@ import org.apache.impala.thrift.TPlanNodeType;
import org.apache.impala.thrift.TQueryOptions;
import org.apache.impala.thrift.TScanRange;
import org.apache.impala.thrift.TScanRangeLocation;
-import org.apache.impala.thrift.TScanRangeLocations;
+import org.apache.impala.thrift.TScanRangeLocationList;
import org.apache.impala.thrift.TStatus;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
@@ -322,7 +322,7 @@ public class DataSourceScanNode extends ScanNode {
TNetworkAddress networkAddress = addressToTNetworkAddress("localhost:12345");
Integer hostIndex = analyzer.getHostIndex().getIndex(networkAddress);
scanRanges_ = Lists.newArrayList(
- new TScanRangeLocations(
+ new TScanRangeLocationList(
new TScanRange(), Lists.newArrayList(new TScanRangeLocation(hostIndex))));
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/main/java/org/apache/impala/planner/HBaseScanNode.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/HBaseScanNode.java b/fe/src/main/java/org/apache/impala/planner/HBaseScanNode.java
index f299131..89296f1 100644
--- a/fe/src/main/java/org/apache/impala/planner/HBaseScanNode.java
+++ b/fe/src/main/java/org/apache/impala/planner/HBaseScanNode.java
@@ -59,7 +59,7 @@ import org.apache.impala.thrift.TPlanNodeType;
import org.apache.impala.thrift.TQueryOptions;
import org.apache.impala.thrift.TScanRange;
import org.apache.impala.thrift.TScanRangeLocation;
-import org.apache.impala.thrift.TScanRangeLocations;
+import org.apache.impala.thrift.TScanRangeLocationList;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -337,13 +337,13 @@ public class HBaseScanNode extends ScanNode {
// extend the key range
setKeyRangeEnd(keyRange, curRegEndKey);
} else {
- // create a new HBaseKeyRange (and TScanRange2/TScanRangeLocations to go
+ // create a new HBaseKeyRange (and TScanRange2/TScanRangeLocationList to go
// with it).
keyRange = new THBaseKeyRange();
setKeyRangeStart(keyRange, curRegStartKey);
setKeyRangeEnd(keyRange, curRegEndKey);
- TScanRangeLocations scanRangeLocation = new TScanRangeLocations();
+ TScanRangeLocationList scanRangeLocation = new TScanRangeLocationList();
TNetworkAddress networkAddress = addressToTNetworkAddress(locEntry.getKey());
scanRangeLocation.addToLocations(
new TScanRangeLocation(analyzer.getHostIndex().getIndex(networkAddress)));
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java b/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
index 95d86e3..66ed792 100644
--- a/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
+++ b/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
@@ -51,7 +51,7 @@ import org.apache.impala.thrift.TQueryOptions;
import org.apache.impala.thrift.TReplicaPreference;
import org.apache.impala.thrift.TScanRange;
import org.apache.impala.thrift.TScanRangeLocation;
-import org.apache.impala.thrift.TScanRangeLocations;
+import org.apache.impala.thrift.TScanRangeLocationList;
import org.apache.impala.util.MembershipSnapshot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -353,7 +353,7 @@ public class HdfsScanNode extends ScanNode {
fileDesc.getFileName(), currentOffset, currentLength, partition.getId(),
fileDesc.getFileLength(), fileDesc.getFileCompression(),
fileDesc.getModificationTime()));
- TScanRangeLocations scanRangeLocations = new TScanRangeLocations();
+ TScanRangeLocationList scanRangeLocations = new TScanRangeLocationList();
scanRangeLocations.scan_range = scanRange;
scanRangeLocations.locations = locations;
scanRanges_.add(scanRangeLocations);
@@ -456,7 +456,7 @@ public class HdfsScanNode extends ScanNode {
int totalNodes = 0;
int numLocalRanges = 0;
int numRemoteRanges = 0;
- for (TScanRangeLocations range: scanRanges_) {
+ for (TScanRangeLocationList range: scanRanges_) {
boolean anyLocal = false;
for (TScanRangeLocation loc: range.locations) {
TNetworkAddress dataNode = analyzer.getHostIndex().getEntry(loc.getHost_idx());
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java b/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
index d338608..7ef1c20 100644
--- a/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
+++ b/fe/src/main/java/org/apache/impala/planner/KuduScanNode.java
@@ -43,7 +43,7 @@ import org.apache.impala.thrift.TPlanNode;
import org.apache.impala.thrift.TPlanNodeType;
import org.apache.impala.thrift.TScanRange;
import org.apache.impala.thrift.TScanRangeLocation;
-import org.apache.impala.thrift.TScanRangeLocations;
+import org.apache.impala.thrift.TScanRangeLocationList;
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.Schema;
import org.apache.kudu.client.KuduClient;
@@ -183,7 +183,7 @@ public class KuduScanNode extends ScanNode {
token.toString(), e);
}
- TScanRangeLocations locs = new TScanRangeLocations();
+ TScanRangeLocationList locs = new TScanRangeLocationList();
locs.setScan_range(scanRange);
locs.locations = locations;
scanRanges_.add(locs);
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/main/java/org/apache/impala/planner/Planner.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/Planner.java b/fe/src/main/java/org/apache/impala/planner/Planner.java
index fade723..ec4cf7e 100644
--- a/fe/src/main/java/org/apache/impala/planner/Planner.java
+++ b/fe/src/main/java/org/apache/impala/planner/Planner.java
@@ -302,9 +302,7 @@ public class Planner {
for (int i = 0; i < fragments.size(); ++i) {
PlanFragment fragment = fragments.get(i);
str.append(fragment.getExplainString(explainLevel));
- if (explainLevel == TExplainLevel.VERBOSE && i + 1 != fragments.size()) {
- str.append("\n");
- }
+ if (i < fragments.size() - 1) str.append("\n");
}
}
return str.toString();
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/main/java/org/apache/impala/planner/ScanNode.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/planner/ScanNode.java b/fe/src/main/java/org/apache/impala/planner/ScanNode.java
index f444ffa..985a03a 100644
--- a/fe/src/main/java/org/apache/impala/planner/ScanNode.java
+++ b/fe/src/main/java/org/apache/impala/planner/ScanNode.java
@@ -26,7 +26,7 @@ import org.apache.impala.catalog.Type;
import org.apache.impala.common.NotImplementedException;
import org.apache.impala.thrift.TExplainLevel;
import org.apache.impala.thrift.TNetworkAddress;
-import org.apache.impala.thrift.TScanRangeLocations;
+import org.apache.impala.thrift.TScanRangeLocationList;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
@@ -45,7 +45,7 @@ abstract public class ScanNode extends PlanNode {
protected int numPartitionsMissingStats_ = 0;
// List of scan-range locations. Populated in init().
- protected List<TScanRangeLocations> scanRanges_;
+ protected List<TScanRangeLocationList> scanRanges_;
public ScanNode(PlanNodeId id, TupleDescriptor desc, String displayName) {
super(id, desc.getId().asList(), displayName);
@@ -82,7 +82,7 @@ abstract public class ScanNode extends PlanNode {
/**
* Returns all scan ranges plus their locations.
*/
- public List<TScanRangeLocations> getScanRangeLocations() {
+ public List<TScanRangeLocationList> getScanRangeLocations() {
Preconditions.checkNotNull(scanRanges_, "Need to call init() first.");
return scanRanges_;
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/main/java/org/apache/impala/service/Frontend.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/Frontend.java b/fe/src/main/java/org/apache/impala/service/Frontend.java
index 4bb51ad..a974278 100644
--- a/fe/src/main/java/org/apache/impala/service/Frontend.java
+++ b/fe/src/main/java/org/apache/impala/service/Frontend.java
@@ -919,27 +919,15 @@ public class Frontend {
TPlanExecInfo result = new TPlanExecInfo();
ArrayList<PlanFragment> fragments = planRoot.getNodesPreOrder();
- // map from fragment to its index in TPlanExecInfo.fragments; needed for
- // TPlanExecInfo.dest_fragment_idx
+ // collect ScanNodes
List<ScanNode> scanNodes = Lists.newArrayList();
- Map<PlanFragment, Integer> fragmentIdx = Maps.newHashMap();
- for (int idx = 0; idx < fragments.size(); ++idx) {
- PlanFragment fragment = fragments.get(idx);
+ for (PlanFragment fragment: fragments) {
Preconditions.checkNotNull(fragment.getPlanRoot());
fragment.getPlanRoot().collect(Predicates.instanceOf(ScanNode.class), scanNodes);
- fragmentIdx.put(fragment, idx);
- }
-
- // set fragment destinations
- for (int i = 1; i < fragments.size(); ++i) {
- PlanFragment dest = fragments.get(i).getDestFragment();
- Integer idx = fragmentIdx.get(dest);
- Preconditions.checkState(idx != null);
- result.addToDest_fragment_idx(idx.intValue());
}
// Set scan ranges/locations for scan nodes.
- LOG.debug("get scan range locations");
+ LOG.trace("get scan range locations");
Set<TTableName> tablesMissingStats = Sets.newTreeSet();
Set<TTableName> tablesWithCorruptStats = Sets.newTreeSet();
for (ScanNode scanNode: scanNodes) {
@@ -960,6 +948,16 @@ public class Frontend {
queryCtx.addToTables_with_corrupt_stats(tableName);
}
+ // Compute resource requirements after scan range locations because the cost
+ // estimates of scan nodes rely on them.
+ try {
+ planner.computeResourceReqs(fragments, true, queryExecRequest);
+ } catch (Exception e) {
+ // Turn exceptions into a warning to allow the query to execute.
+ LOG.error("Failed to compute resource requirements for query\n" +
+ queryCtx.request.getStmt(), e);
+ }
+
// The fragment at this point has all state set, serialize it to thrift.
for (PlanFragment fragment: fragments) {
TPlanFragment thriftFragment = fragment.toThrift();
@@ -970,144 +968,54 @@ public class Frontend {
}
/**
- * Create a populated TQueryExecRequest, corresponding to the supplied planner,
- * for multi-threaded execution.
+ * Create a populated TQueryExecRequest, corresponding to the supplied planner.
*/
- private TQueryExecRequest mtCreateExecRequest(
- Planner planner, StringBuilder explainString)
- throws ImpalaException {
+ private TQueryExecRequest createExecRequest(
+ Planner planner, StringBuilder explainString) throws ImpalaException {
TQueryCtx queryCtx = planner.getQueryCtx();
- Preconditions.checkState(queryCtx.request.query_options.mt_dop > 0);
- // for now, always disable spilling in the backend
- // TODO-MT: re-enable spilling
- queryCtx.setDisable_spilling(true);
- TQueryExecRequest result = new TQueryExecRequest();
-
- LOG.debug("create mt plan");
- List<PlanFragment> planRoots = planner.createParallelPlans();
+ AnalysisContext.AnalysisResult analysisResult = planner.getAnalysisResult();
+ boolean isMtExec =
+ analysisResult.isQueryStmt() && queryCtx.request.query_options.mt_dop > 0;
- // create EXPLAIN output
- result.setQuery_ctx(queryCtx); // needed by getExplainString()
- explainString.append(
- planner.getExplainString(Lists.newArrayList(planRoots.get(0)), result));
- result.setQuery_plan(explainString.toString());
+ List<PlanFragment> planRoots = Lists.newArrayList();
+ TQueryExecRequest result = new TQueryExecRequest();
+ if (isMtExec) {
+ LOG.debug("create mt plan");
+ planRoots.addAll(planner.createParallelPlans());
+ } else {
+ LOG.debug("create plan");
+ planRoots.add(planner.createPlan().get(0));
+ }
// create per-plan exec info;
// also assemble list of names of tables with missing or corrupt stats for
// assembling a warning message
for (PlanFragment planRoot: planRoots) {
- result.addToMt_plan_exec_info(
+ result.addToPlan_exec_info(
createPlanExecInfo(planRoot, planner, queryCtx, result));
}
- // assign fragment ids
- int idx = 0;
- for (TPlanExecInfo planExecInfo: result.mt_plan_exec_info) {
- for (TPlanFragment fragment: planExecInfo.fragments) fragment.setIdx(idx++);
- }
-
- // TODO-MT: implement
- // Compute resource requirements after scan range locations because the cost
- // estimates of scan nodes rely on them.
- //try {
- //planner.computeResourceReqs(fragments, true, queryExecRequest);
- //} catch (Exception e) {
- //// Turn exceptions into a warning to allow the query to execute.
- //LOG.error("Failed to compute resource requirements for query\n" +
- //queryCtx.request.getStmt(), e);
- //}
-
- return result;
- }
-
- /**
- * Create a populated TQueryExecRequest corresponding to the supplied TQueryCtx.
- * TODO-MT: remove this function and rename mtCreateExecRequest() to
- * createExecRequest()
- */
- private TQueryExecRequest createExecRequest(
- Planner planner, StringBuilder explainString)
- throws ImpalaException {
- LOG.debug("create plan");
- ArrayList<PlanFragment> fragments = planner.createPlan();
-
- List<ScanNode> scanNodes = Lists.newArrayList();
- // map from fragment to its index in queryExecRequest.fragments; needed for
- // queryExecRequest.dest_fragment_idx
- Map<PlanFragment, Integer> fragmentIdx = Maps.newHashMap();
-
- for (int idx = 0; idx < fragments.size(); ++idx) {
- PlanFragment fragment = fragments.get(idx);
- Preconditions.checkNotNull(fragment.getPlanRoot());
- fragment.getPlanRoot().collect(Predicates.instanceOf(ScanNode.class), scanNodes);
- fragmentIdx.put(fragment, idx);
- }
-
- TQueryExecRequest result = new TQueryExecRequest();
- // set fragment destinations
- for (int i = 1; i < fragments.size(); ++i) {
- PlanFragment dest = fragments.get(i).getDestFragment();
- Integer idx = fragmentIdx.get(dest);
- Preconditions.checkState(idx != null);
- result.addToDest_fragment_idx(idx.intValue());
- }
-
- // Set scan ranges/locations for scan nodes.
- // Also assemble list of tables names missing stats for assembling a warning message.
- LOG.debug("get scan range locations");
- Set<TTableName> tablesMissingStats = Sets.newTreeSet();
- // Assemble a similar list for corrupt stats
- Set<TTableName> tablesWithCorruptStats = Sets.newTreeSet();
- for (ScanNode scanNode: scanNodes) {
- result.putToPer_node_scan_ranges(
- scanNode.getId().asInt(), scanNode.getScanRangeLocations());
- if (scanNode.isTableMissingStats()) {
- tablesMissingStats.add(scanNode.getTupleDesc().getTableName().toThrift());
- }
- if (scanNode.hasCorruptTableStats()) {
- tablesWithCorruptStats.add(scanNode.getTupleDesc().getTableName().toThrift());
- }
- }
-
- TQueryCtx queryCtx = planner.getQueryCtx();
- for (TTableName tableName: tablesMissingStats) {
- queryCtx.addToTables_missing_stats(tableName);
- }
- for (TTableName tableName: tablesWithCorruptStats) {
- queryCtx.addToTables_with_corrupt_stats(tableName);
- }
-
// Optionally disable spilling in the backend. Allow spilling if there are plan hints
// or if all tables have stats.
- AnalysisContext.AnalysisResult analysisResult = planner.getAnalysisResult();
- if (queryCtx.request.query_options.isDisable_unsafe_spills()
- && !tablesMissingStats.isEmpty()
- && !analysisResult.getAnalyzer().hasPlanHints()) {
- queryCtx.setDisable_spilling(true);
- }
-
- // Compute resource requirements after scan range locations because the cost
- // estimates of scan nodes rely on them.
- try {
- planner.computeResourceReqs(fragments, true, result);
- } catch (Exception e) {
- // Turn exceptions into a warning to allow the query to execute.
- LOG.error("Failed to compute resource requirements for query\n" +
- queryCtx.request.getStmt(), e);
- }
-
- // The fragment at this point has all state set, assign sequential ids
- // and serialize to thrift.
- for (int i = 0; i < fragments.size(); ++i) {
- PlanFragment fragment = fragments.get(i);
- TPlanFragment thriftFragment = fragment.toThrift();
- thriftFragment.setIdx(i);
- result.addToFragments(thriftFragment);
+ boolean disableSpilling =
+ queryCtx.request.query_options.isDisable_unsafe_spills()
+ && !queryCtx.tables_missing_stats.isEmpty()
+ && !analysisResult.getAnalyzer().hasPlanHints();
+ // for now, always disable spilling for multi-threaded execution
+ if (isMtExec || disableSpilling) queryCtx.setDisable_spilling(true);
+
+ // assign fragment idx
+ int idx = 0;
+ for (TPlanExecInfo planExecInfo: result.plan_exec_info) {
+ for (TPlanFragment fragment: planExecInfo.fragments) fragment.setIdx(idx++);
}
+ // create EXPLAIN output after setting everything else
result.setQuery_ctx(queryCtx); // needed by getExplainString()
- explainString.append(planner.getExplainString(fragments, result));
+ ArrayList<PlanFragment> allFragments = planRoots.get(0).getNodesPreOrder();
+ explainString.append(planner.getExplainString(allFragments, result));
result.setQuery_plan(explainString.toString());
+
return result;
}
@@ -1156,12 +1064,7 @@ public class Frontend {
|| analysisResult.isDeleteStmt());
Planner planner = new Planner(analysisResult, queryCtx);
- TQueryExecRequest queryExecRequest;
- if (analysisResult.isQueryStmt() && queryCtx.request.query_options.mt_dop > 0) {
- queryExecRequest = mtCreateExecRequest(planner, explainString);
- } else {
- queryExecRequest = createExecRequest(planner, explainString);
- }
+ TQueryExecRequest queryExecRequest = createExecRequest(planner, explainString);
queryExecRequest.setDesc_tbl(
planner.getAnalysisResult().getAnalyzer().getDescTbl().toThrift());
queryExecRequest.setQuery_ctx(queryCtx);
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/fe/src/test/java/org/apache/impala/planner/PlannerTestBase.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/planner/PlannerTestBase.java b/fe/src/test/java/org/apache/impala/planner/PlannerTestBase.java
index a94901b..745efa3 100644
--- a/fe/src/test/java/org/apache/impala/planner/PlannerTestBase.java
+++ b/fe/src/test/java/org/apache/impala/planner/PlannerTestBase.java
@@ -57,12 +57,13 @@ import org.apache.impala.thrift.THdfsScanNode;
import org.apache.impala.thrift.THdfsTable;
import org.apache.impala.thrift.TLineageGraph;
import org.apache.impala.thrift.TNetworkAddress;
+import org.apache.impala.thrift.TPlanExecInfo;
import org.apache.impala.thrift.TPlanFragment;
import org.apache.impala.thrift.TPlanNode;
import org.apache.impala.thrift.TQueryCtx;
import org.apache.impala.thrift.TQueryExecRequest;
import org.apache.impala.thrift.TQueryOptions;
-import org.apache.impala.thrift.TScanRangeLocations;
+import org.apache.impala.thrift.TScanRangeLocationList;
import org.apache.impala.thrift.TTableDescriptor;
import org.apache.impala.thrift.TTableSink;
import org.apache.impala.thrift.TTupleDescriptor;
@@ -133,9 +134,11 @@ public class PlannerTestBase extends FrontendTestBase {
planMap_.clear();
tupleMap_.clear();
tableMap_.clear();
- for (TPlanFragment frag: execRequest.fragments) {
- for (TPlanNode node: frag.plan.nodes) {
- planMap_.put(node.node_id, node);
+ for (TPlanExecInfo execInfo: execRequest.plan_exec_info) {
+ for (TPlanFragment frag: execInfo.fragments) {
+ for (TPlanNode node: frag.plan.nodes) {
+ planMap_.put(node.node_id, node);
+ }
}
}
if (execRequest.isSetDesc_tbl()) {
@@ -194,24 +197,28 @@ public class PlannerTestBase extends FrontendTestBase {
long insertTableId = -1;
// Collect all partitions that are referenced by a scan range.
Set<THdfsPartition> scanRangePartitions = Sets.newHashSet();
- if (execRequest.per_node_scan_ranges != null) {
- for (Map.Entry<Integer, List<TScanRangeLocations>> entry:
- execRequest.per_node_scan_ranges.entrySet()) {
- if (entry.getValue() == null) {
- continue;
- }
- for (TScanRangeLocations locations: entry.getValue()) {
- if (locations.scan_range.isSetHdfs_file_split()) {
- THdfsFileSplit split = locations.scan_range.getHdfs_file_split();
- THdfsPartition partition = findPartition(entry.getKey(), split);
- scanRangePartitions.add(partition);
+ for (TPlanExecInfo execInfo: execRequest.plan_exec_info) {
+ if (execInfo.per_node_scan_ranges != null) {
+ for (Map.Entry<Integer, List<TScanRangeLocationList>> entry:
+ execInfo.per_node_scan_ranges.entrySet()) {
+ if (entry.getValue() == null) {
+ continue;
+ }
+ for (TScanRangeLocationList locationList: entry.getValue()) {
+ if (locationList.scan_range.isSetHdfs_file_split()) {
+ THdfsFileSplit split = locationList.scan_range.getHdfs_file_split();
+ THdfsPartition partition = findPartition(entry.getKey(), split);
+ scanRangePartitions.add(partition);
+ }
}
}
}
}
+
if (execRequest.isSetFinalize_params()) {
insertTableId = execRequest.getFinalize_params().getTable_id();
}
+
boolean first = true;
// Iterate through all partitions of the descriptor table and verify all partitions
// are referenced.
@@ -241,64 +248,62 @@ public class PlannerTestBase extends FrontendTestBase {
*/
private StringBuilder printScanRangeLocations(TQueryExecRequest execRequest) {
StringBuilder result = new StringBuilder();
- if (execRequest.per_node_scan_ranges == null) {
- return result;
- }
- for (Map.Entry<Integer, List<TScanRangeLocations>> entry:
- execRequest.per_node_scan_ranges.entrySet()) {
- result.append("NODE " + entry.getKey().toString() + ":\n");
- if (entry.getValue() == null) {
- continue;
- }
-
- for (TScanRangeLocations locations: entry.getValue()) {
- // print scan range
- result.append(" ");
- if (locations.scan_range.isSetHdfs_file_split()) {
- THdfsFileSplit split = locations.scan_range.getHdfs_file_split();
- THdfsTable table = findTable(entry.getKey());
- THdfsPartition partition = table.getPartitions().get(split.partition_id);
- THdfsPartitionLocation location = partition.getLocation();
- String file_location = location.getSuffix();
- if (location.prefix_index != -1) {
- file_location =
- table.getPartition_prefixes().get(location.prefix_index) + file_location;
- }
- Path filePath = new Path(file_location, split.file_name);
- filePath = cleanseFilePath(filePath);
- result.append("HDFS SPLIT " + filePath.toString() + " "
- + Long.toString(split.offset) + ":" + Long.toString(split.length));
- }
- if (locations.scan_range.isSetHbase_key_range()) {
- THBaseKeyRange keyRange = locations.scan_range.getHbase_key_range();
- Integer hostIdx = locations.locations.get(0).host_idx;
- TNetworkAddress networkAddress = execRequest.getHost_list().get(hostIdx);
- result.append("HBASE KEYRANGE ");
- result.append("port=" + networkAddress.port + " ");
- if (keyRange.isSetStartKey()) {
- result.append(HBaseScanNode.printKey(keyRange.getStartKey().getBytes()));
- } else {
- result.append("<unbounded>");
+ for (TPlanExecInfo execInfo: execRequest.plan_exec_info) {
+ if (execInfo.per_node_scan_ranges == null) continue;
+ for (Map.Entry<Integer, List<TScanRangeLocationList>> entry:
+ execInfo.per_node_scan_ranges.entrySet()) {
+ result.append("NODE " + entry.getKey().toString() + ":\n");
+ if (entry.getValue() == null) continue;
+
+ for (TScanRangeLocationList locations: entry.getValue()) {
+ // print scan range
+ result.append(" ");
+ if (locations.scan_range.isSetHdfs_file_split()) {
+ THdfsFileSplit split = locations.scan_range.getHdfs_file_split();
+ THdfsTable table = findTable(entry.getKey());
+ THdfsPartition partition = table.getPartitions().get(split.partition_id);
+ THdfsPartitionLocation location = partition.getLocation();
+ String file_location = location.getSuffix();
+ if (location.prefix_index != -1) {
+ file_location =
+ table.getPartition_prefixes().get(location.prefix_index) + file_location;
+ }
+ Path filePath = new Path(file_location, split.file_name);
+ filePath = cleanseFilePath(filePath);
+ result.append("HDFS SPLIT " + filePath.toString() + " "
+ + Long.toString(split.offset) + ":" + Long.toString(split.length));
}
- result.append(":");
- if (keyRange.isSetStopKey()) {
- result.append(HBaseScanNode.printKey(keyRange.getStopKey().getBytes()));
- } else {
- result.append("<unbounded>");
+ if (locations.scan_range.isSetHbase_key_range()) {
+ THBaseKeyRange keyRange = locations.scan_range.getHbase_key_range();
+ Integer hostIdx = locations.locations.get(0).host_idx;
+ TNetworkAddress networkAddress = execRequest.getHost_list().get(hostIdx);
+ result.append("HBASE KEYRANGE ");
+ result.append("port=" + networkAddress.port + " ");
+ if (keyRange.isSetStartKey()) {
+ result.append(HBaseScanNode.printKey(keyRange.getStartKey().getBytes()));
+ } else {
+ result.append("<unbounded>");
+ }
+ result.append(":");
+ if (keyRange.isSetStopKey()) {
+ result.append(HBaseScanNode.printKey(keyRange.getStopKey().getBytes()));
+ } else {
+ result.append("<unbounded>");
+ }
}
- }
- if (locations.scan_range.isSetKudu_scan_token()) {
- Preconditions.checkNotNull(kuduClient_,
- "Test should not be invoked on platforms that do not support Kudu.");
- try {
- result.append(KuduScanToken.stringifySerializedToken(
- locations.scan_range.kudu_scan_token.array(), kuduClient_));
- } catch (IOException e) {
- throw new IllegalStateException("Unable to parse Kudu scan token", e);
+ if (locations.scan_range.isSetKudu_scan_token()) {
+ Preconditions.checkNotNull(kuduClient_,
+ "Test should not be invoked on platforms that do not support Kudu.");
+ try {
+ result.append(KuduScanToken.stringifySerializedToken(
+ locations.scan_range.kudu_scan_token.array(), kuduClient_));
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to parse Kudu scan token", e);
+ }
}
+ result.append("\n");
}
- result.append("\n");
}
}
return result;
@@ -446,8 +451,8 @@ public class PlannerTestBase extends FrontendTestBase {
}
}
- if (execRequest.isSetFragments() && !execRequest.fragments.isEmpty()) {
- TPlanFragment firstPlanFragment = execRequest.fragments.get(0);
+ if (execRequest.isSetPlan_exec_info() && !execRequest.plan_exec_info.isEmpty()) {
+ TPlanFragment firstPlanFragment = execRequest.plan_exec_info.get(0).fragments.get(0);
if (firstPlanFragment.isSetOutput_sink()
&& firstPlanFragment.output_sink.isSetTable_sink()) {
TTableSink tableSink = firstPlanFragment.output_sink.table_sink;
@@ -552,7 +557,7 @@ public class PlannerTestBase extends FrontendTestBase {
// Query exec request may not be set for DDL, e.g., CTAS.
String locationsStr = null;
if (execRequest != null && execRequest.isSetQuery_exec_request()) {
- if (execRequest.query_exec_request.fragments == null) return;
+ if (execRequest.query_exec_request.plan_exec_info == null) return;
buildMaps(execRequest.query_exec_request);
// If we optimize the partition key scans, we may get all the partition key values
// from the metadata and don't reference any table. Skip the check in this case.
@@ -614,27 +619,29 @@ public class PlannerTestBase extends FrontendTestBase {
if (execRequest == null) return;
if (!execRequest.isSetQuery_exec_request()
|| execRequest.query_exec_request == null
- || execRequest.query_exec_request.fragments == null) {
+ || execRequest.query_exec_request.plan_exec_info == null) {
return;
}
- for (TPlanFragment planFragment : execRequest.query_exec_request.fragments) {
- if (!planFragment.isSetPlan() || planFragment.plan == null) continue;
- for (TPlanNode node : planFragment.plan.nodes) {
- if (!node.isSetLimit() || -1 == node.limit) continue;
- if (!node.isSetEstimated_stats() || node.estimated_stats == null) continue;
- if (node.limit < node.estimated_stats.cardinality) {
- StringBuilder limitCardinalityError = new StringBuilder();
- limitCardinalityError.append("Query: " + query + "\n");
- limitCardinalityError.append(
- "Expected cardinality estimate less than or equal to LIMIT: "
- + node.limit + "\n");
- limitCardinalityError.append(
- "Actual cardinality estimate: "
- + node.estimated_stats.cardinality + "\n");
- limitCardinalityError.append(
- "In node id "
- + node.node_id + "\n");
- errorLog.append(limitCardinalityError.toString());
+ for (TPlanExecInfo execInfo : execRequest.query_exec_request.plan_exec_info) {
+ for (TPlanFragment planFragment : execInfo.fragments) {
+ if (!planFragment.isSetPlan() || planFragment.plan == null) continue;
+ for (TPlanNode node : planFragment.plan.nodes) {
+ if (!node.isSetLimit() || -1 == node.limit) continue;
+ if (!node.isSetEstimated_stats() || node.estimated_stats == null) continue;
+ if (node.limit < node.estimated_stats.cardinality) {
+ StringBuilder limitCardinalityError = new StringBuilder();
+ limitCardinalityError.append("Query: " + query + "\n");
+ limitCardinalityError.append(
+ "Expected cardinality estimate less than or equal to LIMIT: "
+ + node.limit + "\n");
+ limitCardinalityError.append(
+ "Actual cardinality estimate: "
+ + node.estimated_stats.cardinality + "\n");
+ limitCardinalityError.append(
+ "In node id "
+ + node.node_id + "\n");
+ errorLog.append(limitCardinalityError.toString());
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/testdata/workloads/functional-planner/queries/PlannerTest/mt-dop-validation.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-planner/queries/PlannerTest/mt-dop-validation.test b/testdata/workloads/functional-planner/queries/PlannerTest/mt-dop-validation.test
index fe25599..6ce43db 100644
--- a/testdata/workloads/functional-planner/queries/PlannerTest/mt-dop-validation.test
+++ b/testdata/workloads/functional-planner/queries/PlannerTest/mt-dop-validation.test
@@ -70,23 +70,23 @@ PLAN-ROOT SINK
|
02:TOP-N [LIMIT=10]
| order by: count(int_col) ASC, bigint_col ASC
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=160B
| tuple-ids=2 row-size=16B cardinality=10
|
04:AGGREGATE [FINALIZE]
| output: count:merge(int_col)
| group by: bigint_col
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=128.00MB
| tuple-ids=1 row-size=16B cardinality=unavailable
|
03:EXCHANGE [HASH(bigint_col)]
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=1 row-size=16B cardinality=unavailable
|
01:AGGREGATE [STREAMING]
| output: count(int_col)
| group by: bigint_col
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=128.00MB
| tuple-ids=1 row-size=16B cardinality=unavailable
|
00:SCAN HDFS [functional_parquet.alltypes, RANDOM]
@@ -94,7 +94,7 @@ PLAN-ROOT SINK
predicates: id < 10
table stats: unavailable
column stats: unavailable
- hosts=3 per-host-mem=unavailable
+ hosts=3 per-host-mem=16.00MB
tuple-ids=0 row-size=16B cardinality=unavailable
====
# Single-table scan/filter/analysic should work.
@@ -136,16 +136,16 @@ PLAN-ROOT SINK
| partition by: int_col
| order by: id ASC
| window: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=3,2 row-size=16B cardinality=unavailable
|
01:SORT
| order by: int_col ASC NULLS FIRST, id ASC
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=3 row-size=8B cardinality=unavailable
|
03:EXCHANGE [HASH(int_col)]
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=0 row-size=8B cardinality=unavailable
|
00:SCAN HDFS [functional_parquet.alltypes, RANDOM]
@@ -153,7 +153,7 @@ PLAN-ROOT SINK
predicates: id < 10
table stats: unavailable
column stats: unavailable
- hosts=3 per-host-mem=unavailable
+ hosts=3 per-host-mem=16.00MB
tuple-ids=0 row-size=8B cardinality=unavailable
====
# Nested-loop join in a subplan should work.
@@ -216,39 +216,39 @@ PLAN-ROOT SINK
| tuple-ids=2,1,0 row-size=562B cardinality=1500000
|
01:SUBPLAN
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=2,1,0 row-size=562B cardinality=1500000
|
|--08:NESTED LOOP JOIN [CROSS JOIN]
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=254B
| | tuple-ids=2,1,0 row-size=562B cardinality=100
| |
| |--02:SINGULAR ROW SRC
| | parent-subplan=01
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=0B
| | tuple-ids=0 row-size=254B cardinality=1
| |
| 04:SUBPLAN
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=0B
| | tuple-ids=2,1 row-size=308B cardinality=100
| |
| |--07:NESTED LOOP JOIN [CROSS JOIN]
-| | | hosts=3 per-host-mem=unavailable
+| | | hosts=3 per-host-mem=124B
| | | tuple-ids=2,1 row-size=308B cardinality=10
| | |
| | |--05:SINGULAR ROW SRC
| | | parent-subplan=04
-| | | hosts=3 per-host-mem=unavailable
+| | | hosts=3 per-host-mem=0B
| | | tuple-ids=1 row-size=124B cardinality=1
| | |
| | 06:UNNEST [o.o_lineitems]
| | parent-subplan=04
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=0B
| | tuple-ids=2 row-size=0B cardinality=10
| |
| 03:UNNEST [c.c_orders o]
| parent-subplan=01
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=1 row-size=0B cardinality=10
|
00:SCAN HDFS [tpch_nested_parquet.customer c, RANDOM]
@@ -258,7 +258,7 @@ PLAN-ROOT SINK
predicates on o_lineitems: l_linenumber < 3
table stats: 150000 rows total
columns missing stats: c_orders
- hosts=3 per-host-mem=unavailable
+ hosts=3 per-host-mem=88.00MB
tuple-ids=0 row-size=254B cardinality=15000
====
# Hash-join in a subplan should work.
@@ -312,31 +312,31 @@ PLAN-ROOT SINK
| tuple-ids=1,0,2 row-size=286B cardinality=1500000
|
01:SUBPLAN
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=1,0,2 row-size=286B cardinality=1500000
|
|--06:HASH JOIN [INNER JOIN]
| | hash predicates: o1.o_orderkey = o2.o_orderkey + 2
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=0B
| | tuple-ids=1,0,2 row-size=286B cardinality=10
| |
| |--04:UNNEST [c.c_orders o2]
| | parent-subplan=01
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=0B
| | tuple-ids=2 row-size=0B cardinality=10
| |
| 05:NESTED LOOP JOIN [CROSS JOIN]
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=270B
| | tuple-ids=1,0 row-size=278B cardinality=10
| |
| |--02:SINGULAR ROW SRC
| | parent-subplan=01
-| | hosts=3 per-host-mem=unavailable
+| | hosts=3 per-host-mem=0B
| | tuple-ids=0 row-size=270B cardinality=1
| |
| 03:UNNEST [c.c_orders o1]
| parent-subplan=01
-| hosts=3 per-host-mem=unavailable
+| hosts=3 per-host-mem=0B
| tuple-ids=1 row-size=0B cardinality=10
|
00:SCAN HDFS [tpch_nested_parquet.customer c, RANDOM]
@@ -345,6 +345,6 @@ PLAN-ROOT SINK
predicates on o1: o1.o_orderkey < 5
table stats: 150000 rows total
columns missing stats: c_orders, c_orders
- hosts=3 per-host-mem=unavailable
+ hosts=3 per-host-mem=88.00MB
tuple-ids=0 row-size=270B cardinality=150000
====
[3/3] incubator-impala git commit: IMPALA-4379: Fix and test Kudu
table type checking
Posted by ta...@apache.org.
IMPALA-4379: Fix and test Kudu table type checking
Creating Kudu tables shouldn't allow types not supported by
Kudu (e.g. VARCHAR/CHAR, DECIMAL, TIMESTAMP, collection types).
The behavior is inconsistent: for some types it throws in
the catalog, for VARCHAR/CHAR these become strings. This changes
behavior so that all fail during analysis. Analysis tests
were added.
Similarly, external tables cannot contain Kudu types that
Impala doesn't support (e.g. UNIXTIME_MICROS, BINARY). Tests
were added to validate this behavior. Note that this
required upgrading the python Kudu client.
This also fixes a small corner case with ALTER TABLE:
ALTER TABLE shouldn't allow Kudu tables to change the
storage descriptor tblproperty, otherwise the table metadata
gets in an inconsistent state.
Tests were added for all of the above.
Change-Id: I475273cbbf4110db8d0f78ddf9a56abfc6221e3e
Reviewed-on: http://gerrit.cloudera.org:8080/4857
Reviewed-by: Dimitris Tsirogiannis <dt...@cloudera.com>
Tested-by: Tim Armstrong <ta...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/9b507b6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/9b507b6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/9b507b6e
Branch: refs/heads/master
Commit: 9b507b6ed6d1a1265544f129dbe75441a2f68783
Parents: 0d85723
Author: Matthew Jacobs <mj...@cloudera.com>
Authored: Wed Oct 26 19:08:00 2016 -0700
Committer: Tim Armstrong <ta...@cloudera.com>
Committed: Mon Oct 31 16:03:54 2016 +0000
----------------------------------------------------------------------
.../apache/impala/analysis/CreateTableStmt.java | 15 ++++-
.../impala/service/CatalogOpExecutor.java | 19 +++---
.../impala/service/KuduCatalogOpExecutor.java | 18 ++++--
.../java/org/apache/impala/util/KuduUtil.java | 8 +--
.../apache/impala/analysis/AnalyzeDDLTest.java | 61 ++++++++++++++++----
infra/python/deps/download_requirements | 2 +-
infra/python/deps/requirements.txt | 2 +-
.../queries/QueryTest/kudu_alter.test | 5 ++
.../queries/QueryTest/kudu_create.test | 25 --------
.../queries/QueryTest/kudu_crud.test | 9 +--
tests/common/kudu_test_suite.py | 4 +-
tests/query_test/test_kudu.py | 34 ++++++++++-
12 files changed, 136 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/fe/src/main/java/org/apache/impala/analysis/CreateTableStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/CreateTableStmt.java b/fe/src/main/java/org/apache/impala/analysis/CreateTableStmt.java
index 73173cb..b896acc 100644
--- a/fe/src/main/java/org/apache/impala/analysis/CreateTableStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/CreateTableStmt.java
@@ -20,9 +20,12 @@ package org.apache.impala.analysis;
import java.util.List;
import java.util.Map;
+import org.apache.avro.Schema;
+import org.apache.avro.SchemaParseException;
import org.apache.impala.catalog.KuduTable;
import org.apache.impala.catalog.RowFormat;
import org.apache.impala.common.AnalysisException;
+import org.apache.impala.common.ImpalaRuntimeException;
import org.apache.impala.thrift.TCreateTableParams;
import org.apache.impala.thrift.THdfsFileFormat;
import org.apache.impala.thrift.TTableName;
@@ -37,9 +40,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
-import org.apache.avro.Schema;
-import org.apache.avro.SchemaParseException;
-
/**
* Represents a CREATE TABLE statement.
*/
@@ -266,6 +266,15 @@ public class CreateTableStmt extends StatementBase {
getTblProperties().put(KuduTable.KEY_TABLE_NAME,
KuduUtil.getDefaultCreateKuduTableName(getDb(), getTbl()));
}
+ // Check column types are valid Kudu types
+ for (ColumnDef col: getColumnDefs()) {
+ try {
+ KuduUtil.fromImpalaType(col.getType());
+ } catch (ImpalaRuntimeException e) {
+ throw new AnalysisException(String.format(
+ "Cannot create table '%s': %s", getTbl(), e.getMessage()));
+ }
+ }
AnalysisUtils.throwIfNotNull(getTblProperties().get(KuduTable.KEY_KEY_COLUMNS),
String.format("PRIMARY KEY must be used instead of the table property '%s'.",
KuduTable.KEY_KEY_COLUMNS));
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
index 54493d1..f5ffb59 100644
--- a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
+++ b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
@@ -49,14 +49,6 @@ import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
import org.apache.hadoop.hive.metastore.api.StringColumnStatsData;
-import org.apache.log4j.Logger;
-import org.apache.thrift.TException;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
import org.apache.impala.analysis.FunctionName;
import org.apache.impala.analysis.TableName;
import org.apache.impala.authorization.User;
@@ -150,6 +142,14 @@ import org.apache.impala.thrift.TTruncateParams;
import org.apache.impala.thrift.TUpdateCatalogRequest;
import org.apache.impala.thrift.TUpdateCatalogResponse;
import org.apache.impala.util.HdfsCachingUtil;
+import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
/**
* Class used to execute Catalog Operations, including DDL and refresh/invalidate
@@ -2082,8 +2082,9 @@ public class CatalogOpExecutor {
tbl.getMetaStoreTable().deepCopy();
switch (params.getTarget()) {
case TBL_PROPERTY:
+ boolean isKuduTable = KuduTable.isKuduTable(msTbl);
msTbl.getParameters().putAll(properties);
- if (KuduTable.isKuduTable(msTbl)) {
+ if (isKuduTable) {
KuduCatalogOpExecutor.validateKuduTblExists(msTbl);
}
break;
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java b/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
index bd6d0fe..ad4f2a9 100644
--- a/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
+++ b/fe/src/main/java/org/apache/impala/service/KuduCatalogOpExecutor.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import com.google.common.base.Preconditions;
@@ -220,15 +221,24 @@ public class KuduCatalogOpExecutor {
}
/**
- * Validates the table properties of a Kudu table. It checks that the specified master
- * addresses point to valid Kudu masters and that the table exists.
+ * Validates the table properties of a Kudu table. It checks that the msTbl represents
+ * a Kudu table (indicated by the Kudu storage handler), that the master
+ * addresses point to valid Kudu masters, and that the table exists.
* Throws an ImpalaRuntimeException if this is not the case.
*/
public static void validateKuduTblExists(
org.apache.hadoop.hive.metastore.api.Table msTbl) throws ImpalaRuntimeException {
- String masterHosts = msTbl.getParameters().get(KuduTable.KEY_MASTER_HOSTS);
+ Map<String, String> properties = msTbl.getParameters();
+ if (!KuduTable.isKuduTable(msTbl)) {
+ throw new ImpalaRuntimeException(String.format("Table '%s' does not represent a " +
+ "Kudu table. Expected storage_handler '%s' but found '%s'",
+ msTbl.getTableName(), KuduTable.KUDU_STORAGE_HANDLER,
+ properties.get(KuduTable.KEY_STORAGE_HANDLER)));
+ }
+
+ String masterHosts = properties.get(KuduTable.KEY_MASTER_HOSTS);
Preconditions.checkState(!Strings.isNullOrEmpty(masterHosts));
- String kuduTableName = msTbl.getParameters().get(KuduTable.KEY_TABLE_NAME);
+ String kuduTableName = properties.get(KuduTable.KEY_TABLE_NAME);
Preconditions.checkState(!Strings.isNullOrEmpty(kuduTableName));
try (KuduClient kudu = new KuduClient.KuduClientBuilder(masterHosts).build()) {
kudu.tableExists(kuduTableName);
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/fe/src/main/java/org/apache/impala/util/KuduUtil.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/util/KuduUtil.java b/fe/src/main/java/org/apache/impala/util/KuduUtil.java
index a679032..6e07116 100644
--- a/fe/src/main/java/org/apache/impala/util/KuduUtil.java
+++ b/fe/src/main/java/org/apache/impala/util/KuduUtil.java
@@ -206,7 +206,7 @@ public class KuduUtil {
throws ImpalaRuntimeException {
if (!t.isScalarType()) {
throw new ImpalaRuntimeException(format(
- "Non-scalar type %s is not supported in Kudu", t.toSql()));
+ "Type %s is not supported in Kudu", t.toSql()));
}
ScalarType s = (ScalarType) t;
switch (s.getPrimitiveType()) {
@@ -215,9 +215,7 @@ public class KuduUtil {
case INT: return org.apache.kudu.Type.INT32;
case BIGINT: return org.apache.kudu.Type.INT64;
case BOOLEAN: return org.apache.kudu.Type.BOOL;
- case CHAR: return org.apache.kudu.Type.STRING;
case STRING: return org.apache.kudu.Type.STRING;
- case VARCHAR: return org.apache.kudu.Type.STRING;
case DOUBLE: return org.apache.kudu.Type.DOUBLE;
case FLOAT: return org.apache.kudu.Type.FLOAT;
/* Fall through below */
@@ -228,6 +226,8 @@ public class KuduUtil {
case DATE:
case DATETIME:
case DECIMAL:
+ case CHAR:
+ case VARCHAR:
default:
throw new ImpalaRuntimeException(format(
"Type %s is not supported in Kudu", s.toSql()));
@@ -247,7 +247,7 @@ public class KuduUtil {
case STRING: return Type.STRING;
default:
throw new ImpalaRuntimeException(String.format(
- "Kudu type %s is not supported in Impala", t));
+ "Kudu type '%s' is not supported in Impala", t.getName()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
index e79c5ab..730ca92 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
@@ -25,9 +25,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
-import junit.framework.Assert;
-
-import org.apache.impala.analysis.CreateTableStmt;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.permission.FsAction;
+import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.impala.catalog.ArrayType;
import org.apache.impala.catalog.CatalogException;
import org.apache.impala.catalog.ColumnStats;
@@ -45,20 +48,14 @@ import org.apache.impala.common.FrontendTestBase;
import org.apache.impala.common.RuntimeEnv;
import org.apache.impala.testutil.TestUtils;
import org.apache.impala.util.MetaStoreUtil;
+import org.junit.Test;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.hadoop.fs.FSDataOutputStream;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.permission.FsAction;
-import org.apache.hadoop.fs.permission.FsPermission;
-
-import org.junit.Test;
+import junit.framework.Assert;
public class AnalyzeDDLTest extends FrontendTestBase {
@@ -1352,6 +1349,29 @@ public class AnalyzeDDLTest extends FrontendTestBase {
"tblproperties('kudu.table_name'='t') as select id, int_col from " +
"functional.alltypestiny", "CREATE TABLE AS SELECT is not supported for " +
"external Kudu tables.");
+
+ // CTAS into Kudu tables with unsupported types
+ AnalysisError("create table t primary key (id) distribute by hash into 3 buckets" +
+ " stored as kudu as select id, timestamp_col from functional.alltypestiny",
+ "Cannot create table 't': Type TIMESTAMP is not supported in Kudu");
+ AnalysisError("create table t primary key (cs) distribute by hash into 3 buckets" +
+ " stored as kudu as select cs from functional.chars_tiny",
+ "Cannot create table 't': Type CHAR(5) is not supported in Kudu");
+ AnalysisError("create table t primary key (vc) distribute by hash into 3 buckets" +
+ " stored as kudu as select vc from functional.chars_tiny",
+ "Cannot create table 't': Type VARCHAR(32) is not supported in Kudu");
+ AnalysisError("create table t primary key (id) distribute by hash into 3 buckets" +
+ " stored as kudu as select id, s from functional.complextypes_fileformat",
+ "Expr 's' in select list returns a complex type 'STRUCT<f1:STRING,f2:INT>'.\n" +
+ "Only scalar types are allowed in the select list.");
+ AnalysisError("create table t primary key (id) distribute by hash into 3 buckets" +
+ " stored as kudu as select id, m from functional.complextypes_fileformat",
+ "Expr 'm' in select list returns a complex type 'MAP<STRING,BIGINT>'.\n" +
+ "Only scalar types are allowed in the select list.");
+ AnalysisError("create table t primary key (id) distribute by hash into 3 buckets" +
+ " stored as kudu as select id, a from functional.complextypes_fileformat",
+ "Expr 'a' in select list returns a complex type 'ARRAY<INT>'.\n" +
+ "Only scalar types are allowed in the select list.");
}
@Test
@@ -1832,6 +1852,25 @@ public class AnalyzeDDLTest extends FrontendTestBase {
AnalysisError("create table tab (x int primary key) " +
"partitioned by (y int) stored as kudu", "PARTITIONED BY cannot be used " +
"in Kudu tables.");
+
+ // Test unsupported Kudu types
+ List<String> unsupportedTypes = Lists.newArrayList(
+ "DECIMAL(9,0)", "TIMESTAMP", "VARCHAR(20)", "CHAR(20)",
+ "STRUCT<F1:INT,F2:STRING>", "ARRAY<INT>", "MAP<STRING,STRING>");
+ for (String t: unsupportedTypes) {
+ String expectedError = String.format(
+ "Cannot create table 'tab': Type %s is not supported in Kudu", t);
+
+ // Unsupported type is PK and partition col
+ String stmt = String.format("create table tab (x %s primary key) " +
+ "distribute by hash(x) into 3 buckets stored as kudu", t);
+ AnalysisError(stmt, expectedError);
+
+ // Unsupported type is not PK/partition col
+ stmt = String.format("create table tab (x int primary key, y %s) " +
+ "distribute by hash(x) into 3 buckets stored as kudu", t);
+ AnalysisError(stmt, expectedError);
+ }
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/infra/python/deps/download_requirements
----------------------------------------------------------------------
diff --git a/infra/python/deps/download_requirements b/infra/python/deps/download_requirements
index d586104..e068c34 100755
--- a/infra/python/deps/download_requirements
+++ b/infra/python/deps/download_requirements
@@ -29,5 +29,5 @@ PY26="$(./find_py26.py)"
"$PY26" pip_download.py virtualenv 13.1.0
# kudu-python is downloaded separately because pip install attempts to execute a
# setup.py subcommand for kudu-python that can fail even if the download succeeds.
-"$PY26" pip_download.py kudu-python 0.2.0
+"$PY26" pip_download.py kudu-python 0.3.0
popd
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/infra/python/deps/requirements.txt
----------------------------------------------------------------------
diff --git a/infra/python/deps/requirements.txt b/infra/python/deps/requirements.txt
index 2ba0853..dcbb91c 100644
--- a/infra/python/deps/requirements.txt
+++ b/infra/python/deps/requirements.txt
@@ -82,7 +82,7 @@ texttable == 0.8.3
# functional and determines the expected kudu-python version. The version must be listed
# in the format below including # and spacing. Keep this formatting! The kudu-python
# version in download_requirements must be kept in sync with this version.
-# kudu-python==0.2.0
+# kudu-python==0.3.0
Cython == 0.23.4
numpy == 1.10.4
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test b/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test
index e6814e1..ad49c59 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_alter.test
@@ -40,3 +40,8 @@ select count(*) from simple_new;
---- TYPES
BIGINT
====
+---- QUERY
+alter table simple_new set tblproperties ('storage_handler'='foo')
+---- CATCH
+ImpalaRuntimeException: Table 'simple_new' does not represent a Kudu table. Expected storage_handler 'com.cloudera.kudu.hive.KuduStorageHandler' but found 'foo'
+====
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
index 6950fb6..b2c56c4 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_create.test
@@ -1,30 +1,5 @@
====
---- QUERY
-# This test file contains several cases for what basically amount to analysis errors,
-# but they only show up at runtime. These cases correspond to constraints enforced by
-# the Kudu storage engine.
-#
-# Incompatible column types in CTAS.
-create table t primary key (id) distribute by hash (id) into 3 buckets
-stored as kudu
-as select * from functional.alltypestiny
----- CATCH
-ImpalaRuntimeException: Type TIMESTAMP is not supported in Kudu
-====
----- QUERY
-create table t primary key (id) distribute by hash (id) into 3 buckets
-stored as kudu
-as select c1 as id from functional.decimal_tiny
----- CATCH
-ImpalaRuntimeException: Type DECIMAL(10,4) is not supported in Kudu
-====
----- QUERY
-create table t (a int, b array<string>, primary key(a)) distribute by hash (a)
-into 3 buckets stored as kudu
----- CATCH
-ImpalaRuntimeException: Non-scalar type ARRAY<STRING> is not supported in Kudu
-====
----- QUERY
create table t primary key (id) distribute by hash (id) into 3 buckets
stored as kudu
as select id, int_col from functional.alltypestiny;
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/testdata/workloads/functional-query/queries/QueryTest/kudu_crud.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/kudu_crud.test b/testdata/workloads/functional-query/queries/QueryTest/kudu_crud.test
index 18281e3..a2f9599 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/kudu_crud.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/kudu_crud.test
@@ -18,15 +18,15 @@ Couldn't resolve this master's address bogus.host.name:7051
====
---- QUERY
create table tdata
- (id int primary key, name string, valf float, vali bigint, valv varchar(20), valb boolean)
+ (id int primary key, name string, valf float, vali bigint, valv string, valb boolean)
DISTRIBUTE BY RANGE SPLIT ROWS ((10), (30)) STORED AS KUDU
---- RESULTS
====
---- QUERY
insert into tdata values
(1, "martin", 1.0, 232232323, cast('a' as VARCHAR(20)), true),
-(2, "david", cast(1.0 as float), 99398493939, cast('b' as VARCHAR(20)), false),
-(3, "todd", cast(1.0 as float), 993393939, cast('c' as VARCHAR(20)), true)
+(2, "david", cast(1.0 as float), 99398493939, cast('b' as CHAR(1)), false),
+(3, "todd", cast(1.0 as float), 993393939, "c", true)
---- RESULTS
: 3
---- RUNTIME_PROFILE
@@ -50,7 +50,8 @@ INT,STRING,FLOAT,BIGINT,STRING,BOOLEAN
====
====
---- QUERY
-# Try updating a varchar col. with a value that is bigger than it's size (truncated).
+# Try updating a string col where casting a value that is bigger than the varchar in the
+# cast. The value gets truncated and stored to the string col.
update tdata set valv=cast('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' as VARCHAR(20)) where id = 1
---- RESULTS
---- RUNTIME_PROFILE
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/tests/common/kudu_test_suite.py
----------------------------------------------------------------------
diff --git a/tests/common/kudu_test_suite.py b/tests/common/kudu_test_suite.py
index 7a93c12..ff37c99 100644
--- a/tests/common/kudu_test_suite.py
+++ b/tests/common/kudu_test_suite.py
@@ -28,7 +28,9 @@ from kudu.schema import (
INT64,
INT8,
SchemaBuilder,
- STRING)
+ STRING,
+ BINARY,
+ UNIXTIME_MICROS)
from kudu.client import Partitioning
from random import choice, sample
from string import ascii_lowercase, digits
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9b507b6e/tests/query_test/test_kudu.py
----------------------------------------------------------------------
diff --git a/tests/query_test/test_kudu.py b/tests/query_test/test_kudu.py
index 7ccb8a2..56e6964 100644
--- a/tests/query_test/test_kudu.py
+++ b/tests/query_test/test_kudu.py
@@ -23,7 +23,9 @@ from kudu.schema import (
INT32,
INT64,
INT8,
- STRING)
+ STRING,
+ BINARY,
+ UNIXTIME_MICROS)
import logging
import pytest
import textwrap
@@ -79,8 +81,6 @@ class TestCreateExternalTable(KuduTestSuite):
def test_col_types(self, cursor, kudu_client):
"""Check that a table can be created using all available column types."""
- # TODO: The python Kudu client doesn't yet support TIMESTAMP or BYTE[], those should
- # be tested for graceful failure.
kudu_types = [STRING, BOOL, DOUBLE, FLOAT, INT16, INT32, INT64, INT8]
with self.temp_kudu_table(kudu_client, kudu_types) as kudu_table:
impala_table_name = self.get_kudu_table_base_name(kudu_table.name)
@@ -96,6 +96,34 @@ class TestCreateExternalTable(KuduTestSuite):
assert col_type.upper() == \
self.kudu_col_type_to_impala_col_type(kudu_col.type.type)
+ def test_unsupported_binary_col(self, cursor, kudu_client):
+ """Check that external tables with BINARY columns fail gracefully.
+ """
+ with self.temp_kudu_table(kudu_client, [INT32, BINARY]) as kudu_table:
+ impala_table_name = self.random_table_name()
+ try:
+ cursor.execute("""
+ CREATE EXTERNAL TABLE %s
+ STORED AS KUDU
+ TBLPROPERTIES('kudu.table_name' = '%s')""" % (impala_table_name,
+ kudu_table.name))
+ except Exception as e:
+ assert "Kudu type 'binary' is not supported in Impala" in str(e)
+
+ def test_unsupported_unixtime_col(self, cursor, kudu_client):
+ """Check that external tables with UNIXTIME_MICROS columns fail gracefully.
+ """
+ with self.temp_kudu_table(kudu_client, [INT32, UNIXTIME_MICROS]) as kudu_table:
+ impala_table_name = self.random_table_name()
+ try:
+ cursor.execute("""
+ CREATE EXTERNAL TABLE %s
+ STORED AS KUDU
+ TBLPROPERTIES('kudu.table_name' = '%s')""" % (impala_table_name,
+ kudu_table.name))
+ except Exception as e:
+ assert "Kudu type 'unixtime_micros' is not supported in Impala" in str(e)
+
def test_drop_external_table(self, cursor, kudu_client):
"""Check that dropping an external table only affects the catalog and does not delete
the table in Kudu.
[2/3] incubator-impala git commit: IMPALA-4314: Standardize on
MT-related data structures
Posted by ta...@apache.org.
IMPALA-4314: Standardize on MT-related data structures
This removes the data structures that were "superceded" in
IMPALA-3903 and changes all control flow to utilize the
new data structures. The new data structures are renamed
to remove the "Mt" prefix.
Change-Id: I465d0e15e2cf17cafe4c747d34c8f595d3645151
Reviewed-on: http://gerrit.cloudera.org:8080/4853
Reviewed-by: Marcel Kornacker <ma...@cloudera.com>
Tested-by: Tim Armstrong <ta...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/0d857237
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/0d857237
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/0d857237
Branch: refs/heads/master
Commit: 0d857237a8d5231caf9af4c30d4134b151cd1e0d
Parents: 29faca5
Author: Marcel Kornacker <ma...@cloudera.com>
Authored: Tue Oct 4 20:40:18 2016 -0400
Committer: Tim Armstrong <ta...@cloudera.com>
Committed: Mon Oct 31 16:03:32 2016 +0000
----------------------------------------------------------------------
be/src/benchmarks/expr-benchmark.cc | 2 +-
be/src/runtime/coordinator.cc | 415 ++++--------------
be/src/runtime/coordinator.h | 71 +---
be/src/scheduling/query-schedule.cc | 175 ++++----
be/src/scheduling/query-schedule.h | 77 ++--
be/src/scheduling/simple-scheduler-test-util.cc | 10 +-
be/src/scheduling/simple-scheduler-test-util.h | 14 +-
be/src/scheduling/simple-scheduler.cc | 417 +++++++------------
be/src/scheduling/simple-scheduler.h | 81 ++--
be/src/service/impala-http-handler.cc | 7 +-
be/src/service/impala-server.cc | 6 +-
be/src/service/query-exec-state.cc | 8 +-
common/thrift/Frontend.thrift | 50 +--
common/thrift/Planner.thrift | 4 +-
.../impala/planner/DataSourceScanNode.java | 4 +-
.../apache/impala/planner/HBaseScanNode.java | 6 +-
.../org/apache/impala/planner/HdfsScanNode.java | 6 +-
.../org/apache/impala/planner/KuduScanNode.java | 4 +-
.../java/org/apache/impala/planner/Planner.java | 4 +-
.../org/apache/impala/planner/ScanNode.java | 6 +-
.../org/apache/impala/service/Frontend.java | 187 ++-------
.../apache/impala/planner/PlannerTestBase.java | 187 +++++----
.../queries/PlannerTest/mt-dop-validation.test | 50 +--
23 files changed, 627 insertions(+), 1164 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/benchmarks/expr-benchmark.cc
----------------------------------------------------------------------
diff --git a/be/src/benchmarks/expr-benchmark.cc b/be/src/benchmarks/expr-benchmark.cc
index b95e6d7..444df3a 100644
--- a/be/src/benchmarks/expr-benchmark.cc
+++ b/be/src/benchmarks/expr-benchmark.cc
@@ -111,7 +111,7 @@ MemTracker tracker;
// constant query
static Status PrepareSelectList(const TExecRequest& request, ExprContext** ctx) {
const TQueryExecRequest& query_request = request.query_exec_request;
- vector<TExpr> texprs = query_request.fragments[0].output_exprs;
+ vector<TExpr> texprs = query_request.plan_exec_info[0].fragments[0].output_exprs;
DCHECK_EQ(texprs.size(), 1);
RETURN_IF_ERROR(Expr::CreateExprTree(&pool, texprs[0], ctx));
RETURN_IF_ERROR((*ctx)->Prepare(NULL, RowDescriptor(), &tracker));
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/runtime/coordinator.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/coordinator.cc b/be/src/runtime/coordinator.cc
index 7df0bf0..f719e98 100644
--- a/be/src/runtime/coordinator.cc
+++ b/be/src/runtime/coordinator.cc
@@ -125,39 +125,17 @@ struct DebugOptions {
/// - updates through UpdateFragmentExecStatus()
class Coordinator::FragmentInstanceState {
public:
- // TODO-MT: remove this c'tor
- FragmentInstanceState(FragmentIdx fragment_idx, const FragmentExecParams& params,
- int per_fragment_instance_idx, ObjectPool* obj_pool)
- : fragment_instance_id_(params.instance_ids[per_fragment_instance_idx]),
- fragment_idx_(fragment_idx),
- per_fragment_instance_idx_(per_fragment_instance_idx),
- impalad_address_(params.hosts[per_fragment_instance_idx]),
- total_split_size_(0),
- rpc_sent_(false),
- done_(false),
- profile_created_(false),
- profile_(NULL),
- total_ranges_complete_(0),
- rpc_latency_(0) {
- const string& profile_name = Substitute("Instance $0 (host=$1)",
- PrintId(fragment_instance_id_), lexical_cast<string>(impalad_address_));
- profile_ = obj_pool->Add(new RuntimeProfile(obj_pool, profile_name));
- }
-
FragmentInstanceState(const FInstanceExecParams& params, ObjectPool* obj_pool)
- : fragment_instance_id_(params.instance_id),
- fragment_idx_(params.fragment().idx),
- per_fragment_instance_idx_(params.per_fragment_instance_idx),
- impalad_address_(params.host),
+ : exec_params_(params),
total_split_size_(0),
+ profile_(nullptr),
+ total_ranges_complete_(0),
+ rpc_latency_(0),
rpc_sent_(false),
done_(false),
- profile_created_(false),
- profile_(NULL),
- total_ranges_complete_(0),
- rpc_latency_(0) {
+ profile_created_(false) {
const string& profile_name = Substitute("Instance $0 (host=$1)",
- PrintId(fragment_instance_id_), lexical_cast<string>(impalad_address_));
+ PrintId(params.instance_id), lexical_cast<string>(params.host));
profile_ = obj_pool->Add(new RuntimeProfile(obj_pool, profile_name));
}
@@ -182,13 +160,13 @@ class Coordinator::FragmentInstanceState {
int64_t UpdateNumScanRangesCompleted();
// The following getters do not require lock() to be held.
- const TUniqueId& fragment_instance_id() const { return fragment_instance_id_; }
- FragmentIdx fragment_idx() const { return fragment_idx_; }
+ const TUniqueId& fragment_instance_id() const { return exec_params_.instance_id; }
+ FragmentIdx fragment_idx() const { return exec_params_.fragment().idx; }
MonotonicStopWatch* stopwatch() { return &stopwatch_; }
- const TNetworkAddress& impalad_address() const { return impalad_address_; }
+ const TNetworkAddress& impalad_address() const { return exec_params_.host; }
int64_t total_split_size() const { return total_split_size_; }
bool done() const { return done_; }
- int per_fragment_instance_idx() const { return per_fragment_instance_idx_; }
+ int per_fragment_instance_idx() const { return exec_params_.per_fragment_instance_idx; }
bool rpc_sent() const { return rpc_sent_; }
int64_t rpc_latency() const { return rpc_latency_; }
@@ -218,22 +196,11 @@ class Coordinator::FragmentInstanceState {
}
private:
- /// The unique ID of this instance of this fragment (there may be many instance of the
- /// same fragment, but this ID uniquely identifies this FragmentInstanceState).
- TUniqueId fragment_instance_id_;
-
- // Same as TPlanFragment.idx
- FragmentIdx fragment_idx_;
-
- /// range: 0..<# instances of this fragment>-1
- int per_fragment_instance_idx_;
+ const FInstanceExecParams& exec_params_;
/// Wall clock timer for this fragment.
MonotonicStopWatch stopwatch_;
- /// Address of ImpalaInternalService this fragment is running on.
- const TNetworkAddress impalad_address_;
-
/// Summed across all splits; in bytes.
int64_t total_split_size_;
@@ -246,16 +213,6 @@ class Coordinator::FragmentInstanceState {
/// been initiated; either way, execution must not be cancelled.
Status status_;
- /// If true, ExecPlanFragment() rpc has been sent - even if it was not determined to be
- /// successful.
- bool rpc_sent_;
-
- /// If true, execution terminated; do not cancel in that case.
- bool done_;
-
- /// True after the first call to profile->Update()
- bool profile_created_;
-
/// Owned by coordinator object pool provided in the c'tor
RuntimeProfile* profile_;
@@ -270,6 +227,32 @@ class Coordinator::FragmentInstanceState {
/// Time, in ms, that it took to execute the ExecRemoteFragment() RPC.
int64_t rpc_latency_;
+
+ /// If true, ExecPlanFragment() rpc has been sent - even if it was not determined to be
+ /// successful.
+ bool rpc_sent_;
+
+ /// If true, execution terminated; do not cancel in that case.
+ bool done_;
+
+ /// True after the first call to profile->Update()
+ bool profile_created_;
+};
+
+/// Represents a runtime filter target.
+struct Coordinator::FilterTarget {
+ TPlanNodeId node_id;
+ bool is_local;
+ bool is_bound_by_partition_columns;
+
+ // indices into fragment_instance_states_
+ unordered_set<int> fragment_instance_state_idxs;
+
+ FilterTarget(const TRuntimeFilterTargetDesc& tFilterTarget) {
+ node_id = tFilterTarget.node_id;
+ is_bound_by_partition_columns = tFilterTarget.is_bound_by_partition_columns;
+ is_local = tFilterTarget.is_local_target;
+ }
};
@@ -410,7 +393,6 @@ TExecNodePhase::type GetExecNodePhase(const string& key) {
return TExecNodePhase::INVALID;
}
-// TODO: templatize this
TDebugAction::type GetDebugAction(const string& key) {
map<int, const char*>::const_iterator entry =
_TDebugAction_VALUES_TO_NAMES.begin();
@@ -451,7 +433,7 @@ static void ProcessQueryOptions(
Status Coordinator::Exec() {
const TQueryExecRequest& request = schedule_.request();
- DCHECK(request.fragments.size() > 0 || request.mt_plan_exec_info.size() > 0);
+ DCHECK(request.plan_exec_info.size() > 0);
needs_finalization_ = request.__isset.finalize_params;
if (needs_finalization_) finalize_params_ = request.finalize_params;
@@ -474,6 +456,10 @@ Status Coordinator::Exec() {
const string& str = Substitute("Query $0", PrintId(query_id_));
progress_.Init(str, schedule_.num_scan_ranges());
+ // runtime filters not yet supported for mt execution
+ bool is_mt_execution = request.query_ctx.request.query_options.mt_dop > 0;
+ if (is_mt_execution) filter_mode_ = TRuntimeFilterMode::OFF;
+
// to keep things simple, make async Cancel() calls wait until plan fragment
// execution has been initiated, otherwise we might try to cancel fragment
// execution at Impala daemons where it hasn't even started
@@ -494,16 +480,9 @@ Status Coordinator::Exec() {
filter_mem_tracker_.reset(
new MemTracker(-1, "Runtime Filter (Coordinator)", query_mem_tracker(), false));
- // Initialize the execution profile structures.
- bool is_mt_execution = request.query_ctx.request.query_options.mt_dop > 0;
- if (is_mt_execution) {
- MtInitExecProfiles();
- MtInitExecSummary();
- MtStartFInstances();
- } else {
- InitExecProfile(request);
- StartFragments();
- }
+ InitExecProfiles();
+ InitExecSummary();
+ StartFInstances();
// In the error case, it's safe to return and not to get root_sink_ here to close - if
// there was an error, but the coordinator fragment was successfully started, it should
@@ -543,13 +522,16 @@ Status Coordinator::Exec() {
return Status::OK();
}
-void Coordinator::UpdateFilterRoutingTable(const vector<TPlanNode>& plan_nodes,
- int num_hosts, int start_fragment_instance_state_idx) {
+void Coordinator::UpdateFilterRoutingTable(const FragmentExecParams& fragment_params) {
+ DCHECK(schedule_.request().query_ctx.request.query_options.mt_dop == 0);
+ int num_hosts = fragment_params.instance_exec_params.size();
+ DCHECK_GT(num_hosts, 0);
DCHECK_NE(filter_mode_, TRuntimeFilterMode::OFF)
<< "UpdateFilterRoutingTable() called although runtime filters are disabled";
DCHECK(!filter_routing_table_complete_)
<< "UpdateFilterRoutingTable() called after setting filter_routing_table_complete_";
- for (const TPlanNode& plan_node: plan_nodes) {
+
+ for (const TPlanNode& plan_node: fragment_params.fragment.plan.nodes) {
if (!plan_node.__isset.runtime_filters) continue;
for (const TRuntimeFilterDesc& filter: plan_node.runtime_filters) {
if (filter_mode_ == TRuntimeFilterMode::LOCAL && !filter.has_local_targets) {
@@ -564,10 +546,7 @@ void Coordinator::UpdateFilterRoutingTable(const vector<TPlanNode>& plan_nodes,
int pending_count = filter.is_broadcast_join ?
(filter.has_remote_targets ? 1 : 0) : num_hosts;
f->set_pending_count(pending_count);
- vector<int> src_idxs;
- for (int i = 0; i < num_hosts; ++i) {
- src_idxs.push_back(start_fragment_instance_state_idx + i);
- }
+ vector<int> src_idxs = fragment_params.GetInstanceIdxs();
// If this is a broadcast join with only non-local targets, build and publish it
// on MAX_BROADCAST_FILTER_PRODUCERS instances. If this is not a broadcast join
@@ -586,11 +565,9 @@ void Coordinator::UpdateFilterRoutingTable(const vector<TPlanNode>& plan_nodes,
if (filter_mode_ == TRuntimeFilterMode::LOCAL && !tFilterTarget.is_local_target) {
continue;
}
+ vector<int> idxs = fragment_params.GetInstanceIdxs();
FilterTarget target(tFilterTarget);
- for (int i = 0; i < num_hosts; ++i) {
- target.fragment_instance_state_idxs.insert(
- start_fragment_instance_state_idx + i);
- }
+ target.fragment_instance_state_idxs.insert(idxs.begin(), idxs.end());
f->targets()->push_back(target);
} else {
DCHECK(false) << "Unexpected plan node with runtime filters: "
@@ -600,7 +577,7 @@ void Coordinator::UpdateFilterRoutingTable(const vector<TPlanNode>& plan_nodes,
}
}
-void Coordinator::StartFragments() {
+void Coordinator::StartFInstances() {
int num_fragment_instances = schedule_.GetNumFragmentInstances();
DCHECK_GT(num_fragment_instances, 0);
@@ -615,78 +592,28 @@ void Coordinator::StartFragments() {
VLOG_QUERY << "starting " << num_fragment_instances << " fragment instances for query "
<< query_id_;
query_events_->MarkEvent(
- Substitute("Ready to start $0 fragments", num_fragment_instances));
+ Substitute("Ready to start $0 fragment instances", num_fragment_instances));
+
+ // TODO-MT: populate the runtime filter routing table
+ // This requires local aggregation of filters prior to sending
+ // for broadcast joins in order to avoid more complicated merge logic here.
- int instance_state_idx = 0;
if (filter_mode_ != TRuntimeFilterMode::OFF) {
+ DCHECK_EQ(request.plan_exec_info.size(), 1);
// Populate the runtime filter routing table. This should happen before starting the
// fragment instances. This code anticipates the indices of the instance states
// created later on in ExecRemoteFragment()
- for (int fragment_idx = 0; fragment_idx < request.fragments.size(); ++fragment_idx) {
- const FragmentExecParams& params = schedule_.exec_params()[fragment_idx];
- int num_hosts = params.hosts.size();
- DCHECK_GT(num_hosts, 0);
- UpdateFilterRoutingTable(request.fragments[fragment_idx].plan.nodes, num_hosts,
- instance_state_idx);
- instance_state_idx += num_hosts;
+ for (const FragmentExecParams& fragment_params: schedule_.fragment_exec_params()) {
+ UpdateFilterRoutingTable(fragment_params);
}
MarkFilterRoutingTableComplete();
}
int num_instances = 0;
- // Start one fragment instance per fragment per host (number of hosts running each
- // fragment may not be constant).
- for (int fragment_idx = 0; fragment_idx < request.fragments.size(); ++fragment_idx) {
- const FragmentExecParams& params = schedule_.exec_params()[fragment_idx];
- int num_hosts = params.hosts.size();
- DCHECK_GT(num_hosts, 0);
- fragment_profiles_[fragment_idx].num_instances = num_hosts;
- // Start one fragment instance for every fragment_instance required by the
- // schedule. Each fragment instance is assigned a unique ID, numbered from 0, with
- // instances for fragment ID 0 being assigned IDs [0 .. num_hosts(fragment_id_0)] and
- // so on.
- for (int fragment_instance_idx = 0; fragment_instance_idx < num_hosts;
- ++fragment_instance_idx, ++num_instances) {
- DebugOptions* fragment_instance_debug_options =
- debug_options.IsApplicable(instance_state_idx) ? &debug_options : NULL;
- exec_env_->fragment_exec_thread_pool()->Offer(
- std::bind(&Coordinator::ExecRemoteFragment, this, std::cref(params),
- std::cref(request.fragments[fragment_idx]), fragment_instance_debug_options,
- fragment_instance_idx));
- }
- }
- exec_complete_barrier_->Wait();
- query_events_->MarkEvent(
- Substitute("All $0 fragments instances started", num_instances));
-}
-
-void Coordinator::MtStartFInstances() {
- int num_fragment_instances = schedule_.GetNumFragmentInstances();
- DCHECK_GT(num_fragment_instances, 0);
-
- fragment_instance_states_.resize(num_fragment_instances);
- exec_complete_barrier_.reset(new CountingBarrier(num_fragment_instances));
- num_remaining_fragment_instances_ = num_fragment_instances;
-
- DebugOptions debug_options;
- ProcessQueryOptions(schedule_.query_options(), &debug_options);
- const TQueryExecRequest& request = schedule_.request();
-
- VLOG_QUERY << "starting " << num_fragment_instances << " fragment instances for query "
- << query_id_;
- query_events_->MarkEvent(
- Substitute("Ready to start $0 fragment instances", num_fragment_instances));
-
- // TODO: populate the runtime filter routing table
- // this requires local aggregation of filters prior to sending
- // for broadcast joins in order to avoid more complicated merge logic here
-
- int num_instances = 0;
- for (const MtFragmentExecParams& fragment_params: schedule_.mt_fragment_exec_params()) {
- for (int i = 0; i < fragment_params.instance_exec_params.size();
- ++i, ++num_instances) {
- const FInstanceExecParams& instance_params =
- fragment_params.instance_exec_params[i];
+ for (const FragmentExecParams& fragment_params: schedule_.fragment_exec_params()) {
+ num_instances += fragment_params.instance_exec_params.size();
+ for (const FInstanceExecParams& instance_params:
+ fragment_params.instance_exec_params) {
FragmentInstanceState* exec_state = obj_pool()->Add(
new FragmentInstanceState(instance_params, obj_pool()));
int instance_state_idx = GetInstanceIdx(instance_params.instance_id);
@@ -695,7 +622,7 @@ void Coordinator::MtStartFInstances() {
DebugOptions* instance_debug_options =
debug_options.IsApplicable(instance_state_idx) ? &debug_options : NULL;
exec_env_->fragment_exec_thread_pool()->Offer(
- std::bind(&Coordinator::MtExecRemoteFInstance,
+ std::bind(&Coordinator::ExecRemoteFInstance,
this, std::cref(instance_params), instance_debug_options));
}
}
@@ -1243,79 +1170,12 @@ void Coordinator::PrintFragmentInstanceInfo() {
}
}
-void Coordinator::InitExecProfile(const TQueryExecRequest& request) {
- // Initialize the structure to collect execution summary of every plan node.
- fragment_profiles_.resize(request.fragments.size());
- exec_summary_.__isset.nodes = true;
- for (int i = 0; i < request.fragments.size(); ++i) {
- if (!request.fragments[i].__isset.plan) continue;
- const TPlan& plan = request.fragments[i].plan;
- int fragment_first_node_idx = exec_summary_.nodes.size();
-
- for (int j = 0; j < plan.nodes.size(); ++j) {
- TPlanNodeExecSummary node;
- node.node_id = plan.nodes[j].node_id;
- node.fragment_idx = i;
- node.label = plan.nodes[j].label;
- node.__set_label_detail(plan.nodes[j].label_detail);
- node.num_children = plan.nodes[j].num_children;
-
- if (plan.nodes[j].__isset.estimated_stats) {
- node.__set_estimated_stats(plan.nodes[j].estimated_stats);
- }
-
- plan_node_id_to_summary_map_[plan.nodes[j].node_id] = exec_summary_.nodes.size();
- exec_summary_.nodes.push_back(node);
- }
-
- if (request.fragments[i].__isset.output_sink &&
- request.fragments[i].output_sink.type == TDataSinkType::DATA_STREAM_SINK) {
- const TDataStreamSink& sink = request.fragments[i].output_sink.stream_sink;
- int exch_idx = plan_node_id_to_summary_map_[sink.dest_node_id];
- if (sink.output_partition.type == TPartitionType::UNPARTITIONED) {
- exec_summary_.nodes[exch_idx].__set_is_broadcast(true);
- }
- exec_summary_.__isset.exch_to_sender_map = true;
- exec_summary_.exch_to_sender_map[exch_idx] = fragment_first_node_idx;
- }
- }
-
- // Initialize the runtime profile structure. This adds the per fragment average
- // profiles followed by the per fragment instance profiles.
- for (int i = 0; i < request.fragments.size(); ++i) {
- // Insert the avg profiles in ascending fragment number order. If there is a
- // coordinator fragment, it's been placed in fragment_profiles_[0].averaged_profile,
- // ensuring that this code will put the first averaged profile immediately after
- // it. If there is no coordinator fragment, the first averaged profile will be
- // inserted as the first child of query_profile_, and then all other averaged
- // fragments will follow.
- bool is_coordinator_fragment = (i == 0 && schedule_.GetCoordFragment() != nullptr);
- string profile_name =
- Substitute(is_coordinator_fragment ? "Coordinator Fragment $0" : "Fragment $0",
- request.fragments[i].display_name);
- fragment_profiles_[i].root_profile =
- obj_pool()->Add(new RuntimeProfile(obj_pool(), profile_name));
- if (is_coordinator_fragment) {
- fragment_profiles_[i].averaged_profile = nullptr;
- } else {
- fragment_profiles_[i].averaged_profile = obj_pool()->Add(new RuntimeProfile(
- obj_pool(),
- Substitute("Averaged Fragment $0", request.fragments[i].display_name), true));
- query_profile_->AddChild(fragment_profiles_[i].averaged_profile, true,
- (i > 0) ? fragment_profiles_[i - 1].averaged_profile : NULL);
- }
- // Note: we don't start the wall timer here for the fragment
- // profile; it's uninteresting and misleading.
- query_profile_->AddChild(fragment_profiles_[i].root_profile);
- }
-}
-
-void Coordinator::MtInitExecSummary() {
+void Coordinator::InitExecSummary() {
const TQueryExecRequest& request = schedule_.request();
// init exec_summary_.{nodes, exch_to_sender_map}
exec_summary_.__isset.nodes = true;
DCHECK(exec_summary_.nodes.empty());
- for (const TPlanExecInfo& plan_exec_info: request.mt_plan_exec_info) {
+ for (const TPlanExecInfo& plan_exec_info: request.plan_exec_info) {
for (const TPlanFragment& fragment: plan_exec_info.fragments) {
if (!fragment.__isset.plan) continue;
@@ -1354,7 +1214,7 @@ void Coordinator::MtInitExecSummary() {
}
}
-void Coordinator::MtInitExecProfiles() {
+void Coordinator::InitExecProfiles() {
const TQueryExecRequest& request = schedule_.request();
vector<const TPlanFragment*> fragments;
schedule_.GetTPlanFragments(&fragments);
@@ -1370,6 +1230,7 @@ void Coordinator::MtInitExecProfiles() {
PerFragmentProfileData* data = &fragment_profiles_[fragment->idx];
data->num_instances =
schedule_.GetFragmentExecParams(fragment->idx).instance_exec_params.size();
+ // TODO-MT: stop special-casing the coordinator fragment
if (fragment != coord_fragment) {
data->averaged_profile = obj_pool()->Add(new RuntimeProfile(
obj_pool(), Substitute("Averaged Fragment $0", fragment->display_name), true));
@@ -1383,7 +1244,6 @@ void Coordinator::MtInitExecProfiles() {
}
}
-
void Coordinator::CollectScanNodeCounters(RuntimeProfile* profile,
FragmentInstanceCounters* counters) {
vector<RuntimeProfile*> children;
@@ -1407,11 +1267,11 @@ void Coordinator::CollectScanNodeCounters(RuntimeProfile* profile,
}
}
-void Coordinator::MtExecRemoteFInstance(
+void Coordinator::ExecRemoteFInstance(
const FInstanceExecParams& exec_params, const DebugOptions* debug_options) {
NotifyBarrierOnExit notifier(exec_complete_barrier_.get());
TExecPlanFragmentParams rpc_params;
- MtSetExecPlanFragmentParams(exec_params, &rpc_params);
+ SetExecPlanFragmentParams(exec_params, &rpc_params);
if (debug_options != NULL) {
rpc_params.fragment_instance_ctx.__set_debug_node_id(debug_options->node_id);
rpc_params.fragment_instance_ctx.__set_debug_action(debug_options->action);
@@ -1467,70 +1327,6 @@ void Coordinator::MtExecRemoteFInstance(
<< " instance_id=" << PrintId(exec_state->fragment_instance_id());
}
-void Coordinator::ExecRemoteFragment(const FragmentExecParams& fragment_exec_params,
- const TPlanFragment& plan_fragment, DebugOptions* debug_options,
- int fragment_instance_idx) {
- NotifyBarrierOnExit notifier(exec_complete_barrier_.get());
- TExecPlanFragmentParams rpc_params;
- SetExecPlanFragmentParams(
- plan_fragment, fragment_exec_params, fragment_instance_idx, &rpc_params);
- if (debug_options != NULL) {
- rpc_params.fragment_instance_ctx.__set_debug_node_id(debug_options->node_id);
- rpc_params.fragment_instance_ctx.__set_debug_action(debug_options->action);
- rpc_params.fragment_instance_ctx.__set_debug_phase(debug_options->phase);
- }
- FragmentInstanceState* exec_state = obj_pool()->Add(
- new FragmentInstanceState(
- plan_fragment.idx, fragment_exec_params, fragment_instance_idx, obj_pool()));
- exec_state->ComputeTotalSplitSize(
- rpc_params.fragment_instance_ctx.per_node_scan_ranges);
- int instance_state_idx = GetInstanceIdx(exec_state->fragment_instance_id());
- fragment_instance_states_[instance_state_idx] = exec_state;
- VLOG_FILE << "making rpc: ExecPlanFragment"
- << " instance_id=" << PrintId(exec_state->fragment_instance_id())
- << " host=" << exec_state->impalad_address();
-
- int64_t start = MonotonicMillis();
-
- Status client_connect_status;
- ImpalaBackendConnection backend_client(exec_env_->impalad_client_cache(),
- exec_state->impalad_address(), &client_connect_status);
- if (!client_connect_status.ok()) {
- exec_state->SetInitialStatus(client_connect_status, true);
- return;
- }
-
- TExecPlanFragmentResult thrift_result;
- Status rpc_status = backend_client.DoRpc(&ImpalaBackendClient::ExecPlanFragment,
- rpc_params, &thrift_result);
-
- exec_state->set_rpc_latency(MonotonicMillis() - start);
-
- const string ERR_TEMPLATE = "ExecPlanRequest rpc instance_id=$0 failed: $1";
-
- if (!rpc_status.ok()) {
- const string& err_msg =
- Substitute(ERR_TEMPLATE, PrintId(exec_state->fragment_instance_id()),
- rpc_status.msg().msg());
- VLOG_QUERY << err_msg;
- exec_state->SetInitialStatus(Status(err_msg), true);
- return;
- }
-
- Status exec_plan_status = Status(thrift_result.status);
- if (!exec_plan_status.ok()) {
- const string& err_msg =
- Substitute(ERR_TEMPLATE, PrintId(exec_state->fragment_instance_id()),
- exec_plan_status.msg().GetFullMessageDetails());
- VLOG_QUERY << err_msg;
- exec_state->SetInitialStatus(Status(err_msg), true);
- return;
- }
-
- exec_state->SetInitialStatus(Status::OK(), true);
- return;
-}
-
void Coordinator::Cancel(const Status* cause) {
lock_guard<mutex> l(lock_);
// if the query status indicates an error, cancellation has already been initiated
@@ -1834,14 +1630,6 @@ void Coordinator::UpdateExecSummary(const FragmentInstanceState& instance_state)
TPlanNodeExecSummary& exec_summary =
exec_summary_.nodes[plan_node_id_to_summary_map_[node_id]];
- if (exec_summary.exec_stats.empty()) {
- // First time, make an exec_stats for each instance this plan node is running on.
- // TODO-MT: remove this and initialize all runtime state prior to starting
- // instances
- DCHECK_LT(instance_state.fragment_idx(), fragment_profiles_.size());
- exec_summary.exec_stats.resize(
- fragment_profiles_[instance_state.fragment_idx()].num_instances);
- }
DCHECK_LT(instance_state.per_fragment_instance_idx(), exec_summary.exec_stats.size());
DCHECK_EQ(fragment_profiles_[instance_state.fragment_idx()].num_instances,
exec_summary.exec_stats.size());
@@ -1956,7 +1744,7 @@ string Coordinator::GetErrorLog() {
return PrintErrorMapToString(merged);
}
-void Coordinator::MtSetExecPlanFragmentParams(
+void Coordinator::SetExecPlanFragmentParams(
const FInstanceExecParams& params, TExecPlanFragmentParams* rpc_params) {
rpc_params->__set_protocol_version(ImpalaInternalServiceVersion::V1);
rpc_params->__set_query_ctx(query_ctx_);
@@ -1965,35 +1753,12 @@ void Coordinator::MtSetExecPlanFragmentParams(
TPlanFragmentInstanceCtx fragment_instance_ctx;
fragment_ctx.__set_fragment(params.fragment());
- // TODO: Remove filters that weren't selected during filter routing table construction.
SetExecPlanDescriptorTable(params.fragment(), rpc_params);
- fragment_instance_ctx.__set_request_pool(schedule_.request_pool());
- fragment_instance_ctx.__set_per_node_scan_ranges(params.per_node_scan_ranges);
- fragment_instance_ctx.__set_per_exch_num_senders(
- params.fragment_exec_params.per_exch_num_senders);
- fragment_instance_ctx.__set_destinations(
- params.fragment_exec_params.destinations);
- fragment_instance_ctx.__set_sender_id(params.sender_id);
- fragment_instance_ctx.fragment_instance_id = params.instance_id;
- fragment_instance_ctx.per_fragment_instance_idx = params.per_fragment_instance_idx;
- rpc_params->__set_fragment_ctx(fragment_ctx);
- rpc_params->__set_fragment_instance_ctx(fragment_instance_ctx);
-}
-
-void Coordinator::SetExecPlanFragmentParams(
- const TPlanFragment& fragment, const FragmentExecParams& params,
- int per_fragment_instance_idx, TExecPlanFragmentParams* rpc_params) {
- rpc_params->__set_protocol_version(ImpalaInternalServiceVersion::V1);
- rpc_params->__set_query_ctx(query_ctx_);
-
- TPlanFragmentCtx fragment_ctx;
- TPlanFragmentInstanceCtx fragment_instance_ctx;
-
- fragment_ctx.__set_fragment(fragment);
- int instance_state_idx = GetInstanceIdx(params.instance_ids[per_fragment_instance_idx]);
// Remove filters that weren't selected during filter routing table construction.
if (filter_mode_ != TRuntimeFilterMode::OFF) {
+ DCHECK(schedule_.request().query_ctx.request.query_options.mt_dop == 0);
+ int instance_idx = GetInstanceIdx(params.instance_id);
for (TPlanNode& plan_node: rpc_params->fragment_ctx.fragment.plan.nodes) {
if (plan_node.__isset.runtime_filters) {
vector<TRuntimeFilterDesc> required_filters;
@@ -2003,7 +1768,7 @@ void Coordinator::SetExecPlanFragmentParams(
if (filter_it == filter_routing_table_.end()) continue;
const FilterState& f = filter_it->second;
if (plan_node.__isset.hash_join_node) {
- if (f.src_fragment_instance_state_idxs().find(instance_state_idx) ==
+ if (f.src_fragment_instance_state_idxs().find(instance_idx) ==
f.src_fragment_instance_state_idxs().end()) {
DCHECK(desc.is_broadcast_join);
continue;
@@ -2018,24 +1783,16 @@ void Coordinator::SetExecPlanFragmentParams(
}
}
}
- SetExecPlanDescriptorTable(fragment, rpc_params);
-
- TNetworkAddress exec_host = params.hosts[per_fragment_instance_idx];
- FragmentScanRangeAssignment::const_iterator it =
- params.scan_range_assignment.find(exec_host);
- // Scan ranges may not always be set, so use an empty structure if so.
- const PerNodeScanRanges& scan_ranges =
- (it != params.scan_range_assignment.end()) ? it->second : PerNodeScanRanges();
fragment_instance_ctx.__set_request_pool(schedule_.request_pool());
- fragment_instance_ctx.__set_per_node_scan_ranges(scan_ranges);
- fragment_instance_ctx.__set_per_exch_num_senders(params.per_exch_num_senders);
- fragment_instance_ctx.__set_destinations(params.destinations);
- fragment_instance_ctx.__set_sender_id(
- params.sender_id_base + per_fragment_instance_idx);
- fragment_instance_ctx.fragment_instance_id =
- params.instance_ids[per_fragment_instance_idx];
- fragment_instance_ctx.per_fragment_instance_idx = per_fragment_instance_idx;
+ fragment_instance_ctx.__set_per_node_scan_ranges(params.per_node_scan_ranges);
+ fragment_instance_ctx.__set_per_exch_num_senders(
+ params.fragment_exec_params.per_exch_num_senders);
+ fragment_instance_ctx.__set_destinations(
+ params.fragment_exec_params.destinations);
+ fragment_instance_ctx.__set_sender_id(params.sender_id);
+ fragment_instance_ctx.fragment_instance_id = params.instance_id;
+ fragment_instance_ctx.per_fragment_instance_idx = params.per_fragment_instance_idx;
rpc_params->__set_fragment_ctx(fragment_ctx);
rpc_params->__set_fragment_instance_ctx(fragment_instance_ctx);
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/runtime/coordinator.h
----------------------------------------------------------------------
diff --git a/be/src/runtime/coordinator.h b/be/src/runtime/coordinator.h
index 176d89d..53f00eb 100644
--- a/be/src/runtime/coordinator.h
+++ b/be/src/runtime/coordinator.h
@@ -100,10 +100,6 @@ struct DebugOptions;
///
/// TODO: move into separate subdirectory and move nested classes into separate files
/// and unnest them
-///
-/// TODO: remove all data structures and functions that are superceded by their
-/// multi-threaded counterpart and remove the "Mt" prefix with which the latter
-/// is currently marked
class Coordinator {
public:
Coordinator(const QuerySchedule& schedule, ExecEnv* exec_env,
@@ -216,7 +212,8 @@ class Coordinator {
private:
class FragmentInstanceState;
- struct FilterState;
+ struct FilterTarget;
+ class FilterState;
/// Typedef for boost utility to compute averaged stats
/// TODO: including the median doesn't compile, looks like some includes are missing
@@ -253,7 +250,7 @@ class Coordinator {
/// FragmentInstanceStates for all fragment instances, including that of the coordinator
/// fragment. All elements are non-nullptr. Owned by obj_pool(). Filled in
- /// PrepareCoordFragment() and StartRemoteFragments()/MtStartRemoteFInstances().
+ /// StartFInstances().
std::vector<FragmentInstanceState*> fragment_instance_states_;
/// True if the query needs a post-execution step to tidy up
@@ -412,22 +409,6 @@ class Coordinator {
/// returned, successfully or not. Initialised during Exec().
boost::scoped_ptr<CountingBarrier> exec_complete_barrier_;
- /// Represents a runtime filter target.
- struct FilterTarget {
- TPlanNodeId node_id;
- bool is_local;
- bool is_bound_by_partition_columns;
-
- // indices into fragment_instance_states_
- boost::unordered_set<int> fragment_instance_state_idxs;
-
- FilterTarget(const TRuntimeFilterTargetDesc& tFilterTarget) {
- node_id = tFilterTarget.node_id;
- is_bound_by_partition_columns = tFilterTarget.is_bound_by_partition_columns;
- is_local = tFilterTarget.is_local_target;
- }
- };
-
/// Protects filter_routing_table_.
SpinLock filter_lock_;
@@ -444,7 +425,7 @@ class Coordinator {
RuntimeProfile::Counter* filter_updates_received_;
/// The filtering mode for this query. Set in constructor.
- const TRuntimeFilterMode::type filter_mode_;
+ TRuntimeFilterMode::type filter_mode_;
/// Tracks the memory consumed by runtime filters during aggregation. Child of
/// query_mem_tracker_.
@@ -459,22 +440,13 @@ class Coordinator {
/// Sets 'filter_routing_table_complete_' and prints the table to the profile and log.
void MarkFilterRoutingTableComplete();
- /// Fill in rpc_params based on parameters.
- /// 'per_fragment_instance_idx' is the 0-based ordinal of this particular fragment
- /// instance within its fragment.
- void SetExecPlanFragmentParams(const TPlanFragment& fragment,
- const FragmentExecParams& params, int per_fragment_instance_idx,
- TExecPlanFragmentParams* rpc_params);
- void MtSetExecPlanFragmentParams(
+ /// Fill in rpc_params based on params.
+ void SetExecPlanFragmentParams(
const FInstanceExecParams& params, TExecPlanFragmentParams* rpc_params);
/// Wrapper for ExecPlanFragment() RPC. This function will be called in parallel from
- /// multiple threads. Creates a new FragmentInstanceState and registers it in
- /// fragment_instance_states_, then calls RPC to issue fragment on remote impalad.
- void ExecRemoteFragment(const FragmentExecParams& fragment_exec_params,
- const TPlanFragment& plan_fragment, DebugOptions* debug_options,
- int fragment_instance_idx);
- void MtExecRemoteFInstance(
+ /// multiple threads.
+ void ExecRemoteFInstance(
const FInstanceExecParams& exec_params, const DebugOptions* debug_options);
/// Determine fragment number, given fragment id.
@@ -518,14 +490,13 @@ class Coordinator {
/// Moves all temporary staging files to their final destinations.
Status FinalizeSuccessfulInsert();
- /// Initializes the structures in runtime profile and exec_summary_. Must be
- /// called before RPCs to start remote fragments.
- void InitExecProfile(const TQueryExecRequest& request);
- void MtInitExecProfiles();
+ /// Initializes the structures in fragment_profiles_. Must be called before RPCs to
+ /// start remote fragments.
+ void InitExecProfiles();
/// Initialize the structures to collect execution summary of every plan node
/// (exec_summary_ and plan_node_id_to_summary_map_)
- void MtInitExecSummary();
+ void InitExecSummary();
/// Update fragment profile information from a fragment instance state.
void UpdateAverageProfile(FragmentInstanceState* fragment_instance_state);
@@ -556,13 +527,10 @@ class Coordinator {
void PopulatePathPermissionCache(hdfsFS fs, const std::string& path_str,
PermissionCache* permissions_cache);
- /// Starts all fragment instances contained in the schedule by issuing RPCs in parallel,
- /// and then waiting for all of the RPCs to complete.
- void StartFragments();
-
- /// Starts all fragment instances contained in the schedule by issuing RPCs in parallel
- /// and then waiting for all of the RPCs to complete.
- void MtStartFInstances();
+ /// Starts all fragment instances contained in the schedule by issuing RPCs in
+ /// parallel and then waiting for all of the RPCs to complete. Also sets up and
+ /// registers the state for all fragment instances.
+ void StartFInstances();
/// Calls CancelInternal() and returns an error if there was any error starting the
/// fragments.
@@ -570,11 +538,8 @@ class Coordinator {
Status FinishInstanceStartup();
/// Build the filter routing table by iterating over all plan nodes and collecting the
- /// filters that they either produce or consume. The source and target fragment
- /// instance indexes for filters are numbered in the range
- /// [start_fragment_instance_idx .. start_fragment_instance_idx + num_hosts]
- void UpdateFilterRoutingTable(const std::vector<TPlanNode>& plan_nodes, int num_hosts,
- int start_fragment_instance_idx);
+ /// filters that they either produce or consume.
+ void UpdateFilterRoutingTable(const FragmentExecParams& fragment_params);
};
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/scheduling/query-schedule.cc
----------------------------------------------------------------------
diff --git a/be/src/scheduling/query-schedule.cc b/be/src/scheduling/query-schedule.cc
index 1eb36e3..e2dc7c4 100644
--- a/be/src/scheduling/query-schedule.cc
+++ b/be/src/scheduling/query-schedule.cc
@@ -50,39 +50,16 @@ QuerySchedule::QuerySchedule(const TUniqueId& query_id,
query_options_(query_options),
summary_profile_(summary_profile),
query_events_(query_events),
- num_fragment_instances_(0),
num_scan_ranges_(0),
next_instance_id_(query_id),
is_admitted_(false) {
- fragment_exec_params_.resize(request.fragments.size());
- bool is_mt_execution = request.query_ctx.request.query_options.mt_dop > 0;
-
- if (is_mt_execution) {
- /// TODO-MT: remove else branch and move MtInit() logic here
- MtInit();
- } else {
- // Build two maps to map node ids to their fragments as well as to the offset in their
- // fragment's plan's nodes list.
- for (int i = 0; i < request.fragments.size(); ++i) {
- int node_idx = 0;
- for (const TPlanNode& node: request.fragments[i].plan.nodes) {
- if (plan_node_to_fragment_idx_.size() < node.node_id + 1) {
- plan_node_to_fragment_idx_.resize(node.node_id + 1);
- plan_node_to_plan_node_idx_.resize(node.node_id + 1);
- }
- DCHECK_EQ(plan_node_to_fragment_idx_.size(), plan_node_to_plan_node_idx_.size());
- plan_node_to_fragment_idx_[node.node_id] = i;
- plan_node_to_plan_node_idx_[node.node_id] = node_idx;
- ++node_idx;
- }
- }
- }
+ Init();
}
-void QuerySchedule::MtInit() {
- // extract TPlanFragments and order by fragment id
+void QuerySchedule::Init() {
+ // extract TPlanFragments and order by fragment idx
vector<const TPlanFragment*> fragments;
- for (const TPlanExecInfo& plan_exec_info: request_.mt_plan_exec_info) {
+ for (const TPlanExecInfo& plan_exec_info: request_.plan_exec_info) {
for (const TPlanFragment& fragment: plan_exec_info.fragments) {
fragments.push_back(&fragment);
}
@@ -90,41 +67,34 @@ void QuerySchedule::MtInit() {
sort(fragments.begin(), fragments.end(),
[](const TPlanFragment* a, const TPlanFragment* b) { return a->idx < b->idx; });
- DCHECK_EQ(mt_fragment_exec_params_.size(), 0);
+ // this must only be called once
+ DCHECK_EQ(fragment_exec_params_.size(), 0);
for (const TPlanFragment* fragment: fragments) {
- mt_fragment_exec_params_.emplace_back(*fragment);
+ fragment_exec_params_.emplace_back(*fragment);
}
// mark coordinator fragment
- const TPlanFragment& coord_fragment = request_.mt_plan_exec_info[0].fragments[0];
- if (coord_fragment.partition.type == TPartitionType::UNPARTITIONED) {
- mt_fragment_exec_params_[coord_fragment.idx].is_coord_fragment = true;
- next_instance_id_.lo = 1; // generated instance ids start at 1
+ const TPlanFragment& root_fragment = request_.plan_exec_info[0].fragments[0];
+ if (request_.stmt_type == TStmtType::QUERY) {
+ fragment_exec_params_[root_fragment.idx].is_coord_fragment = true;
+ // the coordinator instance gets index 0, generated instance ids start at 1
+ next_instance_id_.lo = 1;
}
- // compute input fragments and find max node id
+ // find max node id
int max_node_id = 0;
- for (const TPlanExecInfo& plan_exec_info: request_.mt_plan_exec_info) {
+ for (const TPlanExecInfo& plan_exec_info: request_.plan_exec_info) {
for (const TPlanFragment& fragment: plan_exec_info.fragments) {
for (const TPlanNode& node: fragment.plan.nodes) {
max_node_id = max(node.node_id, max_node_id);
}
}
-
- // fragments[i] sends its output to fragments[dest_fragment_idx[i-1]]
- for (int i = 1; i < plan_exec_info.fragments.size(); ++i) {
- const TPlanFragment& fragment = plan_exec_info.fragments[i];
- FragmentIdx dest_idx =
- plan_exec_info.fragments[plan_exec_info.dest_fragment_idx[i - 1]].idx;
- MtFragmentExecParams& dest_params = mt_fragment_exec_params_[dest_idx];
- dest_params.input_fragments.push_back(fragment.idx);
- }
}
// populate plan_node_to_fragment_idx_ and plan_node_to_plan_node_idx_
plan_node_to_fragment_idx_.resize(max_node_id + 1);
plan_node_to_plan_node_idx_.resize(max_node_id + 1);
- for (const TPlanExecInfo& plan_exec_info: request_.mt_plan_exec_info) {
+ for (const TPlanExecInfo& plan_exec_info: request_.plan_exec_info) {
for (const TPlanFragment& fragment: plan_exec_info.fragments) {
for (int i = 0; i < fragment.plan.nodes.size(); ++i) {
const TPlanNode& node = fragment.plan.nodes[i];
@@ -133,8 +103,72 @@ void QuerySchedule::MtInit() {
}
}
}
+
+ // compute input fragments
+ for (const TPlanExecInfo& plan_exec_info: request_.plan_exec_info) {
+ // each fragment sends its output to the fragment containing the destination node
+ // of its output sink
+ for (const TPlanFragment& fragment: plan_exec_info.fragments) {
+ if (!fragment.output_sink.__isset.stream_sink) continue;
+ PlanNodeId dest_node_id = fragment.output_sink.stream_sink.dest_node_id;
+ FragmentIdx dest_idx = plan_node_to_fragment_idx_[dest_node_id];
+ FragmentExecParams& dest_params = fragment_exec_params_[dest_idx];
+ dest_params.input_fragments.push_back(fragment.idx);
+ }
+ }
}
+void QuerySchedule::Validate() const {
+ // all fragments have a FragmentExecParams
+ int num_fragments = 0;
+ for (const TPlanExecInfo& plan_exec_info: request_.plan_exec_info) {
+ for (const TPlanFragment& fragment: plan_exec_info.fragments) {
+ DCHECK_LT(fragment.idx, fragment_exec_params_.size());
+ DCHECK_EQ(fragment.idx, fragment_exec_params_[fragment.idx].fragment.idx);
+ ++num_fragments;
+ }
+ }
+ DCHECK_EQ(num_fragments, fragment_exec_params_.size());
+
+ // we assigned the correct number of scan ranges per (host, node id):
+ // assemble a map from host -> (map from node id -> #scan ranges)
+ unordered_map<TNetworkAddress, map<TPlanNodeId, int>> count_map;
+ for (const FragmentExecParams& fp: fragment_exec_params_) {
+ for (const FInstanceExecParams& ip: fp.instance_exec_params) {
+ auto host_it = count_map.find(ip.host);
+ if (host_it == count_map.end()) {
+ count_map.insert(make_pair(ip.host, map<TPlanNodeId, int>()));
+ host_it = count_map.find(ip.host);
+ }
+ map<TPlanNodeId, int>& node_map = host_it->second;
+
+ for (const PerNodeScanRanges::value_type& instance_entry: ip.per_node_scan_ranges) {
+ TPlanNodeId node_id = instance_entry.first;
+ auto count_entry = node_map.find(node_id);
+ if (count_entry == node_map.end()) {
+ node_map.insert(make_pair(node_id, 0));
+ count_entry = node_map.find(node_id);
+ }
+ count_entry->second += instance_entry.second.size();
+ }
+ }
+ }
+
+ for (const FragmentExecParams& fp: fragment_exec_params_) {
+ for (const FragmentScanRangeAssignment::value_type& assignment_entry:
+ fp.scan_range_assignment) {
+ const TNetworkAddress& host = assignment_entry.first;
+ DCHECK_GT(count_map.count(host), 0);
+ map<TPlanNodeId, int>& node_map = count_map.find(host)->second;
+ for (const PerNodeScanRanges::value_type& node_assignment:
+ assignment_entry.second) {
+ TPlanNodeId node_id = node_assignment.first;
+ DCHECK_GT(node_map.count(node_id), 0);
+ DCHECK_EQ(node_map[node_id], node_assignment.second.size());
+ }
+ }
+ }
+}
int64_t QuerySchedule::GetClusterMemoryEstimate() const {
DCHECK_GT(unique_hosts_.size(), 0);
@@ -199,15 +233,8 @@ const TPlanFragment& FInstanceExecParams::fragment() const {
int QuerySchedule::GetNumFragmentInstances() const {
int result = 0;
- if (mt_fragment_exec_params_.empty()) {
- DCHECK(!fragment_exec_params_.empty());
- for (const FragmentExecParams& fragment_exec_params : fragment_exec_params_) {
- result += fragment_exec_params.hosts.size();
- }
- } else {
- for (const MtFragmentExecParams& fragment_exec_params : mt_fragment_exec_params_) {
- result += fragment_exec_params.instance_exec_params.size();
- }
+ for (const FragmentExecParams& fragment_exec_params : fragment_exec_params_) {
+ result += fragment_exec_params.instance_exec_params.size();
}
return result;
}
@@ -215,37 +242,35 @@ int QuerySchedule::GetNumFragmentInstances() const {
const TPlanFragment* QuerySchedule::GetCoordFragment() const {
// Only have coordinator fragment for statements that return rows.
if (request_.stmt_type != TStmtType::QUERY) return nullptr;
- bool is_mt_exec = request_.query_ctx.request.query_options.mt_dop > 0;
- const TPlanFragment* fragment = is_mt_exec
- ? &request_.mt_plan_exec_info[0].fragments[0] : &request_.fragments[0];
-
- return fragment;
+ const TPlanFragment* fragment = &request_.plan_exec_info[0].fragments[0];
+ DCHECK_EQ(fragment->partition.type, TPartitionType::UNPARTITIONED);
+ return fragment;
}
+
void QuerySchedule::GetTPlanFragments(vector<const TPlanFragment*>* fragments) const {
fragments->clear();
- bool is_mt_exec = request_.query_ctx.request.query_options.mt_dop > 0;
- if (is_mt_exec) {
- for (const TPlanExecInfo& plan_info: request_.mt_plan_exec_info) {
- for (const TPlanFragment& fragment: plan_info.fragments) {
- fragments->push_back(&fragment);
- }
- }
- } else {
- for (const TPlanFragment& fragment: request_.fragments) {
+ for (const TPlanExecInfo& plan_info: request_.plan_exec_info) {
+ for (const TPlanFragment& fragment: plan_info.fragments) {
fragments->push_back(&fragment);
}
}
}
const FInstanceExecParams& QuerySchedule::GetCoordInstanceExecParams() const {
- const TPlanFragment& coord_fragment = request_.mt_plan_exec_info[0].fragments[0];
- DCHECK_EQ(coord_fragment.partition.type, TPartitionType::UNPARTITIONED);
- const MtFragmentExecParams* fragment_params =
- &mt_fragment_exec_params_[coord_fragment.idx];
- DCHECK(fragment_params != nullptr);
- DCHECK_EQ(fragment_params->instance_exec_params.size(), 1);
- return fragment_params->instance_exec_params[0];
+ DCHECK_EQ(request_.stmt_type, TStmtType::QUERY);
+ const TPlanFragment& coord_fragment = request_.plan_exec_info[0].fragments[0];
+ const FragmentExecParams& fragment_params = fragment_exec_params_[coord_fragment.idx];
+ DCHECK_EQ(fragment_params.instance_exec_params.size(), 1);
+ return fragment_params.instance_exec_params[0];
+}
+
+vector<int> FragmentExecParams::GetInstanceIdxs() const {
+ vector<int> result;
+ for (const FInstanceExecParams& instance_params: instance_exec_params) {
+ result.push_back(GetInstanceIdx(instance_params.instance_id));
+ }
+ return result;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/scheduling/query-schedule.h
----------------------------------------------------------------------
diff --git a/be/src/scheduling/query-schedule.h b/be/src/scheduling/query-schedule.h
index 77c9cd6..703c07c 100644
--- a/be/src/scheduling/query-schedule.h
+++ b/be/src/scheduling/query-schedule.h
@@ -35,7 +35,7 @@
namespace impala {
class Coordinator;
-struct MtFragmentExecParams;
+struct FragmentExecParams;
/// map from scan node id to a list of scan ranges
typedef std::map<TPlanNodeId, std::vector<TScanRangeParams>> PerNodeScanRanges;
@@ -45,22 +45,6 @@ typedef std::map<TPlanNodeId, std::vector<TScanRangeParams>> PerNodeScanRanges;
typedef std::unordered_map<TNetworkAddress, PerNodeScanRanges>
FragmentScanRangeAssignment;
-/// execution parameters for a single fragment; used to assemble the
-/// TPlanFragmentInstanceCtx;
-/// hosts.size() == instance_ids.size()
-struct FragmentExecParams {
- std::vector<TNetworkAddress> hosts; // execution backends
- std::vector<TUniqueId> instance_ids;
- std::vector<TPlanFragmentDestination> destinations;
- std::map<PlanNodeId, int> per_exch_num_senders;
- FragmentScanRangeAssignment scan_range_assignment;
- /// In its role as a data sender, a fragment instance is assigned a "sender id" to
- /// uniquely identify it to a receiver. The id that a particular fragment instance
- /// is assigned ranges from [sender_id_base, sender_id_base + N - 1], where
- /// N = hosts.size (i.e. N = number of fragment instances)
- int sender_id_base;
-};
-
/// execution parameters for a single fragment instance; used to assemble the
/// TPlanFragmentInstanceCtx
struct FInstanceExecParams {
@@ -75,12 +59,12 @@ struct FInstanceExecParams {
/// uniquely identify it to a receiver. -1 = invalid.
int sender_id;
- /// the parent MtFragmentExecParams
- const MtFragmentExecParams& fragment_exec_params;
+ /// the parent FragmentExecParams
+ const FragmentExecParams& fragment_exec_params;
const TPlanFragment& fragment() const;
FInstanceExecParams(const TUniqueId& instance_id, const TNetworkAddress& host,
- int per_fragment_instance_idx, const MtFragmentExecParams& fragment_exec_params)
+ int per_fragment_instance_idx, const FragmentExecParams& fragment_exec_params)
: instance_id(instance_id), host(host),
per_fragment_instance_idx(per_fragment_instance_idx),
sender_id(-1),
@@ -88,7 +72,7 @@ struct FInstanceExecParams {
};
/// Execution parameters shared between fragment instances
-struct MtFragmentExecParams {
+struct FragmentExecParams {
/// output destinations of this fragment
std::vector<TPlanFragmentDestination> destinations;
@@ -105,8 +89,11 @@ struct MtFragmentExecParams {
std::vector<FragmentIdx> input_fragments;
std::vector<FInstanceExecParams> instance_exec_params;
- MtFragmentExecParams(const TPlanFragment& fragment)
+ FragmentExecParams(const TPlanFragment& fragment)
: is_coord_fragment(false), fragment(fragment) {}
+
+ // extract instance indices from instance_exec_params.instance_id
+ std::vector<int> GetInstanceIdxs() const;
};
/// A QuerySchedule contains all necessary information for a query coordinator to
@@ -123,6 +110,11 @@ class QuerySchedule {
const TQueryOptions& query_options, RuntimeProfile* summary_profile,
RuntimeProfile::EventSequence* query_events);
+ /// Verifies that the schedule is well-formed (and DCHECKs if it isn't):
+ /// - all fragments have a FragmentExecParams
+ /// - all scan ranges are assigned
+ void Validate() const;
+
const TUniqueId& query_id() const { return query_id_; }
const TQueryExecRequest& request() const { return request_; }
const TQueryOptions& query_options() const { return query_options_; }
@@ -165,30 +157,24 @@ class QuerySchedule {
TUniqueId GetNextInstanceId();
const TPlanFragment& GetContainingFragment(PlanNodeId node_id) const {
- return mt_fragment_exec_params_[GetFragmentIdx(node_id)].fragment;
+ FragmentIdx fragment_idx = GetFragmentIdx(node_id);
+ DCHECK_LT(fragment_idx, fragment_exec_params_.size());
+ return fragment_exec_params_[fragment_idx].fragment;
}
- /// Map node ids to the index of their node inside their plan.nodes list.
- /// TODO-MT: remove; only needed for the ST path
- int32_t GetNodeIdx(PlanNodeId id) const { return plan_node_to_plan_node_idx_[id]; }
-
const TPlanNode& GetNode(PlanNodeId id) const {
const TPlanFragment& fragment = GetContainingFragment(id);
return fragment.plan.nodes[plan_node_to_plan_node_idx_[id]];
}
- std::vector<FragmentExecParams>* exec_params() { return &fragment_exec_params_; }
- const std::vector<FragmentExecParams>& exec_params() const {
+ const std::vector<FragmentExecParams>& fragment_exec_params() const {
return fragment_exec_params_;
}
- const std::vector<MtFragmentExecParams>& mt_fragment_exec_params() const {
- return mt_fragment_exec_params_;
- }
- const MtFragmentExecParams& GetFragmentExecParams(FragmentIdx idx) const {
- return mt_fragment_exec_params_[idx];
+ const FragmentExecParams& GetFragmentExecParams(FragmentIdx idx) const {
+ return fragment_exec_params_[idx];
}
- MtFragmentExecParams* GetFragmentExecParams(FragmentIdx idx) {
- return &mt_fragment_exec_params_[idx];
+ FragmentExecParams* GetFragmentExecParams(FragmentIdx idx) {
+ return &fragment_exec_params_[idx];
}
const FInstanceExecParams& GetCoordInstanceExecParams() const;
@@ -211,6 +197,8 @@ class QuerySchedule {
/// The query options from the TClientRequest
const TQueryOptions& query_options_;
+
+ /// TODO: move these into QueryState
RuntimeProfile* summary_profile_;
RuntimeProfile::EventSequence* query_events_;
@@ -220,21 +208,14 @@ class QuerySchedule {
/// Maps from plan node id to its index in plan.nodes. Filled in c'tor.
std::vector<int32_t> plan_node_to_plan_node_idx_;
- /// vector is indexed by fragment index from TQueryExecRequest.fragments;
- /// populated by Scheduler::Schedule()
+ // populated in Init() and Scheduler::Schedule()
+ // (SimpleScheduler::ComputeFInstanceExecParams()), indexed by fragment idx
+ // (TPlanFragment.idx)
std::vector<FragmentExecParams> fragment_exec_params_;
- // populated by Scheduler::Schedule (SimpleScheduler::ComputeMtFInstanceExecParams())
- // indexed by fragment idx (TPlanFragment.idx)
- std::vector<MtFragmentExecParams> mt_fragment_exec_params_;
-
/// The set of hosts that the query will run on excluding the coordinator.
boost::unordered_set<TNetworkAddress> unique_hosts_;
- /// Number of backends executing plan fragments on behalf of this query.
- /// TODO-MT: remove
- int64_t num_fragment_instances_;
-
/// Total number of scan ranges of this query.
int64_t num_scan_ranges_;
@@ -247,10 +228,10 @@ class QuerySchedule {
/// Indicates if the query has been admitted for execution.
bool is_admitted_;
- /// Populate mt_fragment_exec_params_ from request_.mt_plan_exec_info.
+ /// Populate fragment_exec_params_ from request_.plan_exec_info.
/// Sets is_coord_fragment and input_fragments.
/// Also populates plan_node_to_fragment_idx_ and plan_node_to_plan_node_idx_.
- void MtInit();
+ void Init();
};
}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/scheduling/simple-scheduler-test-util.cc
----------------------------------------------------------------------
diff --git a/be/src/scheduling/simple-scheduler-test-util.cc b/be/src/scheduling/simple-scheduler-test-util.cc
index d3f5584..911279c 100644
--- a/be/src/scheduling/simple-scheduler-test-util.cc
+++ b/be/src/scheduling/simple-scheduler-test-util.cc
@@ -202,7 +202,7 @@ const vector<TNetworkAddress>& Plan::referenced_datanodes() const {
return referenced_datanodes_;
}
-const vector<TScanRangeLocations>& Plan::scan_range_locations() const {
+const vector<TScanRangeLocationList>& Plan::scan_range_locations() const {
return scan_range_locations_;
}
@@ -211,14 +211,14 @@ void Plan::AddTableScan(const TableName& table_name) {
const vector<Block>& blocks = table.blocks;
for (int i = 0; i < blocks.size(); ++i) {
const Block& block = blocks[i];
- TScanRangeLocations scan_range_locations;
- BuildTScanRangeLocations(table_name, block, i, &scan_range_locations);
+ TScanRangeLocationList scan_range_locations;
+ BuildTScanRangeLocationList(table_name, block, i, &scan_range_locations);
scan_range_locations_.push_back(scan_range_locations);
}
}
-void Plan::BuildTScanRangeLocations(const TableName& table_name, const Block& block,
- int block_idx, TScanRangeLocations* scan_range_locations) {
+void Plan::BuildTScanRangeLocationList(const TableName& table_name, const Block& block,
+ int block_idx, TScanRangeLocationList* scan_range_locations) {
const vector<int>& replica_idxs = block.replica_host_idxs;
const vector<bool>& is_cached = block.replica_host_idx_is_cached;
DCHECK_EQ(replica_idxs.size(), is_cached.size());
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/0d857237/be/src/scheduling/simple-scheduler-test-util.h
----------------------------------------------------------------------
diff --git a/be/src/scheduling/simple-scheduler-test-util.h b/be/src/scheduling/simple-scheduler-test-util.h
index ab46e2a..82190ad 100644
--- a/be/src/scheduling/simple-scheduler-test-util.h
+++ b/be/src/scheduling/simple-scheduler-test-util.h
@@ -231,11 +231,11 @@ class Plan {
const std::vector<TNetworkAddress>& referenced_datanodes() const;
- const std::vector<TScanRangeLocations>& scan_range_locations() const;
+ const std::vector<TScanRangeLocationList>& scan_range_locations() const;
/// Add a scan of table 'table_name' to the plan. This method will populate the internal
- /// list of TScanRangeLocations and can be called multiple times for the same table to
- /// schedule additional scans.
+ /// list of TScanRangeLocationList and can be called multiple times for the same table
+ /// to schedule additional scans.
void AddTableScan(const TableName& table_name);
private:
@@ -252,11 +252,11 @@ class Plan {
std::unordered_map<int, int> host_idx_to_datanode_idx_;
/// List of all scan range locations, which can be passed to the SimpleScheduler.
- std::vector<TScanRangeLocations> scan_range_locations_;
+ std::vector<TScanRangeLocationList> scan_range_locations_;
- /// Initialize a TScanRangeLocations object in place.
- void BuildTScanRangeLocations(const TableName& table_name, const Block& block,
- int block_idx, TScanRangeLocations* scan_range_locations);
+ /// Initialize a TScanRangeLocationList object in place.
+ void BuildTScanRangeLocationList(const TableName& table_name, const Block& block,
+ int block_idx, TScanRangeLocationList* scan_range_locations);
void BuildScanRange(const TableName& table_name, const Block& block, int block_idx,
TScanRange* scan_range);