Coverage Report

Created: 2026-03-27 23:22

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