Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
plan-fragment-executor.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 
16 #ifndef IMPALA_SERVICE_PLAN_EXECUTOR_H
17 #define IMPALA_SERVICE_PLAN_EXECUTOR_H
18 
19 #include <vector>
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/function.hpp>
23 
24 #include "common/status.h"
25 #include "common/object-pool.h"
26 #include "runtime/runtime-state.h"
27 #include "util/thread.h"
28 
29 namespace impala {
30 
31 class HdfsFsCache;
32 class ExecNode;
33 class RowDescriptor;
34 class RowBatch;
35 class DataSink;
36 class DataStreamMgr;
37 class RuntimeProfile;
38 class RuntimeState;
39 class TRowBatch;
40 class TPlanExecRequest;
41 class TPlanFragment;
42 class TPlanFragmentExecParams;
43 class TPlanExecParams;
44 
49 //
61 //
65  public:
72  typedef boost::function<
73  void (const Status& status, RuntimeProfile* profile, bool done)>
75 
78  PlanFragmentExecutor(ExecEnv* exec_env, const ReportStatusCallback& report_status_cb);
79 
86 
93  Status Prepare(const TExecPlanFragmentParams& request);
94 
104  Status Open();
105 
111  Status GetNext(RowBatch** batch);
112 
115  void Close();
116 
118  void Cancel();
119 
121  bool ReachedLimit();
122 
124  void ReleaseThreadToken();
125 
128  const RowDescriptor& row_desc();
129 
132 
134  static const std::string PER_HOST_PEAK_MEM_COUNTER;
135 
136  private:
137  ExecEnv* exec_env_; // not owned
138  ExecNode* plan_; // lives in runtime_state_->obj_pool()
139  TUniqueId query_id_;
140 
143  boost::scoped_ptr<Thread> report_thread_;
144  boost::mutex report_thread_lock_;
145 
148  boost::condition_variable stop_report_thread_cv_;
149 
152  boost::condition_variable report_thread_started_cv_;
153  bool report_thread_active_; // true if we started the thread
154 
156  bool done_;
157 
159  bool prepared_;
160 
162  bool closed_;
163 
166 
170 
175  boost::mutex status_lock_;
176 
180  boost::scoped_ptr<DataSink> sink_;
181  boost::scoped_ptr<RuntimeState> runtime_state_;
182  boost::scoped_ptr<RowBatch> row_batch_;
183  boost::scoped_ptr<TRowBatch> thrift_batch_;
184 
190 
193 
202 
205 
211 
214 
217 
218  ObjectPool* obj_pool() { return runtime_state_->obj_pool(); }
219 
221  typedef std::map<TPlanNodeId, std::vector<TScanRangeParams> > PerNodeScanRanges;
222 
226  void ReportProfile();
227 
231  void SendReport(bool done);
232 
236  void UpdateStatus(const Status& status);
237 
239  void FragmentComplete();
240 
247  void OptimizeLlvmModule();
248 
256 
260 
263  void StopReportThread();
264 
266  void PrintVolumeIds(const TPlanExecParams& params);
267  void PrintVolumeIds(const PerNodeScanRanges& per_node_scan_ranges);
268 
269  const DescriptorTbl& desc_tbl() { return runtime_state_->desc_tbl(); }
270 };
271 
272 }
273 
274 #endif
void UpdateStatus(const Status &status)
boost::scoped_ptr< RowBatch > row_batch_
Status GetNextInternal(RowBatch **batch)
RuntimeProfile::TimeSeriesCounter * thread_usage_sampled_counter_
Sampled thread usage (tokens) at even time intervals.
void FragmentComplete()
Called when the fragment execution is complete to finalize counters.
RuntimeProfile::Counter * per_host_mem_usage_
MonotonicStopWatch fragment_sw_
Stopwatch for this entire fragment. Started in Prepare(), stopped in Close().
RuntimeProfile::Counter * average_thread_tokens_
const DescriptorTbl & desc_tbl()
boost::condition_variable stop_report_thread_cv_
void Cancel()
Initiate cancellation. Must not be called until after Prepare() returned.
boost::condition_variable report_thread_started_cv_
boost::scoped_ptr< TRowBatch > thrift_batch_
ReportStatusCallback report_status_cb_
profile reporting-related
Status Prepare(const TExecPlanFragmentParams &request)
RuntimeProfile * profile()
Profile information for plan and output sink.
void ReleaseThreadToken()
Releases the thread token for this fragment executor.
bool closed_
true if Close() has been called
boost::scoped_ptr< DataSink > sink_
void PrintVolumeIds(const TPlanExecParams &params)
Print stats about scan ranges for each volumeId in params to info log.
PlanFragmentExecutor(ExecEnv *exec_env, const ReportStatusCallback &report_status_cb)
boost::scoped_ptr< RuntimeState > runtime_state_
RuntimeProfile::Counter * rows_produced_counter_
Number of rows returned by this fragment.
RuntimeState * runtime_state()
call these only after Prepare()
std::map< TPlanNodeId, std::vector< TScanRangeParams > > PerNodeScanRanges
typedef for TPlanFragmentExecParams.per_node_scan_ranges
boost::function< void(const Status &status, RuntimeProfile *profile, bool done)> ReportStatusCallback
bool ReachedLimit()
Returns true if this query has a limit and it has been reached.
RuntimeProfile::TimeSeriesCounter * mem_usage_sampled_counter_
Sampled memory usage at even time intervals.
bool done_
true if plan_->GetNext() indicated that it's done
static const std::string PER_HOST_PEAK_MEM_COUNTER
Name of the counter that is tracking per query, per host peak mem usage.
bool prepared_
true if Prepare() returned OK
Status GetNext(RowBatch **batch)
boost::scoped_ptr< Thread > report_thread_
bool has_thread_token_
true if this fragment has not returned the thread token to the thread resource mgr ...