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