/root/doris/be/src/runtime/runtime_state.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // This file is copied from |
18 | | // https://github.com/apache/impala/blob/branch-2.9.0/be/src/runtime/runtime-state.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <gen_cpp/PaloInternalService_types.h> |
24 | | #include <gen_cpp/Types_types.h> |
25 | | #include <gen_cpp/segment_v2.pb.h> |
26 | | #include <stdint.h> |
27 | | |
28 | | #include <atomic> |
29 | | #include <fstream> |
30 | | #include <functional> |
31 | | #include <memory> |
32 | | #include <mutex> |
33 | | #include <string> |
34 | | #include <utility> |
35 | | #include <vector> |
36 | | |
37 | | #include "cctz/time_zone.h" |
38 | | #include "common/compiler_util.h" // IWYU pragma: keep |
39 | | #include "common/factory_creator.h" |
40 | | #include "common/status.h" |
41 | | #include "gutil/integral_types.h" |
42 | | #include "runtime/task_execution_context.h" |
43 | | #include "util/debug_util.h" |
44 | | #include "util/runtime_profile.h" |
45 | | #include "vec/columns/columns_number.h" |
46 | | |
47 | | namespace doris { |
48 | | class IRuntimeFilter; |
49 | | |
50 | | namespace pipeline { |
51 | | class PipelineXLocalStateBase; |
52 | | class PipelineXSinkLocalStateBase; |
53 | | class PipelineXFragmentContext; |
54 | | class PipelineXTask; |
55 | | } // namespace pipeline |
56 | | |
57 | | class DescriptorTbl; |
58 | | class ObjectPool; |
59 | | class ExecEnv; |
60 | | class RuntimeFilterMgr; |
61 | | class MemTrackerLimiter; |
62 | | class QueryContext; |
63 | | |
64 | | // A collection of items that are part of the global state of a |
65 | | // query and shared across all execution nodes of that query. |
66 | | class RuntimeState { |
67 | | ENABLE_FACTORY_CREATOR(RuntimeState); |
68 | | |
69 | | public: |
70 | | RuntimeState(const TPlanFragmentExecParams& fragment_exec_params, |
71 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
72 | | ExecEnv* exec_env, QueryContext* ctx, |
73 | | const std::shared_ptr<MemTrackerLimiter>& query_mem_tracker = nullptr); |
74 | | |
75 | | RuntimeState(const TUniqueId& instance_id, const TUniqueId& query_id, int32 fragment_id, |
76 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
77 | | ExecEnv* exec_env, QueryContext* ctx); |
78 | | |
79 | | // for only use in pipelineX |
80 | | RuntimeState(pipeline::PipelineXFragmentContext*, const TUniqueId& instance_id, |
81 | | const TUniqueId& query_id, int32 fragment_id, const TQueryOptions& query_options, |
82 | | const TQueryGlobals& query_globals, ExecEnv* exec_env, QueryContext* ctx); |
83 | | |
84 | | // Used by pipelineX. This runtime state is only used for setup. |
85 | | RuntimeState(const TUniqueId& query_id, int32 fragment_id, const TQueryOptions& query_options, |
86 | | const TQueryGlobals& query_globals, ExecEnv* exec_env, QueryContext* ctx); |
87 | | |
88 | | // RuntimeState for executing expr in fe-support. |
89 | | RuntimeState(const TQueryGlobals& query_globals); |
90 | | |
91 | | // for job task only |
92 | | RuntimeState(); |
93 | | |
94 | | // Empty d'tor to avoid issues with unique_ptr. |
95 | | ~RuntimeState(); |
96 | | |
97 | | // Set per-query state. |
98 | | Status init(const TUniqueId& fragment_instance_id, const TQueryOptions& query_options, |
99 | | const TQueryGlobals& query_globals, ExecEnv* exec_env); |
100 | | |
101 | | // for ut and non-query. |
102 | 0 | void set_exec_env(ExecEnv* exec_env) { _exec_env = exec_env; } |
103 | | |
104 | | // for ut and non-query. |
105 | | void init_mem_trackers(const std::string& name = "ut", const TUniqueId& id = TUniqueId()); |
106 | | |
107 | 133 | const TQueryOptions& query_options() const { return _query_options; } |
108 | 0 | int64_t scan_queue_mem_limit() const { |
109 | 0 | return _query_options.__isset.scan_queue_mem_limit ? _query_options.scan_queue_mem_limit |
110 | 0 | : _query_options.mem_limit / 20; |
111 | 0 | } |
112 | 0 | int64_t query_mem_limit() const { |
113 | 0 | if (_query_options.__isset.mem_limit && (_query_options.mem_limit > 0)) { |
114 | 0 | return _query_options.mem_limit; |
115 | 0 | } |
116 | 0 | return 0; |
117 | 0 | } |
118 | | |
119 | 10 | ObjectPool* obj_pool() const { return _obj_pool.get(); } |
120 | | |
121 | 54 | const DescriptorTbl& desc_tbl() const { return *_desc_tbl; } |
122 | 24 | void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; } |
123 | 25 | int batch_size() const { return _query_options.batch_size; } |
124 | 0 | int wait_full_block_schedule_times() const { |
125 | 0 | return _query_options.wait_full_block_schedule_times; |
126 | 0 | } |
127 | 0 | bool abort_on_error() const { return _query_options.abort_on_error; } |
128 | 0 | bool abort_on_default_limit_exceeded() const { |
129 | 0 | return _query_options.abort_on_default_limit_exceeded; |
130 | 0 | } |
131 | 0 | int query_parallel_instance_num() const { return _query_options.parallel_instance; } |
132 | 0 | int max_errors() const { return _query_options.max_errors; } |
133 | 20 | int execution_timeout() const { |
134 | 20 | return _query_options.__isset.execution_timeout ? _query_options.execution_timeout |
135 | 20 | : _query_options.query_timeout; |
136 | 20 | } |
137 | 0 | int max_io_buffers() const { return _query_options.max_io_buffers; } |
138 | 0 | int num_scanner_threads() const { |
139 | 0 | return _query_options.__isset.num_scanner_threads ? _query_options.num_scanner_threads : 0; |
140 | 0 | } |
141 | 0 | double scanner_scale_up_ratio() const { |
142 | 0 | return _query_options.__isset.scanner_scale_up_ratio ? _query_options.scanner_scale_up_ratio |
143 | 0 | : 0; |
144 | 0 | } |
145 | 3 | TQueryType::type query_type() const { return _query_options.query_type; } |
146 | 5 | int64_t timestamp_ms() const { return _timestamp_ms; } |
147 | 5 | int32_t nano_seconds() const { return _nano_seconds; } |
148 | | // if possible, use timezone_obj() rather than timezone() |
149 | 5 | const std::string& timezone() const { return _timezone; } |
150 | 2 | const cctz::time_zone& timezone_obj() const { return _timezone_obj; } |
151 | 0 | const std::string& user() const { return _user; } |
152 | 5 | const TUniqueId& query_id() const { return _query_id; } |
153 | 2 | const TUniqueId& fragment_instance_id() const { return _fragment_instance_id; } |
154 | | // should only be called in pipeline engine |
155 | 0 | int32_t fragment_id() const { return _fragment_id; } |
156 | 23 | ExecEnv* exec_env() { return _exec_env; } |
157 | | std::shared_ptr<MemTrackerLimiter> query_mem_tracker() const; |
158 | | |
159 | | // Returns runtime state profile |
160 | 9 | RuntimeProfile* runtime_profile() { return &_profile; } |
161 | 0 | RuntimeProfile* load_channel_profile() { return &_load_channel_profile; } |
162 | | |
163 | 0 | bool enable_function_pushdown() const { |
164 | 0 | return _query_options.__isset.enable_function_pushdown && |
165 | 0 | _query_options.enable_function_pushdown; |
166 | 0 | } |
167 | | |
168 | 47 | bool check_overflow_for_decimal() const { |
169 | 47 | return _query_options.__isset.check_overflow_for_decimal && |
170 | 47 | _query_options.check_overflow_for_decimal; |
171 | 47 | } |
172 | | |
173 | 58 | bool enable_decimal256() const { |
174 | 58 | return _query_options.__isset.enable_decimal256 && _query_options.enable_decimal256; |
175 | 58 | } |
176 | | |
177 | 0 | bool enable_common_expr_pushdown() const { |
178 | 0 | return _query_options.__isset.enable_common_expr_pushdown && |
179 | 0 | _query_options.enable_common_expr_pushdown; |
180 | 0 | } |
181 | | |
182 | 0 | bool mysql_row_binary_format() const { |
183 | 0 | return _query_options.__isset.mysql_row_binary_format && |
184 | 0 | _query_options.mysql_row_binary_format; |
185 | 0 | } |
186 | | Status query_status(); |
187 | | |
188 | | // Appends error to the _error_log if there is space |
189 | | bool log_error(const std::string& error); |
190 | | |
191 | | // Returns true if the error log has not reached _max_errors. |
192 | 0 | bool log_has_space() { |
193 | 0 | std::lock_guard<std::mutex> l(_error_log_lock); |
194 | 0 | return _error_log.size() < _query_options.max_errors; |
195 | 0 | } |
196 | | |
197 | | // Append all _error_log[_unreported_error_idx+] to new_errors and set |
198 | | // _unreported_error_idx to _errors_log.size() |
199 | | void get_unreported_errors(std::vector<std::string>* new_errors); |
200 | | |
201 | | [[nodiscard]] bool is_cancelled() const; |
202 | | std::string cancel_reason() const; |
203 | 0 | int codegen_level() const { return _query_options.codegen_level; } |
204 | 0 | void set_is_cancelled(std::string msg) { |
205 | 0 | if (!_is_cancelled.exchange(true)) { |
206 | 0 | _cancel_reason = msg; |
207 | | // Create a error status, so that we could print error stack, and |
208 | | // we could know which path call cancel. |
209 | 0 | LOG(WARNING) << "Task is cancelled, instance: " |
210 | 0 | << PrintInstanceStandardInfo(_query_id, _fragment_instance_id) |
211 | 0 | << ", st = " << Status::Error<ErrorCode::CANCELLED>(msg); |
212 | 0 | } else { |
213 | 0 | LOG(WARNING) << "Task is already cancelled, instance: " |
214 | 0 | << PrintInstanceStandardInfo(_query_id, _fragment_instance_id) |
215 | 0 | << ", original cancel msg: " << _cancel_reason |
216 | 0 | << ", new cancel msg: " << Status::Error<ErrorCode::CANCELLED>(msg); |
217 | 0 | } |
218 | 0 | } |
219 | | |
220 | 0 | void set_backend_id(int64_t backend_id) { _backend_id = backend_id; } |
221 | 0 | int64_t backend_id() const { return _backend_id; } |
222 | | |
223 | 0 | void set_be_number(int be_number) { _be_number = be_number; } |
224 | 0 | int be_number(void) const { return _be_number; } |
225 | | |
226 | | // Sets _process_status with err_msg if no error has been set yet. |
227 | 0 | void set_process_status(const std::string& err_msg) { |
228 | 0 | std::lock_guard<std::mutex> l(_process_status_lock); |
229 | 0 | if (!_process_status.ok()) { |
230 | 0 | return; |
231 | 0 | } |
232 | 0 | _process_status = Status::InternalError(err_msg); |
233 | 0 | } |
234 | | |
235 | 0 | void set_process_status(const Status& status) { |
236 | 0 | if (status.ok()) { |
237 | 0 | return; |
238 | 0 | } |
239 | 0 | std::lock_guard<std::mutex> l(_process_status_lock); |
240 | 0 | if (!_process_status.ok()) { |
241 | 0 | return; |
242 | 0 | } |
243 | 0 | _process_status = status; |
244 | 0 | } |
245 | | |
246 | | // Sets _process_status to MEM_LIMIT_EXCEEDED. |
247 | | // Subsequent calls to this will be no-ops. Returns _process_status. |
248 | | // If 'msg' is non-nullptr, it will be appended to query_status_ in addition to the |
249 | | // generic "Memory limit exceeded" error. |
250 | | Status set_mem_limit_exceeded(const std::string& msg = "Memory limit exceeded"); |
251 | | |
252 | 0 | std::vector<std::string>& output_files() { return _output_files; } |
253 | | |
254 | 0 | void set_import_label(const std::string& import_label) { _import_label = import_label; } |
255 | | |
256 | 0 | const std::vector<std::string>& export_output_files() const { return _export_output_files; } |
257 | | |
258 | 0 | void add_export_output_file(const std::string& file) { _export_output_files.push_back(file); } |
259 | | |
260 | 0 | void set_db_name(const std::string& db_name) { _db_name = db_name; } |
261 | | |
262 | 0 | const std::string& db_name() { return _db_name; } |
263 | | |
264 | 0 | void set_wal_id(int64_t wal_id) { _wal_id = wal_id; } |
265 | | |
266 | 3 | int64_t wal_id() const { return _wal_id; } |
267 | | |
268 | 0 | void set_content_length(size_t content_length) { _content_length = content_length; } |
269 | | |
270 | 0 | size_t content_length() const { return _content_length; } |
271 | | |
272 | 0 | const std::string& import_label() { return _import_label; } |
273 | | |
274 | 0 | const std::string& load_dir() const { return _load_dir; } |
275 | | |
276 | 0 | void set_load_job_id(int64_t job_id) { _load_job_id = job_id; } |
277 | | |
278 | 5 | int64_t load_job_id() const { return _load_job_id; } |
279 | | |
280 | 0 | const std::string get_error_log_file_path() const { return _error_log_file_path; } |
281 | | |
282 | | // append error msg and error line to file when loading data. |
283 | | // is_summary is true, means we are going to write the summary line |
284 | | // If we need to stop the processing, set stop_processing to true |
285 | | Status append_error_msg_to_file(std::function<std::string()> line, |
286 | | std::function<std::string()> error_msg, bool* stop_processing, |
287 | | bool is_summary = false); |
288 | | |
289 | 0 | int64_t num_bytes_load_total() { return _num_bytes_load_total.load(); } |
290 | | |
291 | 0 | int64_t num_finished_range() { return _num_finished_scan_range.load(); } |
292 | | |
293 | 0 | int64_t num_rows_load_total() { return _num_rows_load_total.load(); } |
294 | | |
295 | 7 | int64_t num_rows_load_filtered() { return _num_rows_load_filtered.load(); } |
296 | | |
297 | 4 | int64_t num_rows_load_unselected() { return _num_rows_load_unselected.load(); } |
298 | | |
299 | 8 | int64_t num_rows_filtered_in_strict_mode_partial_update() { |
300 | 8 | return _num_rows_filtered_in_strict_mode_partial_update; |
301 | 8 | } |
302 | | |
303 | 0 | int64_t num_rows_load_success() { |
304 | 0 | return num_rows_load_total() - num_rows_load_filtered() - num_rows_load_unselected(); |
305 | 0 | } |
306 | | |
307 | 7 | void update_num_rows_load_total(int64_t num_rows) { _num_rows_load_total.fetch_add(num_rows); } |
308 | | |
309 | 4 | void set_num_rows_load_total(int64_t num_rows) { _num_rows_load_total.store(num_rows); } |
310 | | |
311 | 7 | void update_num_bytes_load_total(int64_t bytes_load) { |
312 | 7 | _num_bytes_load_total.fetch_add(bytes_load); |
313 | 7 | } |
314 | | |
315 | 2 | void update_num_finished_scan_range(int64_t finished_range) { |
316 | 2 | _num_finished_scan_range.fetch_add(finished_range); |
317 | 2 | } |
318 | | |
319 | 4 | void update_num_rows_load_filtered(int64_t num_rows) { |
320 | 4 | _num_rows_load_filtered.fetch_add(num_rows); |
321 | 4 | } |
322 | | |
323 | 4 | void update_num_rows_load_unselected(int64_t num_rows) { |
324 | 4 | _num_rows_load_unselected.fetch_add(num_rows); |
325 | 4 | } |
326 | | |
327 | 0 | void set_num_rows_filtered_in_strict_mode_partial_update(int64_t num_rows) { |
328 | 0 | _num_rows_filtered_in_strict_mode_partial_update = num_rows; |
329 | 0 | } |
330 | | |
331 | 0 | void set_per_fragment_instance_idx(int idx) { _per_fragment_instance_idx = idx; } |
332 | | |
333 | 5 | int per_fragment_instance_idx() const { return _per_fragment_instance_idx; } |
334 | | |
335 | 0 | void set_num_per_fragment_instances(int num_instances) { |
336 | 0 | _num_per_fragment_instances = num_instances; |
337 | 0 | } |
338 | | |
339 | 5 | int num_per_fragment_instances() const { return _num_per_fragment_instances; } |
340 | | |
341 | 0 | void set_load_stream_per_node(int load_stream_per_node) { |
342 | 0 | _load_stream_per_node = load_stream_per_node; |
343 | 0 | } |
344 | | |
345 | 0 | int load_stream_per_node() const { return _load_stream_per_node; } |
346 | | |
347 | 0 | void set_total_load_streams(int total_load_streams) { |
348 | 0 | _total_load_streams = total_load_streams; |
349 | 0 | } |
350 | | |
351 | 0 | int total_load_streams() const { return _total_load_streams; } |
352 | | |
353 | 0 | void set_num_local_sink(int num_local_sink) { _num_local_sink = num_local_sink; } |
354 | | |
355 | 0 | int num_local_sink() const { return _num_local_sink; } |
356 | | |
357 | 0 | bool disable_stream_preaggregations() const { |
358 | 0 | return _query_options.disable_stream_preaggregations; |
359 | 0 | } |
360 | | |
361 | 0 | bool enable_spill() const { return _query_options.enable_spilling; } |
362 | | |
363 | 0 | int32_t runtime_filter_wait_time_ms() const { |
364 | 0 | return _query_options.runtime_filter_wait_time_ms; |
365 | 0 | } |
366 | | |
367 | 0 | bool runtime_filter_wait_infinitely() const { |
368 | 0 | return _query_options.__isset.runtime_filter_wait_infinitely && |
369 | 0 | _query_options.runtime_filter_wait_infinitely; |
370 | 0 | } |
371 | | |
372 | 0 | int32_t runtime_filter_max_in_num() const { return _query_options.runtime_filter_max_in_num; } |
373 | | |
374 | 53 | int be_exec_version() const { |
375 | 53 | if (!_query_options.__isset.be_exec_version) { |
376 | 0 | return 0; |
377 | 0 | } |
378 | 53 | return _query_options.be_exec_version; |
379 | 53 | } |
380 | 12 | bool enable_pipeline_exec() const { |
381 | 12 | return _query_options.__isset.enable_pipeline_engine && |
382 | 12 | _query_options.enable_pipeline_engine; |
383 | 12 | } |
384 | 0 | bool enable_pipeline_x_exec() const { |
385 | 0 | return _query_options.__isset.enable_pipeline_x_engine && |
386 | 0 | _query_options.enable_pipeline_x_engine; |
387 | 0 | } |
388 | 0 | bool enable_local_shuffle() const { |
389 | 0 | return _query_options.__isset.enable_local_shuffle && _query_options.enable_local_shuffle; |
390 | 0 | } |
391 | | |
392 | 0 | bool trim_tailing_spaces_for_external_table_query() const { |
393 | 0 | return _query_options.trim_tailing_spaces_for_external_table_query; |
394 | 0 | } |
395 | | |
396 | 0 | bool return_object_data_as_binary() const { |
397 | 0 | return _query_options.return_object_data_as_binary; |
398 | 0 | } |
399 | | |
400 | 0 | bool enable_exchange_node_parallel_merge() const { |
401 | 0 | return _query_options.enable_enable_exchange_node_parallel_merge; |
402 | 0 | } |
403 | | |
404 | 10 | segment_v2::CompressionTypePB fragement_transmission_compression_type() const { |
405 | 10 | if (_query_options.__isset.fragment_transmission_compression_codec) { |
406 | 0 | if (_query_options.fragment_transmission_compression_codec == "lz4") { |
407 | 0 | return segment_v2::CompressionTypePB::LZ4; |
408 | 0 | } else if (_query_options.fragment_transmission_compression_codec == "snappy") { |
409 | 0 | return segment_v2::CompressionTypePB::SNAPPY; |
410 | 0 | } else { |
411 | 0 | return segment_v2::CompressionTypePB::NO_COMPRESSION; |
412 | 0 | } |
413 | 0 | } |
414 | 10 | return segment_v2::CompressionTypePB::NO_COMPRESSION; |
415 | 10 | } |
416 | | |
417 | 0 | bool skip_storage_engine_merge() const { |
418 | 0 | return _query_options.__isset.skip_storage_engine_merge && |
419 | 0 | _query_options.skip_storage_engine_merge; |
420 | 0 | } |
421 | | |
422 | 0 | bool skip_delete_predicate() const { |
423 | 0 | return _query_options.__isset.skip_delete_predicate && _query_options.skip_delete_predicate; |
424 | 0 | } |
425 | | |
426 | 0 | bool skip_delete_bitmap() const { |
427 | 0 | return _query_options.__isset.skip_delete_bitmap && _query_options.skip_delete_bitmap; |
428 | 0 | } |
429 | | |
430 | 0 | bool skip_missing_version() const { |
431 | 0 | return _query_options.__isset.skip_missing_version && _query_options.skip_missing_version; |
432 | 0 | } |
433 | | |
434 | 0 | int64_t data_queue_max_blocks() const { |
435 | 0 | return _query_options.__isset.data_queue_max_blocks ? _query_options.data_queue_max_blocks |
436 | 0 | : 1; |
437 | 0 | } |
438 | | |
439 | | bool enable_page_cache() const; |
440 | | |
441 | 0 | int partitioned_hash_join_rows_threshold() const { |
442 | 0 | if (!_query_options.__isset.partitioned_hash_join_rows_threshold) { |
443 | 0 | return 0; |
444 | 0 | } |
445 | 0 | return _query_options.partitioned_hash_join_rows_threshold; |
446 | 0 | } |
447 | | |
448 | 0 | int partitioned_hash_agg_rows_threshold() const { |
449 | 0 | if (!_query_options.__isset.partitioned_hash_agg_rows_threshold) { |
450 | 0 | return 0; |
451 | 0 | } |
452 | 0 | return _query_options.partitioned_hash_agg_rows_threshold; |
453 | 0 | } |
454 | | |
455 | 0 | const std::vector<TTabletCommitInfo>& tablet_commit_infos() const { |
456 | 0 | return _tablet_commit_infos; |
457 | 0 | } |
458 | | |
459 | 16 | std::vector<TTabletCommitInfo>& tablet_commit_infos() { return _tablet_commit_infos; } |
460 | | |
461 | 0 | std::vector<THivePartitionUpdate>& hive_partition_updates() { return _hive_partition_updates; } |
462 | | |
463 | 0 | std::vector<TIcebergCommitData>& iceberg_commit_datas() { return _iceberg_commit_datas; } |
464 | | |
465 | 0 | const std::vector<TErrorTabletInfo>& error_tablet_infos() const { return _error_tablet_infos; } |
466 | | |
467 | 8 | std::vector<TErrorTabletInfo>& error_tablet_infos() { return _error_tablet_infos; } |
468 | | |
469 | | // local runtime filter mgr, the runtime filter do not have remote target or |
470 | | // not need local merge should regist here. the instance exec finish, the local |
471 | | // runtime filter mgr can release the memory of local runtime filter |
472 | 0 | RuntimeFilterMgr* local_runtime_filter_mgr() { |
473 | 0 | if (_pipeline_x_runtime_filter_mgr) { |
474 | 0 | return _pipeline_x_runtime_filter_mgr; |
475 | 0 | } else { |
476 | 0 | return _runtime_filter_mgr.get(); |
477 | 0 | } |
478 | 0 | } |
479 | | |
480 | | RuntimeFilterMgr* global_runtime_filter_mgr(); |
481 | | |
482 | 0 | void set_pipeline_x_runtime_filter_mgr(RuntimeFilterMgr* pipeline_x_runtime_filter_mgr) { |
483 | 0 | _pipeline_x_runtime_filter_mgr = pipeline_x_runtime_filter_mgr; |
484 | 0 | } |
485 | | |
486 | 5 | QueryContext* get_query_ctx() { return _query_ctx; } |
487 | | |
488 | 0 | void set_query_mem_tracker(const std::shared_ptr<MemTrackerLimiter>& tracker) { |
489 | 0 | _query_mem_tracker = tracker; |
490 | 0 | } |
491 | | |
492 | 5 | void set_query_options(const TQueryOptions& query_options) { _query_options = query_options; } |
493 | | |
494 | 15 | bool enable_profile() const { |
495 | 15 | return _query_options.__isset.enable_profile && _query_options.enable_profile; |
496 | 15 | } |
497 | | |
498 | 0 | bool enable_verbose_profile() const { |
499 | 0 | return enable_profile() && _query_options.__isset.enable_verbose_profile && |
500 | 0 | _query_options.enable_verbose_profile; |
501 | 0 | } |
502 | | |
503 | 0 | int rpc_verbose_profile_max_instance_count() const { |
504 | 0 | return _query_options.__isset.rpc_verbose_profile_max_instance_count |
505 | 0 | ? _query_options.rpc_verbose_profile_max_instance_count |
506 | 0 | : 0; |
507 | 0 | } |
508 | | |
509 | 0 | bool enable_scan_node_run_serial() const { |
510 | 0 | return _query_options.__isset.enable_scan_node_run_serial && |
511 | 0 | _query_options.enable_scan_node_run_serial; |
512 | 0 | } |
513 | | |
514 | 0 | bool enable_share_hash_table_for_broadcast_join() const { |
515 | 0 | return _query_options.__isset.enable_share_hash_table_for_broadcast_join && |
516 | 0 | _query_options.enable_share_hash_table_for_broadcast_join; |
517 | 0 | } |
518 | | |
519 | 0 | bool enable_hash_join_early_start_probe() const { |
520 | 0 | return _query_options.__isset.enable_hash_join_early_start_probe && |
521 | 0 | _query_options.enable_hash_join_early_start_probe; |
522 | 0 | } |
523 | | |
524 | 0 | bool enable_parallel_scan() const { |
525 | 0 | return _query_options.__isset.enable_parallel_scan && _query_options.enable_parallel_scan; |
526 | 0 | } |
527 | | |
528 | 0 | bool is_read_csv_empty_line_as_null() const { |
529 | 0 | return _query_options.__isset.read_csv_empty_line_as_null && |
530 | 0 | _query_options.read_csv_empty_line_as_null; |
531 | 0 | } |
532 | | |
533 | 0 | int parallel_scan_max_scanners_count() const { |
534 | 0 | return _query_options.__isset.parallel_scan_max_scanners_count |
535 | 0 | ? _query_options.parallel_scan_max_scanners_count |
536 | 0 | : 0; |
537 | 0 | } |
538 | | |
539 | 0 | int partition_topn_max_partitions() const { |
540 | 0 | return _query_options.__isset.partition_topn_max_partitions |
541 | 0 | ? _query_options.partition_topn_max_partitions |
542 | 0 | : 1024; |
543 | 0 | } |
544 | | |
545 | 0 | int partition_topn_per_partition_rows() const { |
546 | 0 | return _query_options.__isset.partition_topn_pre_partition_rows |
547 | 0 | ? _query_options.partition_topn_pre_partition_rows |
548 | 0 | : 1000; |
549 | 0 | } |
550 | | |
551 | 0 | int64_t parallel_scan_min_rows_per_scanner() const { |
552 | 0 | return _query_options.__isset.parallel_scan_min_rows_per_scanner |
553 | 0 | ? _query_options.parallel_scan_min_rows_per_scanner |
554 | 0 | : 0; |
555 | 0 | } |
556 | | |
557 | 12 | int repeat_max_num() const { |
558 | | #ifndef BE_TEST |
559 | | if (!_query_options.__isset.repeat_max_num) { |
560 | | return 10000; |
561 | | } |
562 | | return _query_options.repeat_max_num; |
563 | | #else |
564 | 12 | return 10; |
565 | 12 | #endif |
566 | 12 | } |
567 | | |
568 | 0 | int64_t external_sort_bytes_threshold() const { |
569 | 0 | if (_query_options.__isset.external_sort_bytes_threshold) { |
570 | 0 | return _query_options.external_sort_bytes_threshold; |
571 | 0 | } |
572 | 0 | return 0; |
573 | 0 | } |
574 | | |
575 | 0 | void set_be_exec_version(int32_t version) noexcept { _query_options.be_exec_version = version; } |
576 | | |
577 | 0 | int64_t external_agg_bytes_threshold() const { |
578 | 0 | return _query_options.__isset.external_agg_bytes_threshold |
579 | 0 | ? _query_options.external_agg_bytes_threshold |
580 | 0 | : 0; |
581 | 0 | } |
582 | | |
583 | 0 | void set_task(pipeline::PipelineXTask* task) { _task = task; } |
584 | | |
585 | 0 | pipeline::PipelineXTask* get_task() const { return _task; } |
586 | | |
587 | 0 | inline bool enable_delete_sub_pred_v2() const { |
588 | 0 | return _query_options.__isset.enable_delete_sub_predicate_v2 && |
589 | 0 | _query_options.enable_delete_sub_predicate_v2; |
590 | 0 | } |
591 | | |
592 | | using LocalState = doris::pipeline::PipelineXLocalStateBase; |
593 | | using SinkLocalState = doris::pipeline::PipelineXSinkLocalStateBase; |
594 | | // get result can return an error message, and we will only call it during the prepare. |
595 | | void emplace_local_state(int id, std::unique_ptr<LocalState> state); |
596 | | |
597 | | LocalState* get_local_state(int id); |
598 | | Result<LocalState*> get_local_state_result(int id); |
599 | | |
600 | | void emplace_sink_local_state(int id, std::unique_ptr<SinkLocalState> state); |
601 | | |
602 | | SinkLocalState* get_sink_local_state(); |
603 | | |
604 | | Result<SinkLocalState*> get_sink_local_state_result(); |
605 | | |
606 | | void resize_op_id_to_local_state(int operator_size); |
607 | | |
608 | 0 | auto& pipeline_id_to_profile() { return _pipeline_id_to_profile; } |
609 | | |
610 | 5 | void set_task_execution_context(std::shared_ptr<TaskExecutionContext> context) { |
611 | 5 | _task_execution_context_inited = true; |
612 | 5 | _task_execution_context = context; |
613 | 5 | } |
614 | | |
615 | 15 | std::weak_ptr<TaskExecutionContext> get_task_execution_context() { |
616 | 15 | CHECK(_task_execution_context_inited) |
617 | 0 | << "_task_execution_context_inited == false, the ctx is not inited"; |
618 | 15 | return _task_execution_context; |
619 | 15 | } |
620 | | |
621 | | Status register_producer_runtime_filter(const doris::TRuntimeFilterDesc& desc, |
622 | | bool need_local_merge, |
623 | | doris::IRuntimeFilter** producer_filter, |
624 | | bool build_bf_exactly); |
625 | | |
626 | | Status register_consumer_runtime_filter(const doris::TRuntimeFilterDesc& desc, |
627 | | bool need_local_merge, int node_id, |
628 | | doris::IRuntimeFilter** producer_filter); |
629 | | bool is_nereids() const; |
630 | | |
631 | 0 | bool enable_join_spill() const { |
632 | 0 | return (_query_options.__isset.enable_force_spill && _query_options.enable_force_spill) || |
633 | 0 | (_query_options.__isset.enable_join_spill && _query_options.enable_join_spill); |
634 | 0 | } |
635 | | |
636 | 0 | bool enable_sort_spill() const { |
637 | 0 | return (_query_options.__isset.enable_force_spill && _query_options.enable_force_spill) || |
638 | 0 | (_query_options.__isset.enable_sort_spill && _query_options.enable_sort_spill); |
639 | 0 | } |
640 | | |
641 | 0 | bool enable_agg_spill() const { |
642 | 0 | return (_query_options.__isset.enable_force_spill && _query_options.enable_force_spill) || |
643 | 0 | (_query_options.__isset.enable_agg_spill && _query_options.enable_agg_spill); |
644 | 0 | } |
645 | | |
646 | 0 | bool enable_force_spill() const { |
647 | 0 | return _query_options.__isset.enable_force_spill && _query_options.enable_force_spill; |
648 | 0 | } |
649 | | |
650 | 0 | int64_t min_revocable_mem() const { |
651 | 0 | if (_query_options.__isset.min_revocable_mem) { |
652 | 0 | return _query_options.min_revocable_mem; |
653 | 0 | } |
654 | 0 | return 0; |
655 | 0 | } |
656 | | |
657 | 0 | void set_max_operator_id(int max_operator_id) { _max_operator_id = max_operator_id; } |
658 | | |
659 | 0 | int max_operator_id() const { return _max_operator_id; } |
660 | | |
661 | 0 | void set_task_id(int id) { _task_id = id; } |
662 | | |
663 | 0 | int task_id() const { return _task_id; } |
664 | | |
665 | 0 | void set_task_num(int task_num) { _task_num = task_num; } |
666 | | |
667 | 0 | int task_num() const { return _task_num; } |
668 | | |
669 | 0 | vectorized::ColumnInt64* partial_update_auto_inc_column() { |
670 | 0 | return _partial_update_auto_inc_column; |
671 | 0 | }; |
672 | | |
673 | | private: |
674 | | Status create_error_log_file(); |
675 | | |
676 | | static const int DEFAULT_BATCH_SIZE = 4062; |
677 | | |
678 | | std::shared_ptr<MemTrackerLimiter> _query_mem_tracker = nullptr; |
679 | | |
680 | | // Could not find a better way to record if the weak ptr is inited, use a bool to record |
681 | | // it. In some unit test cases, the runtime state's task ctx is not inited, then the test |
682 | | // hang, it is very hard to debug. |
683 | | bool _task_execution_context_inited = false; |
684 | | // Hold execution context for other threads |
685 | | std::weak_ptr<TaskExecutionContext> _task_execution_context; |
686 | | |
687 | | // put runtime state before _obj_pool, so that it will be deconstructed after |
688 | | // _obj_pool. Because some of object in _obj_pool will use profile when deconstructing. |
689 | | RuntimeProfile _profile; |
690 | | RuntimeProfile _load_channel_profile; |
691 | | |
692 | | const DescriptorTbl* _desc_tbl = nullptr; |
693 | | std::shared_ptr<ObjectPool> _obj_pool; |
694 | | |
695 | | // runtime filter |
696 | | std::unique_ptr<RuntimeFilterMgr> _runtime_filter_mgr; |
697 | | |
698 | | // owned by PipelineXFragmentContext |
699 | | RuntimeFilterMgr* _pipeline_x_runtime_filter_mgr = nullptr; |
700 | | |
701 | | // Data stream receivers created by a plan fragment are gathered here to make sure |
702 | | // they are destroyed before _obj_pool (class members are destroyed in reverse order). |
703 | | // Receivers depend on the descriptor table and we need to guarantee that their control |
704 | | // blocks are removed from the data stream manager before the objects in the |
705 | | // descriptor table are destroyed. |
706 | | std::unique_ptr<ObjectPool> _data_stream_recvrs_pool; |
707 | | |
708 | | // Lock protecting _error_log and _unreported_error_idx |
709 | | std::mutex _error_log_lock; |
710 | | |
711 | | // Logs error messages. |
712 | | std::vector<std::string> _error_log; |
713 | | |
714 | | // _error_log[_unreported_error_idx+] has been not reported to the coordinator. |
715 | | int _unreported_error_idx; |
716 | | |
717 | | // Username of user that is executing the query to which this RuntimeState belongs. |
718 | | std::string _user; |
719 | | |
720 | | //Query-global timestamp_ms |
721 | | int64_t _timestamp_ms; |
722 | | int32_t _nano_seconds; |
723 | | std::string _timezone; |
724 | | cctz::time_zone _timezone_obj; |
725 | | |
726 | | TUniqueId _query_id; |
727 | | // fragment id for each TPipelineFragmentParams |
728 | | int32_t _fragment_id; |
729 | | TUniqueId _fragment_instance_id; |
730 | | TQueryOptions _query_options; |
731 | | ExecEnv* _exec_env = nullptr; |
732 | | |
733 | | // if true, execution should stop with a CANCELLED status |
734 | | std::atomic<bool> _is_cancelled; |
735 | | std::string _cancel_reason; |
736 | | |
737 | | int _per_fragment_instance_idx; |
738 | | int _num_per_fragment_instances = 0; |
739 | | int _load_stream_per_node = 0; |
740 | | int _total_load_streams = 0; |
741 | | int _num_local_sink = 0; |
742 | | |
743 | | // The backend id on which this fragment instance runs |
744 | | int64_t _backend_id = -1; |
745 | | |
746 | | // used as send id |
747 | | int _be_number; |
748 | | |
749 | | // Non-OK if an error has occurred and query execution should abort. Used only for |
750 | | // asynchronously reporting such errors (e.g., when a UDF reports an error), so this |
751 | | // will not necessarily be set in all error cases. |
752 | | std::mutex _process_status_lock; |
753 | | Status _process_status; |
754 | | |
755 | | // put here to collect files?? |
756 | | std::vector<std::string> _output_files; |
757 | | std::atomic<int64_t> _num_rows_load_total; // total rows read from source |
758 | | std::atomic<int64_t> _num_rows_load_filtered; // unqualified rows |
759 | | std::atomic<int64_t> _num_rows_load_unselected; // rows filtered by predicates |
760 | | std::atomic<int64_t> _num_rows_filtered_in_strict_mode_partial_update; |
761 | | std::atomic<int64_t> _num_print_error_rows; |
762 | | |
763 | | std::atomic<int64_t> _num_bytes_load_total; // total bytes read from source |
764 | | std::atomic<int64_t> _num_finished_scan_range; |
765 | | |
766 | | std::vector<std::string> _export_output_files; |
767 | | std::string _import_label; |
768 | | std::string _db_name; |
769 | | std::string _load_dir; |
770 | | int64_t _load_job_id; |
771 | | int64_t _wal_id = -1; |
772 | | size_t _content_length = 0; |
773 | | |
774 | | // mini load |
775 | | int64_t _normal_row_number; |
776 | | int64_t _error_row_number; |
777 | | std::string _error_log_file_path; |
778 | | std::ofstream* _error_log_file = nullptr; // error file path, absolute path |
779 | | std::vector<TTabletCommitInfo> _tablet_commit_infos; |
780 | | std::vector<TErrorTabletInfo> _error_tablet_infos; |
781 | | int _max_operator_id = 0; |
782 | | int _task_id = -1; |
783 | | int _task_num = 0; |
784 | | |
785 | | std::vector<THivePartitionUpdate> _hive_partition_updates; |
786 | | |
787 | | std::vector<TIcebergCommitData> _iceberg_commit_datas; |
788 | | |
789 | | std::vector<std::unique_ptr<doris::pipeline::PipelineXLocalStateBase>> _op_id_to_local_state; |
790 | | |
791 | | std::unique_ptr<doris::pipeline::PipelineXSinkLocalStateBase> _sink_local_state; |
792 | | |
793 | | QueryContext* _query_ctx = nullptr; |
794 | | |
795 | | // true if max_filter_ratio is 0 |
796 | | bool _load_zero_tolerance = false; |
797 | | |
798 | | std::vector<std::unique_ptr<RuntimeProfile>> _pipeline_id_to_profile; |
799 | | |
800 | | // prohibit copies |
801 | | RuntimeState(const RuntimeState&); |
802 | | |
803 | | pipeline::PipelineXTask* _task; |
804 | | vectorized::ColumnInt64* _partial_update_auto_inc_column; |
805 | | }; |
806 | | |
807 | | #define RETURN_IF_CANCELLED(state) \ |
808 | 7 | do { \ |
809 | 7 | if (UNLIKELY((state)->is_cancelled())) return Status::Cancelled("Cancelled"); \ |
810 | 7 | } while (false) |
811 | | |
812 | | } // namespace doris |