Coverage Report

Created: 2026-11-03 12:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/runtime/runtime_state.h
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.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include <gen_cpp/PaloInternalService_types.h>
24
#include <gen_cpp/Types_types.h>
25
#include <stdint.h>
26
27
#include <atomic>
28
#include <cstdint>
29
#include <fstream>
30
#include <functional>
31
#include <memory>
32
#include <mutex>
33
#include <shared_mutex>
34
#include <string>
35
#include <vector>
36
37
#include "agent/be_exec_version_manager.h"
38
#include "cctz/time_zone.h"
39
#include "common/be_mock_util.h"
40
#include "common/compiler_util.h" // IWYU pragma: keep
41
#include "common/config.h"
42
#include "common/factory_creator.h"
43
#include "common/status.h"
44
#include "exec/scan/vector_search_user_params.h"
45
#include "runtime/runtime_profile.h"
46
#include "runtime/task_execution_context.h"
47
#include "runtime/workload_group/workload_group_fwd.h"
48
#include "util/debug_util.h"
49
#include "util/timezone_utils.h"
50
51
namespace doris {
52
namespace segment_v2 {
53
enum CompressionTypePB : int;
54
}
55
namespace io {
56
class S3FileSystem;
57
} // namespace io
58
class RuntimeFilter;
59
60
2.68M
inline int32_t get_execution_rpc_timeout_ms(int32_t execution_timeout_sec) {
61
2.68M
    return std::min(config::execution_max_rpc_timeout_sec, execution_timeout_sec) * 1000;
62
2.68M
}
63
64
class PipelineXLocalStateBase;
65
class PipelineXSinkLocalStateBase;
66
class PipelineFragmentContext;
67
class PipelineTask;
68
class Dependency;
69
70
class DescriptorTbl;
71
class ObjectPool;
72
class ExecEnv;
73
class IdFileMap;
74
class RuntimeFilterMgr;
75
class MemTrackerLimiter;
76
class QueryContext;
77
class RuntimeFilterConsumer;
78
class RuntimeFilterProducer;
79
class TaskExecutionContext;
80
81
// Keep RuntimeState self-contained without importing the full frontend Thrift service header.
82
class TReportExecStatusParams;
83
class RuntimeState;
84
85
// Owns a share of the external-file report budget until the prepared commit messages are
86
// published. Destruction releases an unpublished reservation automatically.
87
class ExternalFileReportReservation {
88
public:
89
5
    ExternalFileReportReservation() = default;
90
    ~ExternalFileReportReservation();
91
92
    ExternalFileReportReservation(const ExternalFileReportReservation&) = delete;
93
    ExternalFileReportReservation& operator=(const ExternalFileReportReservation&) = delete;
94
95
private:
96
    friend class RuntimeState;
97
98
    RuntimeState* _state = nullptr;
99
    size_t _reserved_bytes = 0;
100
};
101
102
class ExternalFileReportState {
103
    friend class RuntimeState;
104
105
private:
106
    std::mutex mutex;
107
    size_t serialized_commit_bytes = 0;
108
    bool ownership_may_have_transferred = false;
109
    std::vector<std::function<void()>> rejected_report_cleanups;
110
};
111
112
enum class ExternalFileReportOutcome { ACKNOWLEDGED, REJECTED, AMBIGUOUS };
113
114
// A collection of items that are part of the global state of a
115
// query and shared across all execution nodes of that query.
116
class RuntimeState {
117
    ENABLE_FACTORY_CREATOR(RuntimeState);
118
119
public:
120
    RuntimeState(const TPlanFragmentExecParams& fragment_exec_params,
121
                 const TQueryOptions& query_options, const TQueryGlobals& query_globals,
122
                 ExecEnv* exec_env, QueryContext* ctx,
123
                 const std::shared_ptr<MemTrackerLimiter>& query_mem_tracker = nullptr);
124
125
    RuntimeState(const TUniqueId& instance_id, const TUniqueId& query_id, int32_t fragment_id,
126
                 const TQueryOptions& query_options, const TQueryGlobals& query_globals,
127
                 ExecEnv* exec_env, QueryContext* ctx);
128
129
    // Used by pipeline. This runtime state is only used for setup.
130
    RuntimeState(const TUniqueId& query_id, int32_t fragment_id, const TQueryOptions& query_options,
131
                 const TQueryGlobals& query_globals, ExecEnv* exec_env, QueryContext* ctx);
132
133
    // Only used in the materialization phase of delayed materialization,
134
    // when there may be no corresponding QueryContext.
135
    RuntimeState(const TUniqueId& query_id, int32_t fragment_id, const TQueryOptions& query_options,
136
                 const TQueryGlobals& query_globals, ExecEnv* exec_env,
137
                 const std::shared_ptr<MemTrackerLimiter>& query_mem_tracker);
138
139
    // RuntimeState for executing expr in fe-support.
140
    RuntimeState(const TQueryOptions& query_options, const TQueryGlobals& query_globals);
141
142
    // for job task only
143
    RuntimeState();
144
145
    // Empty d'tor to avoid issues with unique_ptr.
146
    MOCK_DEFINE(virtual) ~RuntimeState();
147
148
    // Set per-query state.
149
    Status init(const TUniqueId& fragment_instance_id, const TQueryOptions& query_options,
150
                const TQueryGlobals& query_globals, ExecEnv* exec_env);
151
152
    // for ut and non-query.
153
    void set_exec_env(ExecEnv* exec_env) { _exec_env = exec_env; }
154
155
    // for ut and non-query.
156
    void init_mem_trackers(const std::string& name = "ut", const TUniqueId& id = TUniqueId());
157
158
37.4M
    const TQueryOptions& query_options() const { return _query_options; }
159
226k
    int64_t scan_queue_mem_limit() const {
160
226k
        return _query_options.__isset.scan_queue_mem_limit ? _query_options.scan_queue_mem_limit
161
226k
                                                           : _query_options.mem_limit / 20;
162
226k
    }
163
164
778k
    bool enable_adjust_conjunct_order_by_cost() const {
165
778k
        return _query_options.__isset.enable_adjust_conjunct_order_by_cost &&
166
778k
               _query_options.enable_adjust_conjunct_order_by_cost;
167
778k
    }
168
169
228k
    int32_t max_column_reader_num() const {
170
228k
        return _query_options.__isset.max_column_reader_num ? _query_options.max_column_reader_num
171
228k
                                                            : 20000;
172
228k
    }
173
174
6.57M
    ObjectPool* obj_pool() const { return _obj_pool.get(); }
175
176
5.17M
    const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
177
2.45M
    void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
178
179
    // Row-count limit for output blocks. Clamp to [1, 65535].
180
    // Adaptive byte budgeting still uses this as the hard row ceiling.
181
17.8M
    MOCK_FUNCTION int batch_size() const {
182
17.8M
        static constexpr int kMax = 65535;
183
17.8M
        auto v = _query_options.batch_size;
184
17.8M
        return std::min(std::max(1, v), kMax);
185
17.8M
    }
186
187
    // Target byte budget per output block (default 8MB when adaptive is enabled).
188
    // The public FE/session contract is [1MB, 512MB]; this accessor still clamps any direct
189
    // thrift or mixed-version out-of-range value into that range. Returns `kMax` when adaptive
190
    // is disabled by BE config so the value is always a legal byte budget; callers that need
191
    // to know whether adaptive batch size is active should test
192
    // `config::enable_adaptive_batch_size` explicitly.
193
4.01M
    MOCK_FUNCTION size_t preferred_block_size_bytes() const {
194
4.01M
        static constexpr int64_t kDefault = 8388608L; // 8MB
195
4.01M
        static constexpr int64_t kMax = 536870912L;   // 512MB
196
4.01M
        static constexpr int64_t kMin = 1048576L;     // 1MB
197
4.01M
        if (!config::enable_adaptive_batch_size) [[unlikely]] {
198
7.30k
            return kMax;
199
7.30k
        }
200
4.01M
        if (_query_options.__isset.preferred_block_size_bytes) [[likely]] {
201
4.01M
            return std::max<int64_t>(
202
4.01M
                    kMin, std::min<int64_t>(_query_options.preferred_block_size_bytes, kMax));
203
4.01M
        }
204
18.4E
        return kDefault;
205
4.00M
    }
206
207
956k
    int query_parallel_instance_num() const { return _query_options.parallel_instance; }
208
0
    int max_errors() const { return _query_options.max_errors; }
209
2.97M
    int execution_timeout() const {
210
2.97M
        return _query_options.__isset.execution_timeout ? _query_options.execution_timeout
211
18.4E
                                                        : _query_options.query_timeout;
212
2.97M
    }
213
439k
    int max_scanners_concurrency() const {
214
439k
        return _query_options.__isset.max_scanners_concurrency
215
440k
                       ? _query_options.max_scanners_concurrency
216
18.4E
                       : 0;
217
439k
    }
218
12.1k
    int max_file_scanners_concurrency() const {
219
12.1k
        return _query_options.__isset.max_file_scanners_concurrency
220
12.1k
                       ? _query_options.max_file_scanners_concurrency
221
18.4E
                       : max_scanners_concurrency();
222
12.1k
    }
223
224
440k
    int min_scanners_concurrency() const {
225
440k
        return _query_options.__isset.min_scanners_concurrency
226
441k
                       ? _query_options.min_scanners_concurrency
227
18.4E
                       : 1;
228
440k
    }
229
230
4.05k
    int min_file_scanners_concurrency() const {
231
4.05k
        return _query_options.__isset.min_file_scanners_concurrency
232
4.05k
                       ? _query_options.min_file_scanners_concurrency
233
4.05k
                       : 1;
234
4.05k
    }
235
236
    // Support extended regex
237
    // like look-around zero-width assertions(`?=`, `?!`, `?<=`, `?<!`)
238
8.85k
    bool enable_extended_regex() const {
239
8.85k
        return _query_options.__isset.enable_extended_regex && _query_options.enable_extended_regex;
240
8.85k
    }
241
242
98.1k
    TQueryType::type query_type() const { return _query_options.query_type; }
243
48.6k
    int64_t timestamp_ms() const { return _timestamp_ms; }
244
48.8k
    int32_t nano_seconds() const { return _nano_seconds; }
245
    // if possible, use timezone_obj() rather than timezone()
246
262k
    const std::string& timezone() const { return _timezone; }
247
347k
    const cctz::time_zone& timezone_obj() const { return _timezone_obj; }
248
486
    void set_timezone(const std::string& timezone) {
249
486
        _timezone = timezone;
250
486
        TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj);
251
486
    }
252
519
    const std::string& lc_time_names() const { return _lc_time_names; }
253
12.6M
    const TUniqueId& query_id() const { return _query_id; }
254
2.10M
    const TUniqueId& fragment_instance_id() const { return _fragment_instance_id; }
255
    // should only be called in pipeline engine
256
1.02k
    int32_t fragment_id() const { return _fragment_id; }
257
3.50M
    ExecEnv* exec_env() { return _exec_env; }
258
    std::shared_ptr<MemTrackerLimiter> query_mem_tracker() const;
259
260
    // Returns runtime state profile
261
1.70k
    RuntimeProfile* runtime_profile() { return &_profile; }
262
78.5k
    RuntimeProfile* load_channel_profile() { return &_load_channel_profile; }
263
264
309k
    bool enable_function_pushdown() const {
265
309k
        return _query_options.__isset.enable_function_pushdown &&
266
309k
               _query_options.enable_function_pushdown;
267
309k
    }
268
269
738k
    bool check_overflow_for_decimal() const {
270
738k
        return _query_options.__isset.check_overflow_for_decimal &&
271
738k
               _query_options.check_overflow_for_decimal;
272
738k
    }
273
274
743k
    bool enable_strict_mode() const {
275
743k
        return _query_options.__isset.enable_strict_cast && _query_options.enable_strict_cast;
276
743k
    }
277
278
107
    bool enable_insert_strict() const {
279
107
        return _query_options.__isset.enable_insert_strict && _query_options.enable_insert_strict;
280
107
    }
281
282
921k
    bool enable_segment_limit_pushdown() const {
283
921k
        return !_query_options.__isset.enable_segment_limit_pushdown ||
284
922k
               _query_options.enable_segment_limit_pushdown;
285
921k
    }
286
287
386k
    bool mysql_row_binary_format() const {
288
386k
        return _query_options.__isset.mysql_row_binary_format &&
289
386k
               _query_options.mysql_row_binary_format;
290
386k
    }
291
292
22
    bool enable_short_circuit_query_access_column_store() const {
293
22
        return _query_options.__isset.enable_short_circuit_query_access_column_store &&
294
22
               _query_options.enable_short_circuit_query_access_column_store;
295
22
    }
296
297
    // Appends error to the _error_log if there is space
298
    bool log_error(const std::string& error);
299
300
    // Returns true if the error log has not reached _max_errors.
301
0
    bool log_has_space() {
302
0
        std::lock_guard<std::mutex> l(_error_log_lock);
303
0
        return _error_log.size() < _query_options.max_errors;
304
0
    }
305
306
    // Append all _error_log[_unreported_error_idx+] to new_errors and set
307
    // _unreported_error_idx to _errors_log.size()
308
    void get_unreported_errors(std::vector<std::string>* new_errors);
309
310
    [[nodiscard]] MOCK_FUNCTION bool is_cancelled() const;
311
    MOCK_FUNCTION Status cancel_reason() const;
312
36
    void cancel(const Status& reason) {
313
36
        if (_exec_status.update(reason)) {
314
            // Create a error status, so that we could print error stack, and
315
            // we could know which path call cancel.
316
36
            LOG(WARNING) << "Task is cancelled, instance: "
317
36
                         << PrintInstanceStandardInfo(_query_id, _fragment_instance_id)
318
36
                         << ", st = " << reason;
319
36
        } else {
320
0
            LOG(WARNING) << "Task is already cancelled, instance: "
321
0
                         << PrintInstanceStandardInfo(_query_id, _fragment_instance_id)
322
0
                         << ", original cancel msg: " << _exec_status.status()
323
0
                         << ", new cancel msg: " << reason;
324
0
        }
325
36
    }
326
327
2.14M
    void set_backend_id(int64_t backend_id) { _backend_id = backend_id; }
328
68
    int64_t backend_id() const { return _backend_id; }
329
330
1.78M
    void set_be_number(int be_number) { _be_number = be_number; }
331
3.44M
    int be_number(void) const { return _be_number; }
332
333
6.54k
    std::vector<std::string>& output_files() { return _output_files; }
334
335
1.76k
    void set_import_label(const std::string& import_label) { _import_label = import_label; }
336
337
201k
    const std::vector<std::string>& export_output_files() const { return _export_output_files; }
338
339
0
    void add_export_output_file(const std::string& file) { _export_output_files.push_back(file); }
340
341
533
    void set_db_name(const std::string& db_name) { _db_name = db_name; }
342
343
0
    const std::string& db_name() { return _db_name; }
344
345
1.26k
    void set_wal_id(int64_t wal_id) { _wal_id = wal_id; }
346
347
156k
    int64_t wal_id() const { return _wal_id; }
348
349
429
    void set_content_length(size_t content_length) { _content_length = content_length; }
350
351
4
    size_t content_length() const { return _content_length; }
352
353
576
    const std::string& import_label() { return _import_label; }
354
355
0
    const std::string& load_dir() const { return _load_dir; }
356
357
0
    void set_load_job_id(int64_t job_id) { _load_job_id = job_id; }
358
359
48.1k
    int64_t load_job_id() const { return _load_job_id; }
360
361
    std::string get_error_log_file_path();
362
363
    std::string get_first_error_msg() const;
364
365
    // append error msg and error line to file when loading data.
366
    // is_summary is true, means we are going to write the summary line
367
    // If we need to stop the processing, set stop_processing to true
368
    Status append_error_msg_to_file(std::function<std::string()> line,
369
                                    std::function<std::string()> error_msg);
370
371
75.4k
    int64_t num_bytes_load_total() { return _num_bytes_load_total.load(); }
372
373
201k
    int64_t num_finished_range() { return _num_finished_scan_range.load(); }
374
375
315k
    int64_t num_rows_load_total() { return _num_rows_load_total.load(); }
376
377
291k
    int64_t num_rows_load_filtered() { return _num_rows_load_filtered.load(); }
378
379
123k
    int64_t num_rows_load_unselected() { return _num_rows_load_unselected.load(); }
380
381
97.1k
    int64_t num_rows_filtered_in_strict_mode_partial_update() {
382
97.1k
        return _num_rows_filtered_in_strict_mode_partial_update;
383
97.1k
    }
384
385
36.9k
    int64_t num_rows_load_success() {
386
36.9k
        return num_rows_load_total() - num_rows_load_filtered() - num_rows_load_unselected();
387
36.9k
    }
388
389
43.2k
    void update_num_rows_load_total(int64_t num_rows) { _num_rows_load_total.fetch_add(num_rows); }
390
391
49.1k
    void set_num_rows_load_total(int64_t num_rows) { _num_rows_load_total.store(num_rows); }
392
393
43.2k
    void update_num_bytes_load_total(int64_t bytes_load) {
394
43.2k
        _num_bytes_load_total.fetch_add(bytes_load);
395
43.2k
    }
396
397
3.34k
    void update_num_finished_scan_range(int64_t finished_range) {
398
3.34k
        _num_finished_scan_range.fetch_add(finished_range);
399
3.34k
    }
400
401
51.9k
    void update_num_rows_load_filtered(int64_t num_rows) {
402
51.9k
        _num_rows_load_filtered.fetch_add(num_rows);
403
51.9k
    }
404
405
51.4k
    void update_num_rows_load_unselected(int64_t num_rows) {
406
51.4k
        _num_rows_load_unselected.fetch_add(num_rows);
407
51.4k
    }
408
409
70
    void set_num_rows_filtered_in_strict_mode_partial_update(int64_t num_rows) {
410
70
        _num_rows_filtered_in_strict_mode_partial_update = num_rows;
411
70
    }
412
413
1.77M
    void set_per_fragment_instance_idx(int idx) { _per_fragment_instance_idx = idx; }
414
415
269k
    int per_fragment_instance_idx() const { return _per_fragment_instance_idx; }
416
417
2.14M
    void set_num_per_fragment_instances(int num_instances) {
418
2.14M
        _num_per_fragment_instances = num_instances;
419
2.14M
    }
420
421
48.1k
    int num_per_fragment_instances() const { return _num_per_fragment_instances; }
422
423
2.14M
    void set_load_stream_per_node(int load_stream_per_node) {
424
2.14M
        _load_stream_per_node = load_stream_per_node;
425
2.14M
    }
426
427
28
    int load_stream_per_node() const { return _load_stream_per_node; }
428
429
2.14M
    void set_total_load_streams(int total_load_streams) {
430
2.14M
        _total_load_streams = total_load_streams;
431
2.14M
    }
432
433
28
    int total_load_streams() const { return _total_load_streams; }
434
435
2.14M
    void set_num_local_sink(int num_local_sink) { _num_local_sink = num_local_sink; }
436
437
28
    int num_local_sink() const { return _num_local_sink; }
438
439
0
    bool disable_stream_preaggregations() const {
440
0
        return _query_options.disable_stream_preaggregations;
441
0
    }
442
443
0
    int32_t runtime_filter_wait_time_ms() const {
444
0
        return _query_options.runtime_filter_wait_time_ms;
445
0
    }
446
447
1.31k
    int32_t runtime_filter_max_in_num() const { return _query_options.runtime_filter_max_in_num; }
448
449
18.4M
    int be_exec_version() const {
450
18.4M
        DCHECK(_query_options.__isset.be_exec_version &&
451
18.4M
               BeExecVersionManager::check_be_exec_version(_query_options.be_exec_version));
452
18.4M
        return _query_options.be_exec_version;
453
18.4M
    }
454
370k
    bool plan_local_shuffle() const {
455
        // If local shuffle is enabled and not planned by local shuffle planner, we should plan local shuffle in BE.
456
370k
        return _query_options.__isset.enable_local_shuffle && _query_options.enable_local_shuffle &&
457
370k
               (!_query_options.__isset.enable_local_shuffle_planner ||
458
367k
                !_query_options.enable_local_shuffle_planner);
459
370k
    }
460
461
2.53M
    MOCK_FUNCTION bool enable_local_exchange() const {
462
2.54M
        return _query_options.__isset.enable_local_exchange && _query_options.enable_local_exchange;
463
2.53M
    }
464
465
3.61k
    bool trim_tailing_spaces_for_external_table_query() const {
466
3.61k
        return _query_options.trim_tailing_spaces_for_external_table_query;
467
3.61k
    }
468
469
384k
    bool return_object_data_as_binary() const {
470
384k
        return _query_options.return_object_data_as_binary;
471
384k
    }
472
473
6.14M
    bool enable_fuzzy_blockable_task() const {
474
6.14M
        return _query_options.__isset.enable_fuzzy_blockable_task &&
475
6.14M
               _query_options.enable_fuzzy_blockable_task;
476
6.14M
    }
477
478
    segment_v2::CompressionTypePB fragement_transmission_compression_type() const;
479
480
1.84M
    bool skip_storage_engine_merge() const {
481
1.84M
        return _query_options.__isset.skip_storage_engine_merge &&
482
1.84M
               _query_options.skip_storage_engine_merge;
483
1.84M
    }
484
485
1.08M
    bool skip_delete_predicate() const {
486
1.08M
        return _query_options.__isset.skip_delete_predicate && _query_options.skip_delete_predicate;
487
1.08M
    }
488
489
927k
    bool skip_delete_bitmap() const {
490
929k
        return _query_options.__isset.skip_delete_bitmap && _query_options.skip_delete_bitmap;
491
927k
    }
492
493
1.08M
    bool skip_missing_version() const {
494
1.08M
        return _query_options.__isset.skip_missing_version && _query_options.skip_missing_version;
495
1.08M
    }
496
497
9.97k
    int64_t data_queue_max_blocks() const {
498
9.98k
        return _query_options.__isset.data_queue_max_blocks ? _query_options.data_queue_max_blocks
499
18.4E
                                                            : 1;
500
9.97k
    }
501
502
    bool enable_page_cache() const;
503
504
1.06M
    bool enable_prefer_cached_rowset() const {
505
1.06M
        return _query_options.__isset.enable_prefer_cached_rowset &&
506
1.06M
               _query_options.enable_prefer_cached_rowset;
507
1.06M
    }
508
509
1.06M
    int64_t query_freshness_tolerance_ms() const {
510
1.06M
        return _query_options.query_freshness_tolerance_ms;
511
1.06M
    }
512
513
0
    bool enable_query_freshness_tolerance() const {
514
0
        return _query_options.__isset.query_freshness_tolerance_ms &&
515
0
               _query_options.query_freshness_tolerance_ms > 0;
516
0
    }
517
518
204k
    std::vector<TTabletCommitInfo> tablet_commit_infos() const {
519
204k
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
520
204k
        return _tablet_commit_infos;
521
204k
    }
522
523
49.9k
    void add_tablet_commit_infos(std::vector<TTabletCommitInfo>& commit_infos) {
524
49.9k
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
525
49.9k
        _tablet_commit_infos.insert(_tablet_commit_infos.end(),
526
49.9k
                                    std::make_move_iterator(commit_infos.begin()),
527
49.9k
                                    std::make_move_iterator(commit_infos.end()));
528
49.9k
    }
529
530
201k
    std::vector<TErrorTabletInfo> error_tablet_infos() const {
531
201k
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
532
201k
        return _error_tablet_infos;
533
201k
    }
534
535
49.8k
    void add_error_tablet_infos(std::vector<TErrorTabletInfo>& tablet_infos) {
536
49.8k
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
537
49.8k
        _error_tablet_infos.insert(_error_tablet_infos.end(),
538
49.8k
                                   std::make_move_iterator(tablet_infos.begin()),
539
49.8k
                                   std::make_move_iterator(tablet_infos.end()));
540
49.8k
    }
541
542
180k
    std::vector<THivePartitionUpdate> hive_partition_updates() const {
543
180k
        std::lock_guard<std::mutex> lock(_hive_partition_updates_mutex);
544
180k
        return _hive_partition_updates;
545
180k
    }
546
547
8
    void add_hive_partition_updates(const THivePartitionUpdate& hive_partition_update) {
548
8
        std::lock_guard<std::mutex> lock(_hive_partition_updates_mutex);
549
8
        _hive_partition_updates.emplace_back(hive_partition_update);
550
8
    }
551
552
180k
    void append_iceberg_commit_datas(std::vector<TIcebergCommitData>* output) const {
553
180k
        std::lock_guard<std::mutex> lock(_iceberg_commit_datas_mutex);
554
180k
        output->insert(output->end(), _iceberg_commit_datas.begin(), _iceberg_commit_datas.end());
555
180k
    }
556
557
    Status add_iceberg_commit_datas(TIcebergCommitData iceberg_commit_data);
558
559
    // Reserve report space before closing the Paimon writer, then either publish the prepared
560
    // messages after a clean close or let the reservation release itself while aborting the writer.
561
    Status reserve_paimon_commit_messages(const std::vector<TPaimonCommitMessage>& commit_messages,
562
                                          ExternalFileReportReservation* reservation);
563
564
    void publish_reserved_paimon_commit_messages(std::vector<TPaimonCommitMessage> commit_messages,
565
                                                 ExternalFileReportReservation* reservation);
566
567
180k
    void append_paimon_commit_messages(std::vector<TPaimonCommitMessage>* output) const {
568
180k
        std::lock_guard<std::mutex> lock(_paimon_commit_messages_mutex);
569
180k
        output->insert(output->end(), _paimon_commit_messages.begin(),
570
180k
                       _paimon_commit_messages.end());
571
180k
    }
572
573
    size_t coordinator_thrift_message_limit() const;
574
575
    void append_external_file_commit_data(TReportExecStatusParams* params, bool final_report) const;
576
577
    void add_rejected_external_file_report_cleanup(std::function<void()> cleanup);
578
579
    void finalize_external_file_report_cleanup(ExternalFileReportOutcome outcome);
580
581
1.78M
    void set_external_file_report_state(std::shared_ptr<ExternalFileReportState> report_state) {
582
1.78M
        _external_file_report_state = std::move(report_state);
583
1.78M
    }
584
585
1.77M
    const std::shared_ptr<ExternalFileReportState>& external_file_report_state() const {
586
1.77M
        return _external_file_report_state;
587
1.77M
    }
588
589
180k
    std::vector<TMCCommitData> mc_commit_datas() const {
590
180k
        std::lock_guard<std::mutex> lock(_mc_commit_datas_mutex);
591
180k
        return _mc_commit_datas;
592
180k
    }
593
594
1
    void add_mc_commit_datas(const TMCCommitData& mc_commit_data) {
595
1
        std::lock_guard<std::mutex> lock(_mc_commit_datas_mutex);
596
1
        _mc_commit_datas.emplace_back(mc_commit_data);
597
1
    }
598
599
    // local runtime filter mgr, the runtime filter do not have remote target or
600
    // not need local merge should regist here. the instance exec finish, the local
601
    // runtime filter mgr can release the memory of local runtime filter
602
98.9k
    RuntimeFilterMgr* local_runtime_filter_mgr() { return _runtime_filter_mgr; }
603
604
    RuntimeFilterMgr* global_runtime_filter_mgr();
605
606
1.77M
    void set_runtime_filter_mgr(RuntimeFilterMgr* runtime_filter_mgr) {
607
1.77M
        _runtime_filter_mgr = runtime_filter_mgr;
608
1.77M
    }
609
610
73.3M
    QueryContext* get_query_ctx() const { return _query_ctx; }
611
612
    [[nodiscard]] bool low_memory_mode() const;
613
614
    std::weak_ptr<QueryContext> get_query_ctx_weak();
615
    MOCK_FUNCTION WorkloadGroupPtr workload_group();
616
617
1.77M
    void set_query_mem_tracker(const std::shared_ptr<MemTrackerLimiter>& tracker) {
618
1.77M
        _query_mem_tracker = tracker;
619
1.77M
    }
620
621
5.98k
    void set_query_options(const TQueryOptions& query_options) { _query_options = query_options; }
622
623
2.84M
    bool enable_profile() const {
624
2.85M
        return _query_options.__isset.enable_profile && _query_options.enable_profile;
625
2.84M
    }
626
627
169
    int cte_max_recursion_depth() const {
628
169
        return _query_options.__isset.cte_max_recursion_depth
629
169
                       ? _query_options.cte_max_recursion_depth
630
169
                       : 0;
631
169
    }
632
633
60
    bool enable_streaming_agg_hash_join_force_passthrough() const {
634
60
        return _query_options.__isset.enable_streaming_agg_hash_join_force_passthrough &&
635
60
               _query_options.enable_streaming_agg_hash_join_force_passthrough;
636
60
    }
637
638
34.1k
    bool enable_local_exchange_before_agg() const {
639
34.1k
        return _query_options.__isset.enable_local_exchange_before_agg &&
640
34.1k
               _query_options.enable_local_exchange_before_agg;
641
34.1k
    }
642
643
1.52k
    bool enable_local_exchange_before_streaming_agg() const {
644
1.52k
        return _query_options.__isset.enable_local_exchange_before_streaming_agg &&
645
1.52k
               _query_options.enable_local_exchange_before_streaming_agg;
646
1.52k
    }
647
648
7.66k
    bool enable_distinct_streaming_agg_force_passthrough() const {
649
7.66k
        return _query_options.__isset.enable_distinct_streaming_agg_force_passthrough &&
650
7.66k
               _query_options.enable_distinct_streaming_agg_force_passthrough;
651
7.66k
    }
652
653
9.61k
    bool enable_broadcast_join_force_passthrough() const {
654
9.61k
        return _query_options.__isset.enable_broadcast_join_force_passthrough &&
655
9.61k
               _query_options.enable_broadcast_join_force_passthrough;
656
9.61k
    }
657
658
229k
    int rpc_verbose_profile_max_instance_count() const {
659
229k
        return _query_options.__isset.rpc_verbose_profile_max_instance_count
660
229k
                       ? _query_options.rpc_verbose_profile_max_instance_count
661
229k
                       : 0;
662
229k
    }
663
664
15.2k
    MOCK_FUNCTION bool enable_share_hash_table_for_broadcast_join() const {
665
15.2k
        return _query_options.__isset.enable_share_hash_table_for_broadcast_join &&
666
15.2k
               _query_options.enable_share_hash_table_for_broadcast_join;
667
15.2k
    }
668
669
241k
    bool enable_parallel_scan() const {
670
241k
        return _query_options.__isset.enable_parallel_scan && _query_options.enable_parallel_scan;
671
241k
    }
672
673
123k
    bool enable_aggregate_function_null_v2() const {
674
123k
        return _query_options.__isset.enable_aggregate_function_null_v2 &&
675
123k
               _query_options.enable_aggregate_function_null_v2;
676
123k
    }
677
678
1.22M
    bool enable_prune_nested_column() const {
679
1.22M
        return _query_options.__isset.enable_prune_nested_column &&
680
1.22M
               _query_options.enable_prune_nested_column;
681
1.22M
    }
682
683
28
    bool is_read_csv_empty_line_as_null() const {
684
28
        return _query_options.__isset.read_csv_empty_line_as_null &&
685
28
               _query_options.read_csv_empty_line_as_null;
686
28
    }
687
688
119k
    int parallel_scan_max_scanners_count() const {
689
119k
        return _query_options.__isset.parallel_scan_max_scanners_count
690
119k
                       ? _query_options.parallel_scan_max_scanners_count
691
119k
                       : 0;
692
119k
    }
693
694
47.6k
    int partition_topn_max_partitions() const {
695
47.6k
        return _query_options.__isset.partition_topn_max_partitions
696
47.6k
                       ? _query_options.partition_topn_max_partitions
697
47.6k
                       : 1024;
698
47.6k
    }
699
700
0
    int partition_topn_per_partition_rows() const {
701
0
        return _query_options.__isset.partition_topn_pre_partition_rows
702
0
                       ? _query_options.partition_topn_pre_partition_rows
703
0
                       : 1000;
704
0
    }
705
706
119k
    int64_t parallel_scan_min_rows_per_scanner() const {
707
119k
        return _query_options.__isset.parallel_scan_min_rows_per_scanner
708
119k
                       ? _query_options.parallel_scan_min_rows_per_scanner
709
18.4E
                       : 0;
710
119k
    }
711
712
3.26k
    void set_be_exec_version(int32_t version) noexcept { _query_options.be_exec_version = version; }
713
714
    using LocalState = doris::PipelineXLocalStateBase;
715
    using SinkLocalState = doris::PipelineXSinkLocalStateBase;
716
    // get result can return an error message, and we will only call it during the prepare.
717
    void emplace_local_state(int id, std::unique_ptr<LocalState> state);
718
719
    LocalState* get_local_state(int id);
720
    Result<LocalState*> get_local_state_result(int id);
721
722
    void emplace_sink_local_state(int id, std::unique_ptr<SinkLocalState> state);
723
724
    SinkLocalState* get_sink_local_state();
725
726
    Result<SinkLocalState*> get_sink_local_state_result();
727
728
    void resize_op_id_to_local_state(int operator_size);
729
730
    std::vector<std::shared_ptr<RuntimeProfile>> pipeline_id_to_profile();
731
732
    std::vector<std::shared_ptr<RuntimeProfile>> build_pipeline_profile(std::size_t pipeline_size);
733
734
2.22M
    void set_task_execution_context(std::shared_ptr<TaskExecutionContext> context) {
735
2.22M
        _task_execution_context_inited = true;
736
2.22M
        _task_execution_context = context;
737
2.22M
    }
738
739
70.2k
    bool task_execution_context_inited() const { return _task_execution_context_inited; }
740
741
2.03M
    std::weak_ptr<TaskExecutionContext> get_task_execution_context() {
742
18.4E
        CHECK(_task_execution_context_inited)
743
18.4E
                << "_task_execution_context_inited == false, the ctx is not inited";
744
2.03M
        return _task_execution_context;
745
2.03M
    }
746
747
    Status register_producer_runtime_filter(
748
            const doris::TRuntimeFilterDesc& desc,
749
            std::shared_ptr<RuntimeFilterProducer>* producer_filter);
750
751
    Status register_consumer_runtime_filter(
752
            const doris::TRuntimeFilterDesc& desc, bool need_local_merge, int node_id,
753
            std::shared_ptr<RuntimeFilterConsumer>* consumer_filter);
754
755
    bool is_nereids() const;
756
757
7.01M
    bool enable_spill() const {
758
7.01M
        return (_query_options.__isset.enable_force_spill && _query_options.enable_force_spill) ||
759
7.01M
               (_query_options.__isset.enable_spill && _query_options.enable_spill);
760
7.01M
    }
761
762
13.2M
    bool enable_force_spill() const {
763
13.2M
        return _query_options.__isset.enable_force_spill && _query_options.enable_force_spill;
764
13.2M
    }
765
766
46.4k
    int64_t spill_min_revocable_mem() const {
767
46.4k
        if (_query_options.__isset.min_revocable_mem) {
768
46.4k
            return std::max(_query_options.min_revocable_mem, (int64_t)1 << 20);
769
46.4k
        }
770
18.4E
        return 32 << 20;
771
46.4k
    }
772
773
123
    int spill_aggregation_partition_count() const {
774
123
        if (_query_options.__isset.spill_aggregation_partition_count) {
775
123
            return std::min(std::max(2, _query_options.spill_aggregation_partition_count), 32);
776
123
        }
777
0
        return 8;
778
123
    }
779
780
15
    int spill_hash_join_partition_count() const {
781
15
        if (_query_options.__isset.spill_hash_join_partition_count) {
782
15
            return std::min(std::max(2, _query_options.spill_hash_join_partition_count), 32);
783
15
        }
784
0
        return 8;
785
15
    }
786
787
68
    int spill_repartition_max_depth() const {
788
68
        if (_query_options.__isset.spill_repartition_max_depth) {
789
            // Clamp to a reasonable range: [1, 128]
790
68
            return std::max(1, std::min(_query_options.spill_repartition_max_depth, 128));
791
68
        }
792
0
        return 8;
793
68
    }
794
795
289k
    int64_t spill_buffer_size_bytes() const {
796
        // clamp to [1MB, 256MB]
797
289k
        constexpr int64_t kMin = 1LL * 1024 * 1024;
798
289k
        constexpr int64_t kMax = 256LL * 1024 * 1024;
799
289k
        if (_query_options.__isset.spill_buffer_size_bytes) {
800
289k
            int64_t v = _query_options.spill_buffer_size_bytes;
801
289k
            if (v < kMin) return kMin;
802
289k
            if (v > kMax) return kMax;
803
289k
            return v;
804
289k
        }
805
18.4E
        return 8LL * 1024 * 1024;
806
289k
    }
807
808
    // Per-sink memory limits: after spill is triggered, the sink proactively
809
    // spills when its revocable memory exceeds this threshold.
810
    // Clamped to [1MB, 4GB], default 64MB.
811
2
    int64_t spill_join_build_sink_mem_limit_bytes() const {
812
2
        constexpr int64_t kMin = 1LL * 1024 * 1024;
813
2
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
814
2
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
815
2
        if (_query_options.__isset.spill_join_build_sink_mem_limit_bytes) {
816
2
            int64_t v = _query_options.spill_join_build_sink_mem_limit_bytes;
817
2
            return std::min(std::max(v, kMin), kMax);
818
2
        }
819
0
        return kDefault;
820
2
    }
821
822
228
    int64_t spill_aggregation_sink_mem_limit_bytes() const {
823
228
        constexpr int64_t kMin = 1LL * 1024 * 1024;
824
228
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
825
228
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
826
228
        if (_query_options.__isset.spill_aggregation_sink_mem_limit_bytes) {
827
228
            int64_t v = _query_options.spill_aggregation_sink_mem_limit_bytes;
828
228
            return std::min(std::max(v, kMin), kMax);
829
228
        }
830
0
        return kDefault;
831
228
    }
832
833
46
    int64_t spill_sort_sink_mem_limit_bytes() const {
834
46
        constexpr int64_t kMin = 1LL * 1024 * 1024;
835
46
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
836
46
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
837
46
        if (_query_options.__isset.spill_sort_sink_mem_limit_bytes) {
838
46
            int64_t v = _query_options.spill_sort_sink_mem_limit_bytes;
839
46
            return std::min(std::max(v, kMin), kMax);
840
46
        }
841
0
        return kDefault;
842
46
    }
843
844
7.51k
    int64_t spill_analytic_sink_mem_limit_bytes() const {
845
7.51k
        constexpr int64_t kMin = 1LL * 1024 * 1024;
846
7.51k
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
847
7.51k
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
848
7.51k
        if (_query_options.__isset.spill_analytic_sink_mem_limit_bytes) {
849
7.51k
            int64_t v = _query_options.spill_analytic_sink_mem_limit_bytes;
850
7.51k
            return std::min(std::max(v, kMin), kMax);
851
7.51k
        }
852
0
        return kDefault;
853
7.51k
    }
854
855
17
    int64_t spill_sort_merge_mem_limit_bytes() const {
856
17
        constexpr int64_t kMin = 1LL * 1024 * 1024;
857
17
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
858
17
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
859
17
        if (_query_options.__isset.spill_sort_merge_mem_limit_bytes) {
860
17
            int64_t v = _query_options.spill_sort_merge_mem_limit_bytes;
861
17
            return std::min(std::max(v, kMin), kMax);
862
17
        }
863
0
        return kDefault;
864
17
    }
865
866
896
    int64_t low_memory_mode_buffer_limit() const {
867
896
        if (_query_options.__isset.low_memory_mode_buffer_limit) {
868
896
            return std::max(_query_options.low_memory_mode_buffer_limit, (int64_t)1);
869
896
        }
870
0
        return 32L * 1024 * 1024;
871
896
    }
872
873
0
    int spill_revocable_memory_high_watermark_percent() const {
874
0
        if (_query_options.__isset.revocable_memory_high_watermark_percent) {
875
0
            return _query_options.revocable_memory_high_watermark_percent;
876
0
        }
877
0
        return -1;
878
0
    }
879
880
125k
    MOCK_FUNCTION bool enable_shared_exchange_sink_buffer() const {
881
125k
        return _query_options.__isset.enable_shared_exchange_sink_buffer &&
882
125k
               _query_options.enable_shared_exchange_sink_buffer;
883
125k
    }
884
885
9.82M
    size_t minimum_operator_memory_required_bytes() const {
886
9.83M
        if (_query_options.__isset.minimum_operator_memory_required_kb) {
887
9.83M
            return _query_options.minimum_operator_memory_required_kb * 1024;
888
18.4E
        } else {
889
            // refer other database
890
18.4E
            return 4 * 1024 * 1024;
891
18.4E
        }
892
9.82M
    }
893
894
237k
    MOCK_FUNCTION bool enable_use_hybrid_sort() const {
895
237k
        return _query_options.__isset.enable_use_hybrid_sort &&
896
237k
               _query_options.enable_use_hybrid_sort;
897
237k
    }
898
899
1.85M
    void set_max_operator_id(int max_operator_id) { _max_operator_id = max_operator_id; }
900
901
279
    int max_operator_id() const { return _max_operator_id; }
902
903
1.78M
    void set_task_id(int id) { _task_id = id; }
904
905
1.00k
    int task_id() const { return _task_id; }
906
907
1.77M
    void set_task_num(int task_num) { _task_num = task_num; }
908
909
52.2k
    int task_num() const { return _task_num; }
910
911
268k
    int profile_level() const { return _profile_level; }
912
913
21.2k
    std::shared_ptr<IdFileMap>& get_id_file_map() { return _id_file_map; }
914
915
    void set_id_file_map();
916
931k
    VectorSearchUserParams get_vector_search_params() const {
917
931k
        VectorSearchUserParams params;
918
931k
        params.hnsw_ef_search = _query_options.hnsw_ef_search;
919
931k
        params.hnsw_check_relative_distance = _query_options.hnsw_check_relative_distance;
920
931k
        params.hnsw_bounded_queue = _query_options.hnsw_bounded_queue;
921
931k
        params.ivf_nprobe = _query_options.ivf_nprobe;
922
931k
        params.ann_index_candidate_rows_threshold =
923
931k
                _query_options.__isset.ann_index_candidate_rows_threshold
924
931k
                        ? _query_options.ann_index_candidate_rows_threshold
925
931k
                        : 0;
926
931k
        params.ann_index_candidate_rows_percent_threshold =
927
931k
                _query_options.__isset.ann_index_candidate_rows_percent_threshold
928
931k
                        ? _query_options.ann_index_candidate_rows_percent_threshold
929
18.4E
                        : 0.3;
930
931k
        return params;
931
931k
    }
932
933
137
    bool runtime_filter_wait_infinitely() const {
934
137
        return _query_options.__isset.runtime_filter_wait_infinitely &&
935
137
               _query_options.runtime_filter_wait_infinitely;
936
137
    }
937
938
    const std::set<int>& get_deregister_runtime_filter() const;
939
940
    void merge_register_runtime_filter(const std::set<int>& runtime_filter_ids);
941
942
private:
943
    friend class ExternalFileReportReservation;
944
945
    void release_external_file_report_reservation(size_t reserved_bytes);
946
947
    Status create_error_log_file();
948
949
    static const int DEFAULT_BATCH_SIZE = 4062;
950
951
    std::shared_ptr<MemTrackerLimiter> _query_mem_tracker = nullptr;
952
953
    // Could not find a better way to record if the weak ptr is inited, use a bool to record
954
    // it. In some unit test cases, the runtime state's task ctx is not inited, then the test
955
    // hang, it is very hard to debug.
956
    bool _task_execution_context_inited = false;
957
    // Hold execution context for other threads
958
    std::weak_ptr<TaskExecutionContext> _task_execution_context;
959
960
    // put runtime state before _obj_pool, so that it will be deconstructed after
961
    // _obj_pool. Because some of object in _obj_pool will use profile when deconstructing.
962
    RuntimeProfile _profile;
963
    RuntimeProfile _load_channel_profile;
964
    // Why 2?
965
    // During cluster upgrade, fe will not pass profile_level to be, so we need to set it to 2
966
    // to make sure user can see all profile counters like before.
967
    int _profile_level = 2;
968
969
    const DescriptorTbl* _desc_tbl = nullptr;
970
    std::shared_ptr<ObjectPool> _obj_pool;
971
972
    // owned by PipelineFragmentContext
973
    RuntimeFilterMgr* _runtime_filter_mgr = nullptr;
974
975
    // Lock protecting _error_log and _unreported_error_idx
976
    std::mutex _error_log_lock;
977
978
    // Logs error messages.
979
    std::vector<std::string> _error_log;
980
981
    // _error_log[_unreported_error_idx+] has been not reported to the coordinator.
982
    int _unreported_error_idx;
983
984
    //Query-global timestamp_ms
985
    int64_t _timestamp_ms;
986
    int32_t _nano_seconds;
987
    std::string _timezone;
988
    cctz::time_zone _timezone_obj;
989
    std::string _lc_time_names;
990
991
    TUniqueId _query_id;
992
    // fragment id for each TPipelineFragmentParams
993
    int32_t _fragment_id;
994
    TUniqueId _fragment_instance_id;
995
    TQueryOptions _query_options;
996
    ExecEnv* _exec_env = nullptr;
997
998
    AtomicStatus _exec_status;
999
1000
    int _per_fragment_instance_idx;
1001
    int _num_per_fragment_instances = 0;
1002
    int _load_stream_per_node = 0;
1003
    int _total_load_streams = 0;
1004
    int _num_local_sink = 0;
1005
1006
    // The backend id on which this fragment instance runs
1007
    int64_t _backend_id = -1;
1008
1009
    // used as send id
1010
    int _be_number;
1011
1012
    // put here to collect files??
1013
    std::vector<std::string> _output_files;
1014
    std::atomic<int64_t> _num_rows_load_total;      // total rows read from source
1015
    std::atomic<int64_t> _num_rows_load_filtered;   // unqualified rows
1016
    std::atomic<int64_t> _num_rows_load_unselected; // rows filtered by predicates
1017
    std::atomic<int64_t> _num_rows_filtered_in_strict_mode_partial_update;
1018
    std::atomic<int64_t> _num_print_error_rows;
1019
1020
    std::atomic<int64_t> _num_bytes_load_total; // total bytes read from source
1021
    std::atomic<int64_t> _num_finished_scan_range;
1022
1023
    std::vector<std::string> _export_output_files;
1024
    std::string _import_label;
1025
    std::string _db_name;
1026
    std::string _load_dir;
1027
    int64_t _load_job_id;
1028
    int64_t _wal_id = -1;
1029
    size_t _content_length = 0;
1030
1031
    // mini load
1032
    std::string _error_log_file_path;
1033
    std::unique_ptr<std::ofstream> _error_log_file; // error file path, absolute path
1034
    std::string _first_error_msg = "";
1035
    mutable std::mutex _tablet_infos_mutex;
1036
    std::vector<TTabletCommitInfo> _tablet_commit_infos;
1037
    std::vector<TErrorTabletInfo> _error_tablet_infos;
1038
    int _max_operator_id = 0;
1039
    int _task_id = -1;
1040
    int _task_num = 0;
1041
1042
    mutable std::mutex _hive_partition_updates_mutex;
1043
    std::vector<THivePartitionUpdate> _hive_partition_updates;
1044
1045
    mutable std::mutex _iceberg_commit_datas_mutex;
1046
    std::vector<TIcebergCommitData> _iceberg_commit_datas;
1047
    std::shared_ptr<ExternalFileReportState> _external_file_report_state =
1048
            std::make_shared<ExternalFileReportState>();
1049
1050
    mutable std::mutex _mc_commit_datas_mutex;
1051
    std::vector<TMCCommitData> _mc_commit_datas;
1052
1053
    mutable std::mutex _paimon_commit_messages_mutex;
1054
    std::vector<TPaimonCommitMessage> _paimon_commit_messages;
1055
1056
    std::vector<std::unique_ptr<doris::PipelineXLocalStateBase>> _op_id_to_local_state;
1057
1058
    std::unique_ptr<doris::PipelineXSinkLocalStateBase> _sink_local_state;
1059
1060
    QueryContext* _query_ctx = nullptr;
1061
1062
    // true if max_filter_ratio is 0
1063
    bool _load_zero_tolerance = false;
1064
1065
    // only to lock _pipeline_id_to_profile
1066
    std::shared_mutex _pipeline_profile_lock;
1067
    std::vector<std::shared_ptr<RuntimeProfile>> _pipeline_id_to_profile;
1068
1069
    // save error log to s3
1070
    std::shared_ptr<io::S3FileSystem> _s3_error_fs;
1071
    // error file path on s3, ${bucket}/${prefix}/error_log/${label}_${fragment_instance_id}
1072
    std::string _s3_error_log_file_path;
1073
    // Protects the load error log stream, paths, and first error message.
1074
    mutable std::mutex _load_error_log_lock;
1075
    // Serializes S3 upload and presigned URL publication.
1076
    std::mutex _s3_error_log_file_lock;
1077
1078
    // used for encoding the global lazy materialize
1079
    std::shared_ptr<IdFileMap> _id_file_map = nullptr;
1080
1081
    std::set<int> _registered_runtime_filter_ids;
1082
};
1083
1084
#define RETURN_IF_CANCELLED(state)               \
1085
1.48M
    do {                                         \
1086
1.48M
        if (UNLIKELY((state)->is_cancelled())) { \
1087
20
            return (state)->cancel_reason();     \
1088
20
        }                                        \
1089
1.48M
    } while (false)
1090
1091
} // namespace doris