Coverage Report

Created: 2024-11-20 21:49

/root/doris/be/src/runtime/runtime_state.cpp
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/apache/impala/blob/branch-2.9.0/be/src/runtime/runtime-state.cpp
19
// and modified by Doris
20
21
#include "runtime/runtime_state.h"
22
23
#include <fmt/format.h>
24
#include <gen_cpp/PaloInternalService_types.h>
25
#include <gen_cpp/Types_types.h>
26
#include <glog/logging.h>
27
28
#include <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 "io/fs/s3_file_system.h"
39
#include "olap/storage_engine.h"
40
#include "pipeline/exec/operator.h"
41
#include "pipeline/pipeline_task.h"
42
#include "runtime/exec_env.h"
43
#include "runtime/fragment_mgr.h"
44
#include "runtime/load_path_mgr.h"
45
#include "runtime/memory/mem_tracker_limiter.h"
46
#include "runtime/memory/thread_mem_tracker_mgr.h"
47
#include "runtime/query_context.h"
48
#include "runtime/runtime_filter_mgr.h"
49
#include "runtime/thread_context.h"
50
#include "util/timezone_utils.h"
51
#include "util/uid_util.h"
52
#include "vec/runtime/vdatetime_value.h"
53
54
namespace doris {
55
using namespace ErrorCode;
56
57
RuntimeState::RuntimeState(const TPlanFragmentExecParams& fragment_exec_params,
58
                           const TQueryOptions& query_options, const TQueryGlobals& query_globals,
59
                           ExecEnv* exec_env, QueryContext* ctx,
60
                           const std::shared_ptr<MemTrackerLimiter>& query_mem_tracker)
61
        : _profile("Fragment " + print_id(fragment_exec_params.fragment_instance_id)),
62
          _load_channel_profile("<unnamed>"),
63
          _obj_pool(new ObjectPool()),
64
          _unreported_error_idx(0),
65
          _query_id(fragment_exec_params.query_id),
66
          _per_fragment_instance_idx(0),
67
          _num_rows_load_total(0),
68
          _num_rows_load_filtered(0),
69
          _num_rows_load_unselected(0),
70
          _num_print_error_rows(0),
71
          _num_bytes_load_total(0),
72
          _num_finished_scan_range(0),
73
          _error_row_number(0),
74
0
          _query_ctx(ctx) {
75
0
    Status status =
76
0
            init(fragment_exec_params.fragment_instance_id, query_options, query_globals, exec_env);
77
0
    DCHECK(status.ok());
78
0
    if (query_mem_tracker != nullptr) {
79
0
        _query_mem_tracker = query_mem_tracker;
80
0
    } else {
81
0
        DCHECK(ctx != nullptr);
82
0
        _query_mem_tracker = ctx->query_mem_tracker;
83
0
    }
84
0
#ifdef BE_TEST
85
0
    if (_query_mem_tracker == nullptr) {
86
0
        init_mem_trackers();
87
0
    }
88
0
#endif
89
0
    DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan");
90
0
    if (fragment_exec_params.__isset.runtime_filter_params) {
91
0
        _query_ctx->runtime_filter_mgr()->set_runtime_filter_params(
92
0
                fragment_exec_params.runtime_filter_params);
93
0
    }
94
0
}
95
96
RuntimeState::RuntimeState(const TUniqueId& instance_id, const TUniqueId& query_id,
97
                           int32_t fragment_id, const TQueryOptions& query_options,
98
                           const TQueryGlobals& query_globals, ExecEnv* exec_env, QueryContext* ctx)
99
        : _profile("Fragment " + print_id(instance_id)),
100
          _load_channel_profile("<unnamed>"),
101
          _obj_pool(new ObjectPool()),
102
          _unreported_error_idx(0),
103
          _query_id(query_id),
104
          _fragment_id(fragment_id),
105
          _per_fragment_instance_idx(0),
106
          _num_rows_load_total(0),
107
          _num_rows_load_filtered(0),
108
          _num_rows_load_unselected(0),
109
          _num_rows_filtered_in_strict_mode_partial_update(0),
110
          _num_print_error_rows(0),
111
          _num_bytes_load_total(0),
112
          _num_finished_scan_range(0),
113
          _error_row_number(0),
114
0
          _query_ctx(ctx) {
115
0
    [[maybe_unused]] auto status = init(instance_id, query_options, query_globals, exec_env);
116
0
    DCHECK(status.ok());
117
0
    _query_mem_tracker = ctx->query_mem_tracker;
118
0
#ifdef BE_TEST
119
0
    if (_query_mem_tracker == nullptr) {
120
0
        init_mem_trackers();
121
0
    }
122
0
#endif
123
0
    DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan");
124
0
}
125
126
RuntimeState::RuntimeState(pipeline::PipelineFragmentContext*, const TUniqueId& instance_id,
127
                           const TUniqueId& query_id, int32_t fragment_id,
128
                           const TQueryOptions& query_options, const TQueryGlobals& query_globals,
129
                           ExecEnv* exec_env, QueryContext* ctx)
130
        : _profile("Fragment " + print_id(instance_id)),
131
          _load_channel_profile("<unnamed>"),
132
          _obj_pool(new ObjectPool()),
133
          _unreported_error_idx(0),
134
          _query_id(query_id),
135
          _fragment_id(fragment_id),
136
          _per_fragment_instance_idx(0),
137
          _num_rows_load_total(0),
138
          _num_rows_load_filtered(0),
139
          _num_rows_load_unselected(0),
140
          _num_rows_filtered_in_strict_mode_partial_update(0),
141
          _num_print_error_rows(0),
142
          _num_bytes_load_total(0),
143
          _num_finished_scan_range(0),
144
          _error_row_number(0),
145
0
          _query_ctx(ctx) {
146
0
    [[maybe_unused]] auto status = init(instance_id, query_options, query_globals, exec_env);
147
0
    _query_mem_tracker = ctx->query_mem_tracker;
148
0
#ifdef BE_TEST
149
0
    if (_query_mem_tracker == nullptr) {
150
0
        init_mem_trackers();
151
0
    }
152
0
#endif
153
0
    DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan");
154
0
    DCHECK(status.ok());
155
0
}
156
157
RuntimeState::RuntimeState(const TUniqueId& query_id, int32_t fragment_id,
158
                           const TQueryOptions& query_options, const TQueryGlobals& query_globals,
159
                           ExecEnv* exec_env, QueryContext* ctx)
160
        : _profile("PipelineX  " + std::to_string(fragment_id)),
161
          _load_channel_profile("<unnamed>"),
162
          _obj_pool(new ObjectPool()),
163
          _unreported_error_idx(0),
164
          _query_id(query_id),
165
          _fragment_id(fragment_id),
166
          _per_fragment_instance_idx(0),
167
          _num_rows_load_total(0),
168
          _num_rows_load_filtered(0),
169
          _num_rows_load_unselected(0),
170
          _num_rows_filtered_in_strict_mode_partial_update(0),
171
          _num_print_error_rows(0),
172
          _num_bytes_load_total(0),
173
          _num_finished_scan_range(0),
174
          _error_row_number(0),
175
0
          _query_ctx(ctx) {
176
    // TODO: do we really need instance id?
177
0
    Status status = init(TUniqueId(), query_options, query_globals, exec_env);
178
0
    DCHECK(status.ok());
179
0
    _query_mem_tracker = ctx->query_mem_tracker;
180
0
#ifdef BE_TEST
181
0
    if (_query_mem_tracker == nullptr) {
182
0
        init_mem_trackers();
183
0
    }
184
0
#endif
185
0
    DCHECK(_query_mem_tracker != nullptr && _query_mem_tracker->label() != "Orphan");
186
0
}
187
188
RuntimeState::RuntimeState(const TQueryGlobals& query_globals)
189
        : _profile("<unnamed>"),
190
          _load_channel_profile("<unnamed>"),
191
          _obj_pool(new ObjectPool()),
192
          _unreported_error_idx(0),
193
11.0k
          _per_fragment_instance_idx(0) {
194
11.0k
    _query_options.batch_size = DEFAULT_BATCH_SIZE;
195
11.0k
    if (query_globals.__isset.time_zone && query_globals.__isset.nano_seconds) {
196
0
        _timezone = query_globals.time_zone;
197
0
        _timestamp_ms = query_globals.timestamp_ms;
198
0
        _nano_seconds = query_globals.nano_seconds;
199
11.0k
    } else if (query_globals.__isset.time_zone) {
200
11.0k
        _timezone = query_globals.time_zone;
201
11.0k
        _timestamp_ms = query_globals.timestamp_ms;
202
11.0k
        _nano_seconds = 0;
203
11.0k
    } else if (!query_globals.now_string.empty()) {
204
0
        _timezone = TimezoneUtils::default_time_zone;
205
0
        VecDateTimeValue dt;
206
0
        dt.from_date_str(query_globals.now_string.c_str(), query_globals.now_string.size());
207
0
        int64_t timestamp;
208
0
        dt.unix_timestamp(&timestamp, _timezone);
209
0
        _timestamp_ms = timestamp * 1000;
210
0
        _nano_seconds = 0;
211
14
    } else {
212
        //Unit test may set into here
213
14
        _timezone = TimezoneUtils::default_time_zone;
214
14
        _timestamp_ms = 0;
215
14
        _nano_seconds = 0;
216
14
    }
217
11.0k
    TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj);
218
11.0k
    init_mem_trackers("<unnamed>");
219
11.0k
}
220
221
RuntimeState::RuntimeState()
222
        : _profile("<unnamed>"),
