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