/root/doris/be/src/runtime/runtime_state.cpp
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.cpp |
19 | | // and modified by Doris |
20 | | |
21 | | #include "runtime/runtime_state.h" |
22 | | |
23 | | #include <fmt/format.h> |
24 | | #include <gen_cpp/PaloInternalService_types.h> |
25 | | #include <gen_cpp/Types_types.h> |
26 | | #include <glog/logging.h> |
27 | | |
28 | | #include <memory> |
29 | | #include <string> |
30 | | |
31 | | #include "common/config.h" |
32 | | #include "common/logging.h" |
33 | | #include "common/object_pool.h" |
34 | | #include "common/status.h" |
35 | | #include "pipeline/exec/operator.h" |
36 | | #include "pipeline/pipeline_x/operator.h" |
37 | | #include "pipeline/pipeline_x/pipeline_x_task.h" |
38 | | #include "runtime/exec_env.h" |
39 | | #include "runtime/load_path_mgr.h" |
40 | | #include "runtime/memory/mem_tracker_limiter.h" |
41 | | #include "runtime/memory/thread_mem_tracker_mgr.h" |
42 | | #include "runtime/query_context.h" |
43 | | #include "runtime/runtime_filter_mgr.h" |
44 | | #include "runtime/thread_context.h" |
45 | | #include "util/timezone_utils.h" |
46 | | #include "util/uid_util.h" |
47 | | #include "vec/runtime/vdatetime_value.h" |
48 | | |
49 | | namespace doris { |
50 | | using namespace ErrorCode; |
51 | | |
52 | | RuntimeState::RuntimeState(const TPlanFragmentExecParams& fragment_exec_params, |
53 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
54 | | ExecEnv* exec_env, QueryContext* ctx, |
55 | | const std::shared_ptr<MemTrackerLimiter>& query_mem_tracker) |
56 | | : _profile("Fragment " + print_id(fragment_exec_params.fragment_instance_id)), |
57 | | _load_channel_profile("<unnamed>"), |
58 | | _obj_pool(new ObjectPool()), |
59 | | _data_stream_recvrs_pool(new ObjectPool()), |
60 | | _unreported_error_idx(0), |
61 | | _query_id(fragment_exec_params.query_id), |
62 | | _is_cancelled(false), |
63 | | _per_fragment_instance_idx(0), |
64 | | _num_rows_load_total(0), |
65 | | _num_rows_load_filtered(0), |
66 | | _num_rows_load_unselected(0), |
67 | | _num_print_error_rows(0), |
68 | | _num_bytes_load_total(0), |
69 | | _num_finished_scan_range(0), |
70 | | _normal_row_number(0), |
71 | | _error_row_number(0), |
72 | | _error_log_file(nullptr), |
73 | 0 | _query_ctx(ctx) { |
74 | 0 | Status status = |
75 | 0 | init(fragment_exec_params.fragment_instance_id, query_options, query_globals, exec_env); |
76 | 0 | DCHECK(status.ok()); |
77 | 0 | if (query_mem_tracker != nullptr) { |
78 | 0 | _query_mem_tracker = query_mem_tracker; |
79 | 0 | } else { |
80 | 0 | DCHECK(ctx != nullptr); |
81 | 0 | _query_mem_tracker = ctx->query_mem_tracker; |
82 | 0 | } |
83 | 0 | #ifdef BE_TEST |
84 | 0 | if (_query_mem_tracker == nullptr) { |
85 | 0 | init_mem_trackers(); |
86 | 0 | } |
87 | 0 | #endif |
88 | 0 | DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan"); |
89 | 0 | if (ctx) { |
90 | 0 | _runtime_filter_mgr = std::make_unique<RuntimeFilterMgr>( |
91 | 0 | fragment_exec_params.query_id, RuntimeFilterParamsContext::create(this), |
92 | 0 | _query_mem_tracker); |
93 | 0 | } |
94 | 0 | if (fragment_exec_params.__isset.runtime_filter_params) { |
95 | 0 | _query_ctx->runtime_filter_mgr()->set_runtime_filter_params( |
96 | 0 | fragment_exec_params.runtime_filter_params); |
97 | 0 | } |
98 | |
|
99 | 0 | if (_query_ctx) { |
100 | 0 | if (fragment_exec_params.__isset.topn_filter_source_node_ids) { |
101 | 0 | _query_ctx->init_runtime_predicates(fragment_exec_params.topn_filter_source_node_ids); |
102 | 0 | } else { |
103 | 0 | _query_ctx->init_runtime_predicates({0}); |
104 | 0 | } |
105 | 0 | } |
106 | 0 | } |
107 | | |
108 | | RuntimeState::RuntimeState(const TUniqueId& instance_id, const TUniqueId& query_id, |
109 | | int32_t fragment_id, const TQueryOptions& query_options, |
110 | | const TQueryGlobals& query_globals, ExecEnv* exec_env, QueryContext* ctx) |
111 | | : _profile("Fragment " + print_id(instance_id)), |
112 | | _load_channel_profile("<unnamed>"), |
113 | | _obj_pool(new ObjectPool()), |
114 | | _data_stream_recvrs_pool(new ObjectPool()), |
115 | | _unreported_error_idx(0), |
116 | | _query_id(query_id), |
117 | | _fragment_id(fragment_id), |
118 | | _is_cancelled(false), |
119 | | _per_fragment_instance_idx(0), |
120 | | _num_rows_load_total(0), |
121 | | _num_rows_load_filtered(0), |
122 | | _num_rows_load_unselected(0), |
123 | | _num_rows_filtered_in_strict_mode_partial_update(0), |
124 | | _num_print_error_rows(0), |
125 | | _num_bytes_load_total(0), |
126 | | _num_finished_scan_range(0), |
127 | | _normal_row_number(0), |
128 | | _error_row_number(0), |
129 | | _error_log_file(nullptr), |
130 | 0 | _query_ctx(ctx) { |
131 | 0 | [[maybe_unused]] auto status = init(instance_id, query_options, query_globals, exec_env); |
132 | 0 | DCHECK(status.ok()); |
133 | 0 | _query_mem_tracker = ctx->query_mem_tracker; |
134 | 0 | #ifdef BE_TEST |
135 | 0 | if (_query_mem_tracker == nullptr) { |
136 | 0 | init_mem_trackers(); |
137 | 0 | } |
138 | 0 | #endif |
139 | 0 | DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan"); |
140 | 0 | _runtime_filter_mgr.reset(new RuntimeFilterMgr( |
141 | 0 | query_id, RuntimeFilterParamsContext::create(this), _query_mem_tracker)); |
142 | 0 | } |
143 | | |
144 | | RuntimeState::RuntimeState(pipeline::PipelineXFragmentContext*, const TUniqueId& instance_id, |
145 | | const TUniqueId& query_id, int32_t fragment_id, |
146 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
147 | | ExecEnv* exec_env, QueryContext* ctx) |
148 | | : _profile("Fragment " + print_id(instance_id)), |
149 | | _load_channel_profile("<unnamed>"), |
150 | | _obj_pool(new ObjectPool()), |
151 | | _runtime_filter_mgr(nullptr), |
152 | | _data_stream_recvrs_pool(new ObjectPool()), |
153 | | _unreported_error_idx(0), |
154 | | _query_id(query_id), |
155 | | _fragment_id(fragment_id), |
156 | | _is_cancelled(false), |
157 | | _per_fragment_instance_idx(0), |
158 | | _num_rows_load_total(0), |
159 | | _num_rows_load_filtered(0), |
160 | | _num_rows_load_unselected(0), |
161 | | _num_rows_filtered_in_strict_mode_partial_update(0), |
162 | | _num_print_error_rows(0), |
163 | | _num_bytes_load_total(0), |
164 | | _num_finished_scan_range(0), |
165 | | _normal_row_number(0), |
166 | | _error_row_number(0), |
167 | | _error_log_file(nullptr), |
168 | 0 | _query_ctx(ctx) { |
169 | 0 | [[maybe_unused]] auto status = init(instance_id, query_options, query_globals, exec_env); |
170 | 0 | _query_mem_tracker = ctx->query_mem_tracker; |
171 | 0 | #ifdef BE_TEST |
172 | 0 | if (_query_mem_tracker == nullptr) { |
173 | 0 | init_mem_trackers(); |
174 | 0 | } |
175 | 0 | #endif |
176 | 0 | DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan"); |
177 | 0 | DCHECK(status.ok()); |
178 | 0 | } |
179 | | |
180 | | RuntimeState::RuntimeState(const TUniqueId& query_id, int32_t fragment_id, |
181 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
182 | | ExecEnv* exec_env, QueryContext* ctx) |
183 | | : _profile("PipelineX " + std::to_string(fragment_id)), |
184 | | _load_channel_profile("<unnamed>"), |
185 | | _obj_pool(new ObjectPool()), |
186 | | _data_stream_recvrs_pool(new ObjectPool()), |
187 | | _unreported_error_idx(0), |
188 | | _query_id(query_id), |
189 | | _fragment_id(fragment_id), |
190 | | _is_cancelled(false), |
191 | | _per_fragment_instance_idx(0), |
192 | | _num_rows_load_total(0), |
193 | | _num_rows_load_filtered(0), |
194 | | _num_rows_load_unselected(0), |
195 | | _num_rows_filtered_in_strict_mode_partial_update(0), |
196 | | _num_print_error_rows(0), |
197 | | _num_bytes_load_total(0), |
198 | | _num_finished_scan_range(0), |
199 | | _normal_row_number(0), |
200 | | _error_row_number(0), |
201 | | _error_log_file(nullptr), |
202 | 0 | _query_ctx(ctx) { |
203 | | // TODO: do we really need instance id? |
204 | 0 | Status status = init(TUniqueId(), query_options, query_globals, exec_env); |
205 | 0 | DCHECK(status.ok()); |
206 | 0 | _query_mem_tracker = ctx->query_mem_tracker; |
207 | 0 | #ifdef BE_TEST |
208 | 0 | if (_query_mem_tracker == nullptr) { |
209 | 0 | init_mem_trackers(); |
210 | 0 | } |
211 | 0 | #endif |
212 | 0 | DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan"); |
213 | 0 | _runtime_filter_mgr.reset(new RuntimeFilterMgr( |
214 | 0 | query_id, RuntimeFilterParamsContext::create(this), _query_mem_tracker)); |
215 | 0 | } |
216 | | |
217 | | RuntimeState::RuntimeState(const TQueryGlobals& query_globals) |
218 | | : _profile("<unnamed>"), |
219 | | _load_channel_profile("<unnamed>"), |
220 | | _obj_pool(new ObjectPool()), |
221 | | _data_stream_recvrs_pool(new ObjectPool()), |
222 | | _unreported_error_idx(0), |
223 | | _is_cancelled(false), |
224 | 683 | _per_fragment_instance_idx(0) { |
225 | 683 | _query_options.batch_size = DEFAULT_BATCH_SIZE; |
226 | 683 | if (query_globals.__isset.time_zone && query_globals.__isset.nano_seconds) { |
227 | 0 | _timezone = query_globals.time_zone; |
228 | 0 | _timestamp_ms = query_globals.timestamp_ms; |
229 | 0 | _nano_seconds = query_globals.nano_seconds; |
230 | 683 | } else if (query_globals.__isset.time_zone) { |
231 | 663 | _timezone = query_globals.time_zone; |
232 | 663 | _timestamp_ms = query_globals.timestamp_ms; |
233 | 663 | _nano_seconds = 0; |
234 | 663 | } else if (!query_globals.now_string.empty()) { |
235 | 0 | _timezone = TimezoneUtils::default_time_zone; |
236 | 0 | VecDateTimeValue dt; |
237 | 0 | dt.from_date_str(query_globals.now_string.c_str(), query_globals.now_string.size()); |
238 | 0 | int64_t timestamp; |
239 | 0 | dt.unix_timestamp(×tamp, _timezone); |
240 | 0 | _timestamp_ms = timestamp * 1000; |
241 | 0 | _nano_seconds = 0; |
242 | 20 | } else { |
243 | | //Unit test may set into here |
244 | 20 | _timezone = TimezoneUtils::default_time_zone; |
245 | 20 | _timestamp_ms = 0; |
246 | 20 | _nano_seconds = 0; |
247 | 20 | } |
248 | 683 | TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj); |
249 | 683 | init_mem_trackers("<unnamed>"); |
250 | 683 | } |
251 | | |
252 | | RuntimeState::RuntimeState() |
253 | | : _profile("<unnamed>"), |
254 | | _load_channel_profile("<unnamed>"), |
255 | | _obj_pool(new ObjectPool()), |
256 | | _data_stream_recvrs_pool(new ObjectPool()), |
257 | | _unreported_error_idx(0), |
258 | | _is_cancelled(false), |
259 | 10 | _per_fragment_instance_idx(0) { |
260 | 10 | _query_options.batch_size = DEFAULT_BATCH_SIZE; |
261 | 10 | _timezone = TimezoneUtils::default_time_zone; |
262 | 10 | _timestamp_ms = 0; |
263 | 10 | _nano_seconds = 0; |
264 | 10 | TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj); |
265 | 10 | _exec_env = ExecEnv::GetInstance(); |
266 | 10 | init_mem_trackers("<unnamed>"); |
267 | 10 | } |
268 | | |
269 | 693 | RuntimeState::~RuntimeState() { |
270 | 693 | SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_query_mem_tracker); |
271 | | // close error log file |
272 | 693 | if (_error_log_file != nullptr && _error_log_file->is_open()) { |
273 | 0 | _error_log_file->close(); |
274 | 0 | delete _error_log_file; |
275 | 0 | _error_log_file = nullptr; |
276 | 0 | } |
277 | | |
278 | 693 | _obj_pool->clear(); |
279 | 693 | _runtime_filter_mgr.reset(); |
280 | 693 | } |
281 | | |
282 | | Status RuntimeState::init(const TUniqueId& fragment_instance_id, const TQueryOptions& query_options, |
283 | 2 | const TQueryGlobals& query_globals, ExecEnv* exec_env) { |
284 | 2 | _fragment_instance_id = fragment_instance_id; |
285 | 2 | _query_options = query_options; |
286 | 2 | if (query_globals.__isset.time_zone && query_globals.__isset.nano_seconds) { |
287 | 0 | _timezone = query_globals.time_zone; |
288 | 0 | _timestamp_ms = query_globals.timestamp_ms; |
289 | 0 | _nano_seconds = query_globals.nano_seconds; |
290 | 2 | } else if (query_globals.__isset.time_zone) { |
291 | 0 | _timezone = query_globals.time_zone; |
292 | 0 | _timestamp_ms = query_globals.timestamp_ms; |
293 | 0 | _nano_seconds = 0; |
294 | 2 | } else if (!query_globals.now_string.empty()) { |
295 | 0 | _timezone = TimezoneUtils::default_time_zone; |
296 | 0 | VecDateTimeValue dt; |
297 | 0 | dt.from_date_str(query_globals.now_string.c_str(), query_globals.now_string.size()); |
298 | 0 | int64_t timestamp; |
299 | 0 | dt.unix_timestamp(×tamp, _timezone); |
300 | 0 | _timestamp_ms = timestamp * 1000; |
301 | 0 | _nano_seconds = 0; |
302 | 2 | } else { |
303 | | //Unit test may set into here |
304 | 2 | _timezone = TimezoneUtils::default_time_zone; |
305 | 2 | _timestamp_ms = 0; |
306 | 2 | _nano_seconds = 0; |
307 | 2 | } |
308 | 2 | TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj); |
309 | | |
310 | 2 | if (query_globals.__isset.load_zero_tolerance) { |
311 | 2 | _load_zero_tolerance = query_globals.load_zero_tolerance; |
312 | 2 | } |
313 | | |
314 | 2 | _exec_env = exec_env; |
315 | | |
316 | 2 | if (_query_options.max_errors <= 0) { |
317 | | // TODO: fix linker error and uncomment this |
318 | | //_query_options.max_errors = config::max_errors; |
319 | 2 | _query_options.max_errors = 100; |
320 | 2 | } |
321 | | |
322 | 2 | if (_query_options.batch_size <= 0) { |
323 | 2 | _query_options.batch_size = DEFAULT_BATCH_SIZE; |
324 | 2 | } |
325 | | |
326 | 2 | _db_name = "insert_stmt"; |
327 | 2 | _import_label = print_id(fragment_instance_id); |
328 | | |
329 | 2 | return Status::OK(); |
330 | 2 | } |
331 | | |
332 | 693 | void RuntimeState::init_mem_trackers(const std::string& name, const TUniqueId& id) { |
333 | 693 | _query_mem_tracker = MemTrackerLimiter::create_shared( |
334 | 693 | MemTrackerLimiter::Type::OTHER, fmt::format("{}#Id={}", name, print_id(id))); |
335 | 693 | } |
336 | | |
337 | 0 | std::shared_ptr<MemTrackerLimiter> RuntimeState::query_mem_tracker() const { |
338 | 0 | CHECK(_query_mem_tracker != nullptr); |
339 | 0 | return _query_mem_tracker; |
340 | 0 | } |
341 | | |
342 | 0 | bool RuntimeState::log_error(const std::string& error) { |
343 | 0 | std::lock_guard<std::mutex> l(_error_log_lock); |
344 | |
|
345 | 0 | if (_error_log.size() < _query_options.max_errors) { |
346 | 0 | _error_log.push_back(error); |
347 | 0 | return true; |
348 | 0 | } |
349 | | |
350 | 0 | return false; |
351 | 0 | } |
352 | | |
353 | 0 | void RuntimeState::get_unreported_errors(std::vector<std::string>* new_errors) { |
354 | 0 | std::lock_guard<std::mutex> l(_error_log_lock); |
355 | |
|
356 | 0 | if (_unreported_error_idx < _error_log.size()) { |
357 | 0 | new_errors->assign(_error_log.begin() + _unreported_error_idx, _error_log.end()); |
358 | 0 | _unreported_error_idx = _error_log.size(); |
359 | 0 | } |
360 | 0 | } |
361 | | |
362 | 0 | Status RuntimeState::query_status() { |
363 | 0 | auto st = _query_ctx->exec_status(); |
364 | 0 | RETURN_IF_ERROR(st); |
365 | 0 | std::lock_guard<std::mutex> l(_process_status_lock); |
366 | 0 | return _process_status; |
367 | 0 | } |
368 | | |
369 | 47 | bool RuntimeState::is_cancelled() const { |
370 | | // Maybe we should just return _is_cancelled.load() |
371 | 47 | return _is_cancelled.load() || (_query_ctx && _query_ctx->is_cancelled()); |
372 | 47 | } |
373 | | |
374 | 0 | std::string RuntimeState::cancel_reason() const { |
375 | 0 | return _cancel_reason; |
376 | 0 | } |
377 | | |
378 | 0 | Status RuntimeState::set_mem_limit_exceeded(const std::string& msg) { |
379 | 0 | { |
380 | 0 | std::lock_guard<std::mutex> l(_process_status_lock); |
381 | 0 | if (_process_status.ok()) { |
382 | 0 | _process_status = Status::MemoryLimitExceeded(msg); |
383 | 0 | } |
384 | 0 | } |
385 | 0 | DCHECK(_process_status.is<MEM_LIMIT_EXCEEDED>()); |
386 | 0 | return _process_status; |
387 | 0 | } |
388 | | |
389 | | const int64_t MAX_ERROR_NUM = 50; |
390 | | |
391 | 0 | Status RuntimeState::create_error_log_file() { |
392 | 0 | static_cast<void>(_exec_env->load_path_mgr()->get_load_error_file_name( |
393 | 0 | _db_name, _import_label, _fragment_instance_id, &_error_log_file_path)); |
394 | 0 | std::string error_log_absolute_path = |
395 | 0 | _exec_env->load_path_mgr()->get_load_error_absolute_path(_error_log_file_path); |
396 | 0 | _error_log_file = new std::ofstream(error_log_absolute_path, std::ifstream::out); |
397 | 0 | if (!_error_log_file->is_open()) { |
398 | 0 | std::stringstream error_msg; |
399 | 0 | error_msg << "Fail to open error file: [" << _error_log_file_path << "]."; |
400 | 0 | LOG(WARNING) << error_msg.str(); |
401 | 0 | return Status::InternalError(error_msg.str()); |
402 | 0 | } |
403 | 0 | VLOG_FILE << "create error log file: " << _error_log_file_path; |
404 | |
|
405 | 0 | return Status::OK(); |
406 | 0 | } |
407 | | |
408 | | Status RuntimeState::append_error_msg_to_file(std::function<std::string()> line, |
409 | | std::function<std::string()> error_msg, |
410 | 3 | bool* stop_processing, bool is_summary) { |
411 | 3 | *stop_processing = false; |
412 | 3 | if (query_type() != TQueryType::LOAD) { |
413 | 3 | return Status::OK(); |
414 | 3 | } |
415 | | // If file haven't been opened, open it here |
416 | 0 | if (_error_log_file == nullptr) { |
417 | 0 | Status status = create_error_log_file(); |
418 | 0 | if (!status.ok()) { |
419 | 0 | LOG(WARNING) << "Create error file log failed. because: " << status; |
420 | 0 | if (_error_log_file != nullptr) { |
421 | 0 | _error_log_file->close(); |
422 | 0 | delete _error_log_file; |
423 | 0 | _error_log_file = nullptr; |
424 | 0 | } |
425 | 0 | return status; |
426 | 0 | } |
427 | 0 | } |
428 | | |
429 | | // if num of printed error row exceeds the limit, and this is not a summary message, |
430 | | // if _load_zero_tolerance, return Error to stop the load process immediately. |
431 | 0 | if (_num_print_error_rows.fetch_add(1, std::memory_order_relaxed) > MAX_ERROR_NUM && |
432 | 0 | !is_summary) { |
433 | 0 | if (_load_zero_tolerance) { |
434 | 0 | *stop_processing = true; |
435 | 0 | } |
436 | 0 | return Status::OK(); |
437 | 0 | } |
438 | | |
439 | 0 | fmt::memory_buffer out; |
440 | 0 | if (is_summary) { |
441 | 0 | fmt::format_to(out, "Summary: {}", error_msg()); |
442 | 0 | } else { |
443 | 0 | if (_error_row_number < MAX_ERROR_NUM) { |
444 | | // Note: export reason first in case src line too long and be truncated. |
445 | 0 | fmt::format_to(out, "Reason: {}. src line [{}]; ", error_msg(), line()); |
446 | 0 | } else if (_error_row_number == MAX_ERROR_NUM) { |
447 | 0 | fmt::format_to(out, "TOO MUCH ERROR! already reach {}. show no more next error.", |
448 | 0 | MAX_ERROR_NUM); |
449 | 0 | } |
450 | 0 | } |
451 | |
|
452 | 0 | size_t error_row_size = out.size(); |
453 | 0 | if (error_row_size > 0) { |
454 | 0 | if (error_row_size > config::load_error_log_limit_bytes) { |
455 | 0 | fmt::memory_buffer limit_byte_out; |
456 | 0 | limit_byte_out.append(out.data(), out.data() + config::load_error_log_limit_bytes); |
457 | 0 | (*_error_log_file) << fmt::to_string(limit_byte_out) + "error log is too long" |
458 | 0 | << std::endl; |
459 | 0 | } else { |
460 | 0 | (*_error_log_file) << fmt::to_string(out) << std::endl; |
461 | 0 | } |
462 | 0 | } |
463 | 0 | return Status::OK(); |
464 | 0 | } |
465 | | |
466 | 0 | void RuntimeState::resize_op_id_to_local_state(int operator_size) { |
467 | 0 | _op_id_to_local_state.resize(-operator_size); |
468 | 0 | } |
469 | | |
470 | | void RuntimeState::emplace_local_state( |
471 | 0 | int id, std::unique_ptr<doris::pipeline::PipelineXLocalStateBase> state) { |
472 | 0 | id = -id; |
473 | 0 | DCHECK(id < _op_id_to_local_state.size()); |
474 | 0 | DCHECK(!_op_id_to_local_state[id]); |
475 | 0 | _op_id_to_local_state[id] = std::move(state); |
476 | 0 | } |
477 | | |
478 | 0 | doris::pipeline::PipelineXLocalStateBase* RuntimeState::get_local_state(int id) { |
479 | 0 | id = -id; |
480 | 0 | return _op_id_to_local_state[id].get(); |
481 | 0 | } |
482 | | |
483 | 0 | Result<RuntimeState::LocalState*> RuntimeState::get_local_state_result(int id) { |
484 | 0 | id = -id; |
485 | 0 | if (id >= _op_id_to_local_state.size()) { |
486 | 0 | return ResultError(Status::InternalError("get_local_state out of range size:{} , id:{}", |
487 | 0 | _op_id_to_local_state.size(), id)); |
488 | 0 | } |
489 | 0 | if (!_op_id_to_local_state[id]) { |
490 | 0 | return ResultError(Status::InternalError("get_local_state id:{} is null", id)); |
491 | 0 | } |
492 | 0 | return _op_id_to_local_state[id].get(); |
493 | 0 | }; |
494 | | |
495 | | void RuntimeState::emplace_sink_local_state( |
496 | 0 | int id, std::unique_ptr<doris::pipeline::PipelineXSinkLocalStateBase> state) { |
497 | 0 | DCHECK(!_sink_local_state) << " id=" << id << " state: " << state->debug_string(0); |
498 | 0 | _sink_local_state = std::move(state); |
499 | 0 | } |
500 | | |
501 | 0 | doris::pipeline::PipelineXSinkLocalStateBase* RuntimeState::get_sink_local_state() { |
502 | 0 | return _sink_local_state.get(); |
503 | 0 | } |
504 | | |
505 | 0 | Result<RuntimeState::SinkLocalState*> RuntimeState::get_sink_local_state_result() { |
506 | 0 | if (!_sink_local_state) { |
507 | 0 | return ResultError(Status::InternalError("_op_id_to_sink_local_state not exist")); |
508 | 0 | } |
509 | 0 | return _sink_local_state.get(); |
510 | 0 | } |
511 | | |
512 | 0 | bool RuntimeState::enable_page_cache() const { |
513 | 0 | return !config::disable_storage_page_cache && |
514 | 0 | (_query_options.__isset.enable_page_cache && _query_options.enable_page_cache); |
515 | 0 | } |
516 | | |
517 | 0 | RuntimeFilterMgr* RuntimeState::global_runtime_filter_mgr() { |
518 | 0 | return _query_ctx->runtime_filter_mgr(); |
519 | 0 | } |
520 | | |
521 | | Status RuntimeState::register_producer_runtime_filter(const doris::TRuntimeFilterDesc& desc, |
522 | | bool need_local_merge, |
523 | | doris::IRuntimeFilter** producer_filter, |
524 | 0 | bool build_bf_exactly) { |
525 | 0 | if (desc.has_remote_targets || need_local_merge) { |
526 | 0 | return global_runtime_filter_mgr()->register_local_merge_producer_filter( |
527 | 0 | desc, query_options(), producer_filter, build_bf_exactly); |
528 | 0 | } else { |
529 | 0 | return local_runtime_filter_mgr()->register_producer_filter( |
530 | 0 | desc, query_options(), producer_filter, build_bf_exactly); |
531 | 0 | } |
532 | 0 | } |
533 | | |
534 | | Status RuntimeState::register_consumer_runtime_filter(const doris::TRuntimeFilterDesc& desc, |
535 | | bool need_local_merge, int node_id, |
536 | 0 | doris::IRuntimeFilter** consumer_filter) { |
537 | 0 | if (desc.has_remote_targets || need_local_merge) { |
538 | 0 | return global_runtime_filter_mgr()->register_consumer_filter(desc, query_options(), node_id, |
539 | 0 | consumer_filter, false, true); |
540 | 0 | } else { |
541 | 0 | return local_runtime_filter_mgr()->register_consumer_filter(desc, query_options(), node_id, |
542 | 0 | consumer_filter, false, false); |
543 | 0 | } |
544 | 0 | } |
545 | | |
546 | 0 | bool RuntimeState::is_nereids() const { |
547 | 0 | return _query_ctx->is_nereids(); |
548 | 0 | } |
549 | | |
550 | | } // end namespace doris |