223
          _load_channel_profile("<unnamed>"),
224
          _obj_pool(new ObjectPool()),
225
          _unreported_error_idx(0),
226
5
          _per_fragment_instance_idx(0) {
227
5
    _query_options.batch_size = DEFAULT_BATCH_SIZE;
228
5
    _query_options.be_exec_version = BeExecVersionManager::get_newest_version();
229
5
    _timezone = TimezoneUtils::default_time_zone;
230
5
    _timestamp_ms = 0;
231
5
    _nano_seconds = 0;
232
5
    TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj);
233
5
    _exec_env = ExecEnv::GetInstance();
234
5
    init_mem_trackers("<unnamed>");
235
5
}
236
237
11.0k
RuntimeState::~RuntimeState() {
238
11.0k
    SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_query_mem_tracker);
239
    // close error log file
240
11.0k
    if (_error_log_file != nullptr && _error_log_file->is_open()) {
241
0
        _error_log_file->close();
242
0
    }
243
244
11.0k
    _obj_pool->clear();
245
11.0k
}
246
247
Status RuntimeState::init(const TUniqueId& fragment_instance_id, const TQueryOptions& query_options,
248
3
                          const TQueryGlobals& query_globals, ExecEnv* exec_env) {
249
3
    _fragment_instance_id = fragment_instance_id;
250
3
    _query_options = query_options;
251
3
    if (query_globals.__isset.time_zone && query_globals.__isset.nano_seconds) {
252
0
        _timezone = query_globals.time_zone;
253
0
        _timestamp_ms = query_globals.timestamp_ms;
254
0
        _nano_seconds = query_globals.nano_seconds;
255
3
    } else if (query_globals.__isset.time_zone) {
256
0
        _timezone = query_globals.time_zone;
257
0
        _timestamp_ms = query_globals.timestamp_ms;
258
0
        _nano_seconds = 0;
259
3
    } else if (!query_globals.now_string.empty()) {
260
0
        _timezone = TimezoneUtils::default_time_zone;
261
0
        VecDateTimeValue dt;
262
0
        dt.from_date_str(query_globals.now_string.c_str(), query_globals.now_string.size());
263
0
        int64_t timestamp;
264
0
        dt.unix_timestamp(&timestamp, _timezone);
265
0
        _timestamp_ms = timestamp * 1000;
266
0
        _nano_seconds = 0;
267
3
    } else {
268
        //Unit test may set into here
269
3
        _timezone = TimezoneUtils::default_time_zone;
270
3
        _timestamp_ms = 0;
271
3
        _nano_seconds = 0;
272
3
    }
273
3
    TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj);
