Coverage Report

Created: 2026-03-25 00:23

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