Coverage Report

Created: 2026-04-10 16:11

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