274
275
3
    if (query_globals.__isset.load_zero_tolerance) {
276
3
        _load_zero_tolerance = query_globals.load_zero_tolerance;
277
3
    }
278
279
3
    _exec_env = exec_env;
280
281
3
    if (_query_options.max_errors <= 0) {
282
        // TODO: fix linker error and uncomment this
283
        //_query_options.max_errors = config::max_errors;
284
3
        _query_options.max_errors = 100;
285
3
    }
286
287
3
    if (_query_options.batch_size <= 0) {
288
3
        _query_options.batch_size = DEFAULT_BATCH_SIZE;
289
3
    }
290
291
3
    _db_name = "insert_stmt";
292
3
    _import_label = print_id(fragment_instance_id);
293
294
3
    return Status::OK();
295
3
}
296
297
0
std::weak_ptr<QueryContext> RuntimeState::get_query_ctx_weak() {
298
0
    return _exec_env->fragment_mgr()->get_or_erase_query_ctx_with_lock(_query_ctx->query_id());
299
0
}
300
301
11.0k
void RuntimeState::init_mem_trackers(const std::string& name, const TUniqueId& id) {
302
11.0k
    _query_mem_tracker = MemTrackerLimiter::create_shared(
303
11.0k
            MemTrackerLimiter::Type::OTHER, fmt::format("{}#Id={}", name, print_id(id)));
304
11.0k
}
305
306
0
std::shared_ptr<MemTrackerLimiter> RuntimeState::query_mem_tracker() const {
307
0
    CHECK(_query_mem_tracker != nullptr);
308
0
    return _query_mem_tracker;
309
0
}
310
311
0
bool RuntimeState::log_error(const std::string& error) {
312
0
    std::lock_guard<std::mutex> l(_error_log_lock);
313
314
0
    if (_error_log.size() < _query_options.max_errors) {
315
0
        _error_log.push_back(error);
316
0
        return true;
317
0
    }
318
319
0
    return false;
320
0
}
321
322
0
void RuntimeState::get_unreported_errors(std::vector<std::string>* new_errors) {
323
0
    std::lock_guard<std::mutex> l(_error_log_lock);
324
325
0
    if (_unreported_error_idx < _error_log.size()) {
326
0
        new_errors->assign(_error_log.begin() + _unreported_error_idx, _error_log.end());
327
0
        _unreported_error_idx = _error_log.size();
328
0
    }
329
0
}
330
331
19
bool RuntimeState::is_cancelled() const {
332
    // Maybe we should just return _is_cancelled.load()
333
19
    return !_exec_status.ok() || (_query_ctx && _query_ctx->is_cancelled());
334
19
}
335
336
0
Status RuntimeState::cancel_reason() const {
337
0
    if (!_exec_status.ok()) {
338
0
        return _exec_status.status();
339
0
    }
340
341
0
    if (_query_ctx) {
342
0
        return _query_ctx->exec_status();
343
0
    }
344
345
0
    return Status::Cancelled("Query cancelled");
346
0
}
347
348
const int64_t MAX_ERROR_NUM = 50;
349
350
0
Status RuntimeState::create_error_log_file() {
351
0
    if (config::save_load_error_log_to_s3 && config::is_cloud_mode()) {
352
0
        _s3_error_fs = std::dynamic_pointer_cast<io::S3FileSystem>(
353
0
                ExecEnv::GetInstance()->storage_engine().to_cloud().latest_fs());
354
0
        if (_s3_error_fs) {
355
0
            std::stringstream ss;
356
            // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_err_packet.html
357
            // shorten the path as much as possible to prevent the length of the presigned URL from
358
            // exceeding the MySQL error packet size limit
359
0
            ss << "error_log/" << _import_label << "_" << std::hex << _fragment_instance_id.hi;
360
0
            _s3_error_log_file_path = ss.str();
361
0
        }
362
0
    }
363
364
0
    static_cast<void>(_exec_env->load_path_mgr()->get_load_error_file_name(
365
0
            _db_name, _import_label, _fragment_instance_id, &_error_log_file_path));
366
0
    std::string error_log_absolute_path =
367
0
            _exec_env->load_path_mgr()->get_load_error_absolute_path(_error_log_file_path);
368
0
    _error_log_file = std::make_unique<std::ofstream>(error_log_absolute_path, std::ifstream::out);
369
0
    if (!_error_log_file->is_open()) {
370
0
        std::stringstream error_msg;
371
0
        error_msg << "Fail to open error file: [" << _error_log_file_path << "].";
372
0
        LOG(WARNING) << error_msg.str();
373
0
        return Status::InternalError(error_msg.str());
374
0
    }
375
0
    VLOG_FILE << "create error log file: " << _error_log_file_path;
376
377
0
    return Status::OK();
378
0
}
379
380
Status RuntimeState::append_error_msg_to_file(std::function<std::string()> line,
381
                                              std::function<std::string()> error_msg,
382
0
                                              bool* stop_processing, bool is_summary) {
383
0
    *stop_processing = false;
384
0
    if (query_type() != TQueryType::LOAD) {
385
0
        return Status::OK();
386
0
    }
387
    // If file haven't been opened, open it here
388
0
    if (_error_log_file == nullptr) {
389
0
        Status status = create_error_log_file();
390
0
        if (!status.ok()) {
391
0
            LOG(WARNING) << "Create error file log failed. because: " << status;
392
0
            if (_error_log_file != nullptr) {
393
0
                _error_log_file->close();
394
0
            }
395
0
            return status;
396
0
        }
397
0
    }
398
399
    // if num of printed error row exceeds the limit, and this is not a summary message,
400
    // if _load_zero_tolerance, return Error to stop the load process immediately.
401
0
    if (_num_print_error_rows.fetch_add(1, std::memory_order_relaxed) > MAX_ERROR_NUM &&
402
0
        !is_summary) {
403
0
        if (_load_zero_tolerance) {
404
0
            *stop_processing = true;
405
0
        }
406
0
        return Status::OK();
407
0
    }
408
409
0
    fmt::memory_buffer out;
410
0
    if (is_summary) {
411
0
        fmt::format_to(out, "Summary: {}", error_msg());
412
0
    } else {
413
0
        if (_error_row_number < MAX_ERROR_NUM) {
414
            // Note: export reason first in case src line too long and be truncated.
415
0
            fmt::format_to(out, "Reason: {}. src line [{}]; ", error_msg(), line());
416
0
        } else if (_error_row_number == MAX_ERROR_NUM) {
417
0
            fmt::format_to(out, "TOO MUCH ERROR! already reach {}. show no more next error.",
418
0
                           MAX_ERROR_NUM);
419
0
        }
420
0
    }
421
422
0
    size_t error_row_size = out.size();
423
0
    if (error_row_size > 0) {
424
0
        if (error_row_size > config::load_error_log_limit_bytes) {
425
0
            fmt::memory_buffer limit_byte_out;
426
0
            limit_byte_out.append(out.data(), out.data() + config::load_error_log_limit_bytes);
427
0
            (*_error_log_file) << fmt::to_string(limit_byte_out) + "error log is too long"
428
0
                               << std::endl;
429
0
        } else {
430
0
            (*_error_log_file) << fmt::to_string(out) << std::endl;
431
0
        }
432
0
    }
433
0
    return Status::OK();
434
0
}
435
436
0
std::string RuntimeState::get_error_log_file_path() {
437
0
    std::lock_guard<std::mutex> l(_s3_error_log_file_lock);
438
0
    if (_s3_error_fs && _error_log_file && _error_log_file->is_open()) {
439
        // close error log file
440
0
        _error_log_file->close();
441
0
        std::string error_log_absolute_path =
442
0
                _exec_env->load_path_mgr()->get_load_error_absolute_path(_error_log_file_path);
443
        // upload error log file to s3
444
0
        Status st = _s3_error_fs->upload(error_log_absolute_path, _s3_error_log_file_path);
445
0
        if (st.ok()) {
446
            // remove local error log file
447
0
            std::filesystem::remove(error_log_absolute_path);
448
0
        } else {
449
            // upload failed and return local error log file path
450
0
            LOG(WARNING) << "Fail to upload error file to s3, error_log_file_path="
451
0
                         << _error_log_file_path << ", error=" << st;
452
0
            return _error_log_file_path;
453
0
        }
454
        // expiration must be less than a week (in seconds) for presigned url
455
0
        static const unsigned EXPIRATION_SECONDS = 7 * 24 * 60 * 60 - 1;
456
        // We should return a public endpoint to user.
457
0
        _error_log_file_path = _s3_error_fs->generate_presigned_url(_s3_error_log_file_path,
458
0
                                                                    EXPIRATION_SECONDS, true);
459
0
    }
460
0
    return _error_log_file_path;
461
0
}
462
463
3
void RuntimeState::resize_op_id_to_local_state(int operator_size) {
464
3
    _op_id_to_local_state.resize(-operator_size);
465
3
}
466
467
void RuntimeState::emplace_local_state(
468
3
        int id, std::unique_ptr<doris::pipeline::PipelineXLocalStateBase> state) {
469
3
    id = -id;
470
3
    DCHECK(id < _op_id_to_local_state.size());
471
3
    DCHECK(!_op_id_to_local_state[id]);
472
3
    _op_id_to_local_state[id] = std::move(state);
473
3
}
474
475
4
doris::pipeline::PipelineXLocalStateBase* RuntimeState::get_local_state(int id) {
476
4
    id = -id;
477
4
    return _op_id_to_local_state[id].get();
478
4
}
479
480
3
Result<RuntimeState::LocalState*> RuntimeState::get_local_state_result(int id) {
481
3
    id = -id;
482
3
    if (id >= _op_id_to_local_state.size()) {
483
0
        return ResultError(Status::InternalError("get_local_state out of range size:{} , id:{}",
484
0
                                                 _op_id_to_local_state.size(), id));
485
0
    }
486
3
    if (!_op_id_to_local_state[id]) {
487
0
        return ResultError(Status::InternalError("get_local_state id:{} is null", id));
488
0
    }
489
3
    return _op_id_to_local_state[id].get();
490
3
};
491
492
void RuntimeState::emplace_sink_local_state(
493
0
        int id, std::unique_ptr<doris::pipeline::PipelineXSinkLocalStateBase> state) {
494
0
    DCHECK(!_sink_local_state) << " id=" << id << " state: " << state->debug_string(0);
495
0
    _sink_local_state = std::move(state);
496
0
}
497
498
0
doris::pipeline::PipelineXSinkLocalStateBase* RuntimeState::get_sink_local_state() {
499
0
    return _sink_local_state.get();
500
0
}
501
502
0
Result<RuntimeState::SinkLocalState*> RuntimeState::get_sink_local_state_result() {
503
0
    if (!_sink_local_state) {
504
0
        return ResultError(Status::InternalError("_op_id_to_sink_local_state not exist"));
505
0
    }
506
0
    return _sink_local_state.get();
507
0
}
508
509
0
bool RuntimeState::enable_page_cache() const {
510
0
    return !config::disable_storage_page_cache &&
511
0
           (_query_options.__isset.enable_page_cache && _query_options.enable_page_cache);
512
0
}
513
514
0
RuntimeFilterMgr* RuntimeState::global_runtime_filter_mgr() {
515
0
    return _query_ctx->runtime_filter_mgr();
516
0
}
517
518
Status RuntimeState::register_producer_runtime_filter(
519
        const TRuntimeFilterDesc& desc, std::shared_ptr<IRuntimeFilter>* producer_filter,
520
0
        bool build_bf_exactly) {
521
    // Producers are created by local runtime filter mgr and shared by global runtime filter manager.
522
    // When RF is published, consumers in both global and local RF mgr will be found.
523
0
    RETURN_IF_ERROR(local_runtime_filter_mgr()->register_producer_filter(
524
0
            desc, query_options(), producer_filter, build_bf_exactly));
525
0
    RETURN_IF_ERROR(global_runtime_filter_mgr()->register_local_merge_producer_filter(
526
0
            desc, query_options(), *producer_filter, build_bf_exactly));
527
0
    return Status::OK();
528
0
}
529
530
Status RuntimeState::register_consumer_runtime_filter(
531
        const doris::TRuntimeFilterDesc& desc, bool need_local_merge, int node_id,
532
0
        std::shared_ptr<IRuntimeFilter>* consumer_filter) {
533
0
    if (desc.has_remote_targets || need_local_merge) {
534
0
        return global_runtime_filter_mgr()->register_consumer_filter(desc, query_options(), node_id,
535
0
                                                                     consumer_filter, false, true);
536
0
    } else {
537
0
        return local_runtime_filter_mgr()->register_consumer_filter(desc, query_options(), node_id,
538
0
                                                                    consumer_filter, false, false);
539
0
    }
540
0
}
541
542
0
bool RuntimeState::is_nereids() const {
543
0
    return _query_ctx->is_nereids();
544
0
}
545
546
0
std::vector<std::shared_ptr<RuntimeProfile>> RuntimeState::pipeline_id_to_profile() {
547
0
    std::shared_lock lc(_pipeline_profile_lock);
548
0
    return _pipeline_id_to_profile;
549
0
}
550
551
std::vector<std::shared_ptr<RuntimeProfile>> RuntimeState::build_pipeline_profile(
552
0
        std::size_t pipeline_size) {
553
0
    std::unique_lock lc(_pipeline_profile_lock);
554
0
    if (!_pipeline_id_to_profile.empty()) {
555
0
        throw Exception(ErrorCode::INTERNAL_ERROR,
556
0
                        "build_pipeline_profile can only be called once.");
557
0
    }
558
0
    _pipeline_id_to_profile.resize(pipeline_size);
559
0
    {
560
0
        size_t pip_idx = 0;
561
0
        for (auto& pipeline_profile : _pipeline_id_to_profile) {
562
0
            pipeline_profile =
563
0
                    std::make_shared<RuntimeProfile>("Pipeline : " + std::to_string(pip_idx));
564
0
            pip_idx++;
565
0
        }
566
0
    }
567
0
    return _pipeline_id_to_profile;
568
0
}
569
570
} // end namespace doris