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