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