Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
query-schedule.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef STATESTORE_QUERY_SCHEDULE_H
16 #define STATESTORE_QUERY_SCHEDULE_H
17 
18 #include <vector>
19 #include <string>
20 #include <boost/unordered_set.hpp>
21 #include <boost/unordered_map.hpp>
22 #include <boost/scoped_ptr.hpp>
23 
24 #include "common/global-types.h"
25 #include "common/status.h"
27 #include "util/promise.h"
28 #include "util/runtime-profile.h"
29 #include "gen-cpp/Types_types.h" // for TNetworkAddress
30 #include "gen-cpp/Frontend_types.h"
31 #include "gen-cpp/ResourceBrokerService_types.h"
32 
33 namespace impala {
34 
35 class Coordinator;
36 
38 typedef std::map<TPlanNodeId, std::vector<TScanRangeParams> > PerNodeScanRanges;
41 typedef boost::unordered_map<TNetworkAddress, PerNodeScanRanges>
43 
48  std::vector<TNetworkAddress> hosts; // execution backends
49  std::vector<TUniqueId> instance_ids;
50  std::vector<TPlanFragmentDestination> destinations;
51  std::map<PlanNodeId, int> per_exch_num_senders;
58 };
68  public:
69  QuerySchedule(const TUniqueId& query_id, const TQueryExecRequest& request,
70  const TQueryOptions& query_options, const std::string& effective_user,
72 
76 
77  const TUniqueId& query_id() const { return query_id_; }
78  const TQueryExecRequest& request() const { return request_; }
79  const TQueryOptions& query_options() const { return query_options_; }
80  const std::string& effective_user() const { return effective_user_; }
81  const std::string& request_pool() const { return request_pool_; }
82  void set_request_pool(const std::string& pool_name) { request_pool_ = pool_name; }
83  bool HasReservation() const { return !reservation_.allocated_resources.empty(); }
84 
87  bool NeedsRelease() const { return reservation_.__isset.reservation_id; }
88 
93  int64_t GetPerHostMemoryEstimate() const;
94  int16_t GetPerHostVCores() const;
96  int64_t GetClusterMemoryEstimate() const;
97  void GetResourceHostport(const TNetworkAddress& src, TNetworkAddress* dst);
98 
100  void AddScanRanges(int64_t delta) { num_scan_ranges_ += delta; }
102  void set_num_hosts(int64_t num_hosts) {
103  DCHECK_GT(num_hosts, 0);
105  }
106  int64_t num_backends() const { return num_backends_; }
107  int64_t num_hosts() const { return num_hosts_; }
108  int64_t num_scan_ranges() const { return num_scan_ranges_; }
109  int32_t GetFragmentIdx(PlanNodeId id) const { return plan_node_to_fragment_idx_[id]; }
110  std::vector<FragmentExecParams>* exec_params() { return &fragment_exec_params_; }
111  const boost::unordered_set<TNetworkAddress>& unique_hosts() const {
112  return unique_hosts_;
113  }
114  TResourceBrokerReservationResponse* reservation() { return &reservation_; }
115  const TResourceBrokerReservationRequest& reservation_request() const {
116  return reservation_request_;
117  }
118  bool is_admitted() const { return is_admitted_; }
122 
123  void SetUniqueHosts(const boost::unordered_set<TNetworkAddress>& unique_hosts);
124 
127  void PrepareReservationRequest(const std::string& pool, const std::string& user);
128 
129  private:
130 
133  const TUniqueId& query_id_;
134  const TQueryExecRequest& request_;
135  const TQueryOptions& query_options_;
136  const std::string effective_user_;
139 
141  std::vector<int32_t> plan_node_to_fragment_idx_;
142 
145  std::vector<FragmentExecParams> fragment_exec_params_;
146 
148  boost::unordered_set<TNetworkAddress> unique_hosts_;
149 
151  int64_t num_backends_;
152 
155  int64_t num_hosts_;
156 
159 
161  std::string request_pool_;
162 
164  TResourceBrokerReservationRequest reservation_request_;
165 
167  TResourceBrokerReservationResponse reservation_;
168 
171 
174  boost::scoped_ptr<ResourceResolver> resource_resolver_;
175 };
176 
177 }
178 
179 #endif
RuntimeProfile * summary_profile_
bool is_admitted_
Indicates if the query has been admitted for execution.
RuntimeProfile::EventSequence * query_events()
int64_t num_hosts() const
int PlanNodeId
Definition: global-types.h:26
const TQueryOptions & query_options_
void set_request_pool(const std::string &pool_name)
std::vector< TNetworkAddress > hosts
std::vector< int32_t > plan_node_to_fragment_idx_
Maps from plan node id to its fragment index. Filled in c'tor.
int32_t GetFragmentIdx(PlanNodeId id) const
boost::unordered_map< TNetworkAddress, PerNodeScanRanges > FragmentScanRangeAssignment
std::vector< TPlanFragmentDestination > destinations
int64_t GetPerHostMemoryEstimate() const
int64_t num_backends() const
bool HasReservation() const
const TUniqueId & query_id_
void PrepareReservationRequest(const std::string &pool, const std::string &user)
void GetResourceHostport(const TNetworkAddress &src, TNetworkAddress *dst)
void set_num_backends(int64_t num_backends)
bool NeedsRelease() const
void AddScanRanges(int64_t delta)
Helper methods used by scheduler to populate this QuerySchedule.
QuerySchedule(const TUniqueId &query_id, const TQueryExecRequest &request, const TQueryOptions &query_options, const std::string &effective_user, RuntimeProfile *summary_profile, RuntimeProfile::EventSequence *query_events)
const TUniqueId & query_id() const
FragmentScanRangeAssignment scan_range_assignment
std::map< TPlanNodeId, std::vector< TScanRangeParams > > PerNodeScanRanges
map from scan node id to a list of scan ranges
std::string request_pool_
Request pool to which the request was submitted for admission.
void set_num_hosts(int64_t num_hosts)
std::vector< FragmentExecParams > fragment_exec_params_
int64_t num_backends_
Number of backends executing plan fragments on behalf of this query.
const TQueryExecRequest & request_
ObjectPool pool
std::vector< FragmentExecParams > * exec_params()
RuntimeProfile * summary_profile()
void SetUniqueHosts(const boost::unordered_set< TNetworkAddress > &unique_hosts)
int64_t num_scan_ranges() const
void set_is_admitted(bool is_admitted)
const std::string effective_user_
int16_t GetPerHostVCores() const
std::map< PlanNodeId, int > per_exch_num_senders
int64_t GetClusterMemoryEstimate() const
Total estimated memory for all nodes. set_num_hosts() must be set before calling. ...
const TResourceBrokerReservationRequest & reservation_request() const
const std::string & effective_user() const
const boost::unordered_set< TNetworkAddress > & unique_hosts() const
const std::string & request_pool() const
TResourceBrokerReservationResponse reservation_
Fulfilled reservation request. Populated by scheduler.
RuntimeProfile::EventSequence * query_events_
TResourceBrokerReservationResponse * reservation()
TResourceBrokerReservationRequest reservation_request_
Reservation request to be submitted to Llama. Set in PrepareReservationRequest(). ...
const TQueryOptions & query_options() const
boost::unordered_set< TNetworkAddress > unique_hosts_
The set of hosts that the query will run on excluding the coordinator.
std::vector< TUniqueId > instance_ids
int64_t num_scan_ranges_
Total number of scan ranges of this query.
const TQueryExecRequest & request() const
boost::scoped_ptr< ResourceResolver > resource_resolver_
bool is_admitted() const