/root/doris/be/src/runtime/runtime_state.cpp
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.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 <fstream> |
29 | | #include <memory> |
30 | | #include <string> |
31 | | |
32 | | #include "cloud/cloud_storage_engine.h" |
33 | | #include "cloud/config.h" |
34 | | #include "common/config.h" |
35 | | #include "common/logging.h" |
36 | | #include "common/object_pool.h" |
37 | | #include "common/status.h" |
38 | | #include "core/value/vdatetime_value.h" |
39 | | #include "exec/operator/operator.h" |
40 | | #include "exec/pipeline/pipeline_fragment_context.h" |
41 | | #include "exec/pipeline/pipeline_task.h" |
42 | | #include "exec/runtime_filter/runtime_filter_consumer.h" |
43 | | #include "exec/runtime_filter/runtime_filter_mgr.h" |
44 | | #include "exec/runtime_filter/runtime_filter_producer.h" |
45 | | #include "exprs/function/cast/cast_to_date_or_datetime_impl.hpp" |
46 | | #include "io/fs/s3_file_system.h" |
47 | | #include "load/load_path_mgr.h" |
48 | | #include "runtime/exec_env.h" |
49 | | #include "runtime/fragment_mgr.h" |
50 | | #include "runtime/memory/mem_tracker_limiter.h" |
51 | | #include "runtime/memory/thread_mem_tracker_mgr.h" |
52 | | #include "runtime/query_context.h" |
53 | | #include "runtime/thread_context.h" |
54 | | #include "storage/id_manager.h" |
55 | | #include "storage/storage_engine.h" |
56 | | #include "util/io_helper.h" |
57 | | #include "util/timezone_utils.h" |
58 | | #include "util/uid_util.h" |
59 | | |
60 | | namespace doris { |
61 | | #include "common/compile_check_begin.h" |
62 | | using namespace ErrorCode; |
63 | | |
64 | | RuntimeState::RuntimeState(const TPlanFragmentExecParams& fragment_exec_params, |
65 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
66 | | ExecEnv* exec_env, QueryContext* ctx, |
67 | | const std::shared_ptr<MemTrackerLimiter>& query_mem_tracker) |
68 | 0 | : _profile("Fragment " + print_id(fragment_exec_params.fragment_instance_id)), |
69 | 0 | _load_channel_profile("<unnamed>"), |
70 | 0 | _obj_pool(new ObjectPool()), |
71 | 0 | _unreported_error_idx(0), |
72 | 0 | _query_id(fragment_exec_params.query_id), |
73 | 0 | _per_fragment_instance_idx(0), |
74 | 0 | _num_rows_load_total(0), |
75 | 0 | _num_rows_load_filtered(0), |
76 | 0 | _num_rows_load_unselected(0), |
77 | 0 | _num_print_error_rows(0), |
78 | 0 | _num_bytes_load_total(0), |
79 | 0 | _num_finished_scan_range(0), |
80 | 0 | _query_ctx(ctx) { |
81 | 0 | Status status = |
82 | 0 | init(fragment_exec_params.fragment_instance_id, query_options, query_globals, exec_env); |
83 | 0 | DCHECK(status.ok()); |
84 | 0 | _query_mem_tracker = query_mem_tracker; |
85 | 0 | DCHECK(_query_mem_tracker != nullptr); |
86 | 0 | } |
87 | | |
88 | | RuntimeState::RuntimeState(const TUniqueId& instance_id, const TUniqueId& query_id, |
89 | | int32_t fragment_id, const TQueryOptions& query_options, |
90 | | const TQueryGlobals& query_globals, ExecEnv* exec_env, QueryContext* ctx) |
91 | 80 | : _profile("Fragment " + print_id(instance_id)), |
92 | 80 | _load_channel_profile("<unnamed>"), |
93 | 80 | _obj_pool(new ObjectPool()), |
94 | 80 | _unreported_error_idx(0), |
95 | 80 | _query_id(query_id), |
96 | 80 | _fragment_id(fragment_id), |
97 | 80 | _per_fragment_instance_idx(0), |
98 | 80 | _num_rows_load_total(0), |
99 | 80 | _num_rows_load_filtered(0), |
100 | 80 | _num_rows_load_unselected(0), |
101 | 80 | _num_rows_filtered_in_strict_mode_partial_update(0), |
102 | 80 | _num_print_error_rows(0), |
103 | 80 | _num_bytes_load_total(0), |
104 | 80 | _num_finished_scan_range(0), |
105 | 80 | _query_ctx(ctx) { |
106 | 80 | [[maybe_unused]] auto status = init(instance_id, query_options, query_globals, exec_env); |
107 | 80 | DCHECK(status.ok()); |
108 | 80 | _query_mem_tracker = ctx->query_mem_tracker(); |
109 | 80 | } |
110 | | |
111 | | RuntimeState::RuntimeState(const TUniqueId& query_id, int32_t fragment_id, |
112 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
113 | | ExecEnv* exec_env, QueryContext* ctx) |
114 | 113 | : _profile("PipelineX " + std::to_string(fragment_id)), |
115 | 113 | _load_channel_profile("<unnamed>"), |
116 | 113 | _obj_pool(new ObjectPool()), |
117 | 113 | _unreported_error_idx(0), |
118 | 113 | _query_id(query_id), |
119 | 113 | _fragment_id(fragment_id), |
120 | 113 | _per_fragment_instance_idx(0), |
121 | 113 | _num_rows_load_total(0), |
122 | 113 | _num_rows_load_filtered(0), |
123 | 113 | _num_rows_load_unselected(0), |
124 | 113 | _num_rows_filtered_in_strict_mode_partial_update(0), |
125 | 113 | _num_print_error_rows(0), |
126 | 113 | _num_bytes_load_total(0), |
127 | 113 | _num_finished_scan_range(0), |
128 | 113 | _query_ctx(ctx) { |
129 | | // TODO: do we really need instance id? |
130 | 113 | Status status = init(TUniqueId(), query_options, query_globals, exec_env); |
131 | 113 | DCHECK(status.ok()); |
132 | 113 | _query_mem_tracker = ctx->query_mem_tracker(); |
133 | 113 | } |
134 | | |
135 | | RuntimeState::RuntimeState(const TUniqueId& query_id, int32_t fragment_id, |
136 | | const TQueryOptions& query_options, const TQueryGlobals& query_globals, |
137 | | ExecEnv* exec_env, |
138 | | const std::shared_ptr<MemTrackerLimiter>& query_mem_tracker) |
139 | 0 | : _profile("PipelineX " + std::to_string(fragment_id)), |
140 | 0 | _load_channel_profile("<unnamed>"), |
141 | 0 | _obj_pool(new ObjectPool()), |
142 | 0 | _unreported_error_idx(0), |
143 | 0 | _query_id(query_id), |
144 | 0 | _fragment_id(fragment_id), |
145 | 0 | _per_fragment_instance_idx(0), |
146 | 0 | _num_rows_load_total(0), |
147 | 0 | _num_rows_load_filtered(0), |
148 | 0 | _num_rows_load_unselected(0), |
149 | 0 | _num_rows_filtered_in_strict_mode_partial_update(0), |
150 | 0 | _num_print_error_rows(0), |
151 | 0 | _num_bytes_load_total(0), |
152 | 0 | _num_finished_scan_range(0) { |
153 | 0 | Status status = init(TUniqueId(), query_options, query_globals, exec_env); |
154 | 0 | DCHECK(status.ok()); |
155 | 0 | _query_mem_tracker = query_mem_tracker; |
156 | 0 | DCHECK(_query_mem_tracker != nullptr); |
157 | 0 | } |
158 | | |
159 | | RuntimeState::RuntimeState(const TQueryGlobals& query_globals) |
160 | 49.2k | : _profile("<unnamed>"), |
161 | 49.2k | _load_channel_profile("<unnamed>"), |
162 | 49.2k | _obj_pool(new ObjectPool()), |
163 | 49.2k | _unreported_error_idx(0), |
164 | 49.2k | _per_fragment_instance_idx(0) { |
165 | 49.2k | _query_options.batch_size = DEFAULT_BATCH_SIZE; |
166 | 49.2k | if (query_globals.__isset.time_zone && query_globals.__isset.nano_seconds) { |
167 | 49.1k | _timezone = query_globals.time_zone; |
168 | 49.1k | _timestamp_ms = query_globals.timestamp_ms; |
169 | 49.1k | _nano_seconds = query_globals.nano_seconds; |
170 | 49.1k | } else if (query_globals.__isset.time_zone) { |
171 | 0 | _timezone = query_globals.time_zone; |
172 | 0 | _timestamp_ms = query_globals.timestamp_ms; |
173 | 0 | _nano_seconds = 0; |
174 | 113 | } else if (!query_globals.now_string.empty()) { |
175 | 0 | _timezone = TimezoneUtils::default_time_zone; |
176 | 0 | VecDateTimeValue dt; |
177 | 0 | read_datetime_text_impl( |
178 | 0 | dt, StringRef(query_globals.now_string.data(), query_globals.now_string.size())); |
179 | 0 | int64_t timestamp; |
180 | 0 | dt.unix_timestamp(×tamp, _timezone); |
181 | 0 | _timestamp_ms = timestamp * 1000; |
182 | 0 | _nano_seconds = 0; |
183 | 113 | } else { |
184 | | //Unit test may set into here |
185 | 113 | _timezone = TimezoneUtils::default_time_zone; |
186 | 113 | _timestamp_ms = 0; |
187 | 113 | _nano_seconds = 0; |
188 | 113 | } |
189 | 49.2k | TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj); |
190 | 49.2k | init_mem_trackers("<unnamed>"); |
191 | 49.2k | } |
192 | | |
193 | | RuntimeState::RuntimeState() |
194 | 130k | : _profile("<unnamed>"), |
195 | 130k | _load_channel_profile("<unnamed>"), |
196 | 130k | _obj_pool(new ObjectPool()), |
197 | 130k | _unreported_error_idx(0), |
198 | 130k | _per_fragment_instance_idx(0) { |
199 | 130k | _query_options.batch_size = DEFAULT_BATCH_SIZE; |
200 | 130k | _query_options.be_exec_version = BeExecVersionManager::get_newest_version(); |
201 | 130k | _timezone = TimezoneUtils::default_time_zone; |
202 | 130k | _timestamp_ms = 0; |
203 | 130k | _nano_seconds = 0; |
204 | 130k | TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj); |
205 | 130k | _exec_env = ExecEnv::GetInstance(); |
206 | 130k | init_mem_trackers("<unnamed>"); |
207 | 130k | } |
208 | | |
209 | 179k | RuntimeState::~RuntimeState() { |
210 | 179k | SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_query_mem_tracker); |
211 | | // close error log file |
212 | 179k | if (_error_log_file != nullptr && _error_log_file->is_open()) { |
213 | 0 | _error_log_file->close(); |
214 | 0 | } |
215 | 179k | _obj_pool->clear(); |
216 | 179k | } |
217 | | |
218 | 2 | const std::set<int>& RuntimeState::get_deregister_runtime_filter() const { |
219 | 2 | return _registered_runtime_filter_ids; |
220 | 2 | } |
221 | | |
222 | 2 | void RuntimeState::merge_register_runtime_filter(const std::set<int>& runtime_filter_ids) { |
223 | 2 | _registered_runtime_filter_ids.insert(runtime_filter_ids.begin(), runtime_filter_ids.end()); |
224 | 2 | } |
225 | | |
226 | | Status RuntimeState::init(const TUniqueId& fragment_instance_id, const TQueryOptions& query_options, |
227 | 198 | const TQueryGlobals& query_globals, ExecEnv* exec_env) { |
228 | 198 | _fragment_instance_id = fragment_instance_id; |
229 | 198 | _query_options = query_options; |
230 | 198 | _lc_time_names = query_globals.lc_time_names; |
231 | 198 | if (query_globals.__isset.time_zone && query_globals.__isset.nano_seconds) { |
232 | 0 | _timezone = query_globals.time_zone; |
233 | 0 | _timestamp_ms = query_globals.timestamp_ms; |
234 | 0 | _nano_seconds = query_globals.nano_seconds; |
235 | 198 | } else if (query_globals.__isset.time_zone) { |
236 | 0 | _timezone = query_globals.time_zone; |
237 | 0 | _timestamp_ms = query_globals.timestamp_ms; |
238 | 0 | _nano_seconds = 0; |
239 | 198 | } else if (!query_globals.now_string.empty()) { |
240 | 0 | _timezone = TimezoneUtils::default_time_zone; |
241 | 0 | VecDateTimeValue dt; |
242 | 0 | CastParameters params; |
243 | 0 | DORIS_CHECK((CastToDateOrDatetime::from_string_strict_mode<DatelikeParseMode::STRICT, |
244 | 0 | DatelikeTargetType::DATE_TIME>( |
245 | 0 | {query_globals.now_string.c_str(), query_globals.now_string.size()}, dt, nullptr, |
246 | 0 | params))); |
247 | 0 | int64_t timestamp; |
248 | 0 | dt.unix_timestamp(×tamp, _timezone); |
249 | 0 | _timestamp_ms = timestamp * 1000; |
250 | 0 | _nano_seconds = 0; |
251 | 198 | } else { |
252 | | //Unit test may set into here |
253 | 198 | _timezone = TimezoneUtils::default_time_zone; |
254 | 198 | _timestamp_ms = 0; |
255 | 198 | _nano_seconds = 0; |
256 | 198 | } |
257 | 198 | TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj); |
258 | | |
259 | 198 | if (query_globals.__isset.load_zero_tolerance) { |
260 | 198 | _load_zero_tolerance = query_globals.load_zero_tolerance; |
261 | 198 | } |
262 | | |
263 | 198 | _exec_env = exec_env; |
264 | | |
265 | 198 | if (_query_options.max_errors <= 0) { |
266 | | // TODO: fix linker error and uncomment this |
267 | | //_query_options.max_errors = config::max_errors; |
268 | 198 | _query_options.max_errors = 100; |
269 | 198 | } |
270 | | |
271 | 198 | if (_query_options.batch_size <= 0) { |
272 | 125 | _query_options.batch_size = DEFAULT_BATCH_SIZE; |
273 | 125 | } |
274 | | |
275 | 198 | _db_name = "insert_stmt"; |
276 | 198 | _import_label = print_id(fragment_instance_id); |
277 | | |
278 | 198 | _profile_level = query_options.__isset.profile_level ? query_options.profile_level : 2; |
279 | | |
280 | 198 | return Status::OK(); |
281 | 198 | } |
282 | | |
283 | 0 | std::weak_ptr<QueryContext> RuntimeState::get_query_ctx_weak() { |
284 | 0 | return _exec_env->fragment_mgr()->get_query_ctx(_query_ctx->query_id()); |
285 | 0 | } |
286 | | |
287 | 179k | void RuntimeState::init_mem_trackers(const std::string& name, const TUniqueId& id) { |
288 | 179k | _query_mem_tracker = MemTrackerLimiter::create_shared( |
289 | 179k | MemTrackerLimiter::Type::OTHER, fmt::format("{}#Id={}", name, print_id(id))); |
290 | 179k | } |
291 | | |
292 | 177 | std::shared_ptr<MemTrackerLimiter> RuntimeState::query_mem_tracker() const { |
293 | 177 | CHECK(_query_mem_tracker != nullptr); |
294 | 177 | return _query_mem_tracker; |
295 | 177 | } |
296 | | |
297 | 11 | WorkloadGroupPtr RuntimeState::workload_group() { |
298 | 11 | return _query_ctx->workload_group(); |
299 | 11 | } |
300 | | |
301 | 0 | bool RuntimeState::log_error(const std::string& error) { |
302 | 0 | std::lock_guard<std::mutex> l(_error_log_lock); |
303 | |
|
304 | 0 | if (_error_log.size() < _query_options.max_errors) { |
305 | 0 | _error_log.push_back(error); |
306 | 0 | return true; |
307 | 0 | } |
308 | | |
309 | 0 | return false; |
310 | 0 | } |
311 | | |
312 | 0 | void RuntimeState::get_unreported_errors(std::vector<std::string>* new_errors) { |
313 | 0 | std::lock_guard<std::mutex> l(_error_log_lock); |
314 | |
|
315 | 0 | if (_unreported_error_idx < _error_log.size()) { |
316 | 0 | new_errors->assign(_error_log.begin() + _unreported_error_idx, _error_log.end()); |
317 | 0 | _unreported_error_idx = (int)_error_log.size(); |
318 | 0 | } |
319 | 0 | } |
320 | | |
321 | 1.10M | bool RuntimeState::is_cancelled() const { |
322 | | // Maybe we should just return _is_cancelled.load() |
323 | 1.10M | return !_exec_status.ok() || (_query_ctx && _query_ctx->is_cancelled()); |
324 | 1.10M | } |
325 | | |
326 | 0 | Status RuntimeState::cancel_reason() const { |
327 | 0 | if (!_exec_status.ok()) { |
328 | 0 | return _exec_status.status(); |
329 | 0 | } |
330 | | |
331 | 0 | if (_query_ctx) { |
332 | 0 | return _query_ctx->exec_status(); |
333 | 0 | } |
334 | | |
335 | 0 | return Status::Cancelled("Query cancelled"); |
336 | 0 | } |
337 | | |
338 | | const int64_t MAX_ERROR_NUM = 50; |
339 | | |
340 | 0 | Status RuntimeState::create_error_log_file() { |
341 | 0 | if (config::save_load_error_log_to_s3 && config::is_cloud_mode()) { |
342 | 0 | _s3_error_fs = std::dynamic_pointer_cast<io::S3FileSystem>( |
343 | 0 | ExecEnv::GetInstance()->storage_engine().to_cloud().latest_fs()); |
344 | 0 | if (_s3_error_fs) { |
345 | 0 | std::stringstream ss; |
346 | | // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_err_packet.html |
347 | | // shorten the path as much as possible to prevent the length of the presigned URL from |
348 | | // exceeding the MySQL error packet size limit |
349 | 0 | ss << "error_log/" << std::hex << _fragment_instance_id.lo; |
350 | 0 | _s3_error_log_file_path = ss.str(); |
351 | 0 | } |
352 | 0 | } |
353 | |
|
354 | 0 | static_cast<void>(_exec_env->load_path_mgr()->get_load_error_file_name( |
355 | 0 | _db_name, _import_label, _fragment_instance_id, &_error_log_file_path)); |
356 | 0 | std::string error_log_absolute_path = |
357 | 0 | _exec_env->load_path_mgr()->get_load_error_absolute_path(_error_log_file_path); |
358 | 0 | _error_log_file = std::make_unique<std::ofstream>(error_log_absolute_path, std::ifstream::out); |
359 | 0 | if (!_error_log_file->is_open()) { |
360 | 0 | std::stringstream error_msg; |
361 | 0 | error_msg << "Fail to open error file: [" << _error_log_file_path << "]."; |
362 | 0 | LOG(WARNING) << error_msg.str(); |
363 | 0 | return Status::InternalError(error_msg.str()); |
364 | 0 | } |
365 | 0 | LOG(INFO) << "create error log file: " << _error_log_file_path |
366 | 0 | << ", query id: " << print_id(_query_id) |
367 | 0 | << ", fragment instance id: " << print_id(_fragment_instance_id); |
368 | |
|
369 | 0 | return Status::OK(); |
370 | 0 | } |
371 | | |
372 | | Status RuntimeState::append_error_msg_to_file(std::function<std::string()> line, |
373 | 0 | std::function<std::string()> error_msg) { |
374 | 0 | if (query_type() != TQueryType::LOAD) { |
375 | 0 | return Status::OK(); |
376 | 0 | } |
377 | | // If file haven't been opened, open it here |
378 | 0 | if (_error_log_file == nullptr) { |
379 | 0 | Status status = create_error_log_file(); |
380 | 0 | if (!status.ok()) { |
381 | 0 | LOG(WARNING) << "Create error file log failed. because: " << status; |
382 | 0 | if (_error_log_file != nullptr) { |
383 | 0 | _error_log_file->close(); |
384 | 0 | } |
385 | 0 | return status; |
386 | 0 | } |
387 | | // record the first error message if the file is just created |
388 | 0 | _first_error_msg = error_msg() + ". Src line: " + line(); |
389 | 0 | LOG(INFO) << "The first error message: " << _first_error_msg; |
390 | 0 | } |
391 | | // If num of printed error row exceeds the limit, don't add error messages to error log file any more |
392 | 0 | if (_num_print_error_rows.fetch_add(1, std::memory_order_relaxed) > MAX_ERROR_NUM) { |
393 | | // if _load_zero_tolerance, return Error to stop the load process immediately. |
394 | 0 | if (_load_zero_tolerance) { |
395 | 0 | return Status::DataQualityError( |
396 | 0 | "Encountered unqualified data, stop processing. Please check if the source " |
397 | 0 | "data matches the schema, and consider disabling strict mode or increasing " |
398 | 0 | "max_filter_ratio."); |
399 | 0 | } |
400 | 0 | return Status::OK(); |
401 | 0 | } |
402 | | |
403 | 0 | fmt::memory_buffer out; |
404 | | // Note: export reason first in case src line too long and be truncated. |
405 | 0 | fmt::format_to(out, "Reason: {}. src line [{}]; ", error_msg(), line()); |
406 | |
|
407 | 0 | size_t error_row_size = out.size(); |
408 | 0 | if (error_row_size > 0) { |
409 | 0 | if (error_row_size > config::load_error_log_limit_bytes) { |
410 | 0 | fmt::memory_buffer limit_byte_out; |
411 | 0 | limit_byte_out.append(out.data(), out.data() + config::load_error_log_limit_bytes); |
412 | 0 | (*_error_log_file) << fmt::to_string(limit_byte_out) + "error log is too long" |
413 | 0 | << std::endl; |
414 | 0 | } else { |
415 | 0 | (*_error_log_file) << fmt::to_string(out) << std::endl; |
416 | 0 | } |
417 | 0 | } |
418 | |
|
419 | 0 | return Status::OK(); |
420 | 0 | } |
421 | | |
422 | 0 | std::string RuntimeState::get_error_log_file_path() { |
423 | 0 | DBUG_EXECUTE_IF("RuntimeState::get_error_log_file_path.block", { |
424 | 0 | if (!_error_log_file_path.empty()) { |
425 | 0 | std::this_thread::sleep_for(std::chrono::seconds(1)); |
426 | 0 | } |
427 | 0 | }); |
428 | 0 | std::lock_guard<std::mutex> l(_s3_error_log_file_lock); |
429 | 0 | if (_s3_error_fs && _error_log_file && _error_log_file->is_open()) { |
430 | | // close error log file |
431 | 0 | _error_log_file->close(); |
432 | 0 | std::string error_log_absolute_path = |
433 | 0 | _exec_env->load_path_mgr()->get_load_error_absolute_path(_error_log_file_path); |
434 | | // upload error log file to s3 |
435 | 0 | Status st = _s3_error_fs->upload(error_log_absolute_path, _s3_error_log_file_path); |
436 | 0 | if (!st.ok()) { |
437 | | // upload failed and return local error log file path |
438 | 0 | LOG(WARNING) << "Fail to upload error file to s3, error_log_file_path=" |
439 | 0 | << _error_log_file_path << ", error=" << st; |
440 | 0 | return _error_log_file_path; |
441 | 0 | } |
442 | | // expiration must be less than a week (in seconds) for presigned url |
443 | 0 | static const unsigned EXPIRATION_SECONDS = 7 * 24 * 60 * 60 - 1; |
444 | | // Use public or private endpoint based on configuration |
445 | 0 | _error_log_file_path = |
446 | 0 | _s3_error_fs->generate_presigned_url(_s3_error_log_file_path, EXPIRATION_SECONDS, |
447 | 0 | config::use_public_endpoint_for_error_log); |
448 | 0 | } |
449 | 0 | return _error_log_file_path; |
450 | 0 | } |
451 | | |
452 | 72.3k | void RuntimeState::resize_op_id_to_local_state(int operator_size) { |
453 | 72.3k | _op_id_to_local_state.resize(-operator_size); |
454 | 72.3k | } |
455 | | |
456 | | void RuntimeState::emplace_local_state(int id, |
457 | 24.3k | std::unique_ptr<doris::PipelineXLocalStateBase> state) { |
458 | 24.3k | id = -id; |
459 | 24.3k | DCHECK_LT(id, _op_id_to_local_state.size()) |
460 | 0 | << state->parent()->get_name() << " node id = " << state->parent()->node_id(); |
461 | 24.3k | DCHECK(!_op_id_to_local_state[id]); |
462 | 24.3k | _op_id_to_local_state[id] = std::move(state); |
463 | 24.3k | } |
464 | | |
465 | 2.05M | doris::PipelineXLocalStateBase* RuntimeState::get_local_state(int id) { |
466 | 2.05M | id = -id; |
467 | 2.05M | return _op_id_to_local_state[id].get(); |
468 | 2.05M | } |
469 | | |
470 | 24.0k | Result<RuntimeState::LocalState*> RuntimeState::get_local_state_result(int id) { |
471 | 24.0k | id = -id; |
472 | 24.0k | if (id >= _op_id_to_local_state.size()) { |
473 | 1 | return ResultError(Status::InternalError("get_local_state out of range size:{} , id:{}", |
474 | 1 | _op_id_to_local_state.size(), id)); |
475 | 1 | } |
476 | 24.0k | if (!_op_id_to_local_state[id]) { |
477 | 0 | return ResultError(Status::InternalError("get_local_state id:{} is null", id)); |
478 | 0 | } |
479 | 24.0k | return _op_id_to_local_state[id].get(); |
480 | 24.0k | }; |
481 | | |
482 | | void RuntimeState::emplace_sink_local_state( |
483 | 72.3k | int id, std::unique_ptr<doris::PipelineXSinkLocalStateBase> state) { |
484 | 72.3k | DCHECK(!_sink_local_state) << " id=" << id << " state: " << state->debug_string(0); |
485 | 72.3k | _sink_local_state = std::move(state); |
486 | 72.3k | } |
487 | | |
488 | 426k | doris::PipelineXSinkLocalStateBase* RuntimeState::get_sink_local_state() { |
489 | 426k | return _sink_local_state.get(); |
490 | 426k | } |
491 | | |
492 | 1.08M | Result<RuntimeState::SinkLocalState*> RuntimeState::get_sink_local_state_result() { |
493 | 1.08M | if (!_sink_local_state) { |
494 | 0 | return ResultError(Status::InternalError("_op_id_to_sink_local_state not exist")); |
495 | 0 | } |
496 | 1.08M | return _sink_local_state.get(); |
497 | 1.08M | } |
498 | | |
499 | 0 | bool RuntimeState::enable_page_cache() const { |
500 | 0 | return !config::disable_storage_page_cache && |
501 | 0 | (_query_options.__isset.enable_page_cache && _query_options.enable_page_cache); |
502 | 0 | } |
503 | | |
504 | 60 | RuntimeFilterMgr* RuntimeState::global_runtime_filter_mgr() { |
505 | 60 | return _query_ctx->runtime_filter_mgr(); |
506 | 60 | } |
507 | | |
508 | | Status RuntimeState::register_producer_runtime_filter( |
509 | 29 | const TRuntimeFilterDesc& desc, std::shared_ptr<RuntimeFilterProducer>* producer_filter) { |
510 | 29 | _registered_runtime_filter_ids.insert(desc.filter_id); |
511 | | // Producers are created by local runtime filter mgr and shared by global runtime filter manager. |
512 | | // When RF is published, consumers in both global and local RF mgr will be found. |
513 | 29 | RETURN_IF_ERROR(local_runtime_filter_mgr()->register_producer_filter(_query_ctx, desc, |
514 | 29 | producer_filter)); |
515 | | // Stamp the producer with the current recursive CTE stage so that outgoing merge RPCs |
516 | | // carry the correct round number and stale messages from old rounds are discarded. |
517 | | // PFC must still be alive: this runs inside a pipeline task, so the execution context |
518 | | // cannot have expired yet. |
519 | | // In unit-test scenarios the task execution context is never set (no PipelineFragmentContext |
520 | | // exists), so skip the stage stamping — the default stage (0) is correct. |
521 | 29 | if (task_execution_context_inited()) { |
522 | 2 | auto pfc = std::static_pointer_cast<PipelineFragmentContext>( |
523 | 2 | get_task_execution_context().lock()); |
524 | 2 | DORIS_CHECK(pfc); |
525 | 2 | (*producer_filter)->set_stage(pfc->rec_cte_stage()); |
526 | 2 | } |
527 | 29 | RETURN_IF_ERROR(global_runtime_filter_mgr()->register_local_merger_producer_filter( |
528 | 29 | _query_ctx, desc, *producer_filter)); |
529 | 29 | return Status::OK(); |
530 | 29 | } |
531 | | |
532 | | Status RuntimeState::register_consumer_runtime_filter( |
533 | | const TRuntimeFilterDesc& desc, bool need_local_merge, int node_id, |
534 | 6 | std::shared_ptr<RuntimeFilterConsumer>* consumer_filter) { |
535 | 6 | _registered_runtime_filter_ids.insert(desc.filter_id); |
536 | 6 | bool need_merge = desc.has_remote_targets || need_local_merge; |
537 | 6 | RuntimeFilterMgr* mgr = need_merge ? global_runtime_filter_mgr() : local_runtime_filter_mgr(); |
538 | 6 | RETURN_IF_ERROR(mgr->register_consumer_filter(this, desc, node_id, consumer_filter)); |
539 | | // Stamp the consumer with the current recursive CTE stage so that incoming publish RPCs |
540 | | // from old rounds are detected and discarded. |
541 | | // PFC must still be alive: this runs inside a pipeline task, so the execution context |
542 | | // cannot have expired yet. |
543 | | // In unit-test scenarios the task execution context is never set (no PipelineFragmentContext |
544 | | // exists), so skip the stage stamping — the default stage (0) is correct. |
545 | 6 | if (task_execution_context_inited()) { |
546 | 0 | auto pfc = std::static_pointer_cast<PipelineFragmentContext>( |
547 | 0 | get_task_execution_context().lock()); |
548 | 0 | DORIS_CHECK(pfc); |
549 | 0 | (*consumer_filter)->set_stage(pfc->rec_cte_stage()); |
550 | 0 | } |
551 | 6 | return Status::OK(); |
552 | 6 | } |
553 | | |
554 | 72 | bool RuntimeState::is_nereids() const { |
555 | 72 | return _query_ctx->is_nereids(); |
556 | 72 | } |
557 | | |
558 | 0 | std::vector<std::shared_ptr<RuntimeProfile>> RuntimeState::pipeline_id_to_profile() { |
559 | 0 | std::shared_lock lc(_pipeline_profile_lock); |
560 | 0 | return _pipeline_id_to_profile; |
561 | 0 | } |
562 | | |
563 | | std::vector<std::shared_ptr<RuntimeProfile>> RuntimeState::build_pipeline_profile( |
564 | 0 | std::size_t pipeline_size) { |
565 | 0 | std::unique_lock lc(_pipeline_profile_lock); |
566 | 0 | if (!_pipeline_id_to_profile.empty()) { |
567 | 0 | return _pipeline_id_to_profile; |
568 | 0 | } |
569 | 0 | _pipeline_id_to_profile.resize(pipeline_size); |
570 | 0 | { |
571 | 0 | size_t pip_idx = 0; |
572 | 0 | for (auto& pipeline_profile : _pipeline_id_to_profile) { |
573 | 0 | pipeline_profile = |
574 | 0 | std::make_shared<RuntimeProfile>("Pipeline : " + std::to_string(pip_idx)); |
575 | 0 | pip_idx++; |
576 | 0 | } |
577 | 0 | } |
578 | 0 | return _pipeline_id_to_profile; |
579 | 0 | } |
580 | | |
581 | 665k | bool RuntimeState::low_memory_mode() const { |
582 | 665k | #ifdef BE_TEST |
583 | 665k | if (!_query_ctx) { |
584 | 0 | return false; |
585 | 0 | } |
586 | 665k | #endif |
587 | 665k | return _query_ctx->low_memory_mode(); |
588 | 665k | } |
589 | | |
590 | 0 | void RuntimeState::set_id_file_map() { |
591 | 0 | _id_file_map = _exec_env->get_id_manager()->add_id_file_map(_query_id, execution_timeout()); |
592 | 0 | } |
593 | | #include "common/compile_check_end.h" |
594 | | } // end namespace doris |