Coverage Report

Created: 2026-11-03 20:28

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
26
inline int32_t get_execution_rpc_timeout_ms(int32_t execution_timeout_sec) {
61
26
    return std::min(config::execution_max_rpc_timeout_sec, execution_timeout_sec) * 1000;
62
26
}
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
100
    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
25.5k
    const TQueryOptions& query_options() const { return _query_options; }
159
9
    int64_t scan_queue_mem_limit() const {
160
9
        return _query_options.__isset.scan_queue_mem_limit ? _query_options.scan_queue_mem_limit
161
9
                                                           : _query_options.mem_limit / 20;
162
9
    }
163
164
48.2k
    bool enable_adjust_conjunct_order_by_cost() const {
165
48.2k
        return _query_options.__isset.enable_adjust_conjunct_order_by_cost &&
166
48.2k
               _query_options.enable_adjust_conjunct_order_by_cost;
167
48.2k
    }
168
169
7
    int32_t max_column_reader_num() const {
170
7
        return _query_options.__isset.max_column_reader_num ? _query_options.max_column_reader_num
171
7
                                                            : 20000;
172
7
    }
173
174
221k
    ObjectPool* obj_pool() const { return _obj_pool.get(); }
175
176
547k
    const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
177
308k
    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
12.4k
    MOCK_FUNCTION int batch_size() const {
182
12.4k
        static constexpr int kMax = 65535;
183
12.4k
        auto v = _query_options.batch_size;
184
12.4k
        return std::min(std::max(1, v), kMax);
185
12.4k
    }
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
156
    MOCK_FUNCTION size_t preferred_block_size_bytes() const {
194
156
        static constexpr int64_t kDefault = 8388608L; // 8MB
195
156
        static constexpr int64_t kMax = 536870912L;   // 512MB
196
156
        static constexpr int64_t kMin = 1048576L;     // 1MB
197
156
        if (!config::enable_adaptive_batch_size) [[unlikely]] {
198
3
            return kMax;
199
3
        }
200
153
        if (_query_options.__isset.preferred_block_size_bytes) [[likely]] {
201
153
            return std::max<int64_t>(
202
153
                    kMin, std::min<int64_t>(_query_options.preferred_block_size_bytes, kMax));
203
153
        }
204
0
        return kDefault;
205
153
    }
206
207
88
    int query_parallel_instance_num() const { return _query_options.parallel_instance; }
208
0
    int max_errors() const { return _query_options.max_errors; }
209
53
    int execution_timeout() const {
210
53
        return _query_options.__isset.execution_timeout ? _query_options.execution_timeout
211
53
                                                        : _query_options.query_timeout;
212
53
    }
213
0
    int max_scanners_concurrency() const {
214
0
        return _query_options.__isset.max_scanners_concurrency
215
0
                       ? _query_options.max_scanners_concurrency
216
0
                       : 0;
217
0
    }
218
5
    int max_file_scanners_concurrency() const {
219
5
        return _query_options.__isset.max_file_scanners_concurrency
220
5
                       ? _query_options.max_file_scanners_concurrency
221
5
                       : max_scanners_concurrency();
222
5
    }
223
224
80
    int min_scanners_concurrency() const {
225
80
        return _query_options.__isset.min_scanners_concurrency
226
80
                       ? _query_options.min_scanners_concurrency
227
80
                       : 1;
228
80
    }
229
230
0
    int min_file_scanners_concurrency() const {
231
0
        return _query_options.__isset.min_file_scanners_concurrency
232
0
                       ? _query_options.min_file_scanners_concurrency
233
0
                       : 1;
234
0
    }
235
236
    // Support extended regex
237
    // like look-around zero-width assertions(`?=`, `?!`, `?<=`, `?<!`)
238
548
    bool enable_extended_regex() const {
239
548
        return _query_options.__isset.enable_extended_regex && _query_options.enable_extended_regex;
240
548
    }
241
242
24
    TQueryType::type query_type() const { return _query_options.query_type; }
243
37
    int64_t timestamp_ms() const { return _timestamp_ms; }
244
28
    int32_t nano_seconds() const { return _nano_seconds; }
245
    // if possible, use timezone_obj() rather than timezone()
246
533
    const std::string& timezone() const { return _timezone; }
247
2.94k
    const cctz::time_zone& timezone_obj() const { return _timezone_obj; }
248
214
    void set_timezone(const std::string& timezone) {
249
214
        _timezone = timezone;
250
214
        TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj);
251
214
    }
252
5
    const std::string& lc_time_names() const { return _lc_time_names; }
253
894
    const TUniqueId& query_id() const { return _query_id; }
254
110k
    const TUniqueId& fragment_instance_id() const { return _fragment_instance_id; }
255
    // should only be called in pipeline engine
256
103
    int32_t fragment_id() const { return _fragment_id; }
257
83
    ExecEnv* exec_env() { return _exec_env; }
258
    std::shared_ptr<MemTrackerLimiter> query_mem_tracker() const;
259
260
    // Returns runtime state profile
261
7
    RuntimeProfile* runtime_profile() { return &_profile; }
262
0
    RuntimeProfile* load_channel_profile() { return &_load_channel_profile; }
263
264
100
    bool enable_function_pushdown() const {
265
100
        return _query_options.__isset.enable_function_pushdown &&
266
100
               _query_options.enable_function_pushdown;
267
100
    }
268
269
603
    bool check_overflow_for_decimal() const {
270
603
        return _query_options.__isset.check_overflow_for_decimal &&
271
603
               _query_options.check_overflow_for_decimal;
272
603
    }
273
274
3.30k
    bool enable_strict_mode() const {
275
3.30k
        return _query_options.__isset.enable_strict_cast && _query_options.enable_strict_cast;
276
3.30k
    }
277
278
0
    bool enable_insert_strict() const {
279
0
        return _query_options.__isset.enable_insert_strict && _query_options.enable_insert_strict;
280
0
    }
281
282
0
    bool enable_segment_limit_pushdown() const {
283
0
        return !_query_options.__isset.enable_segment_limit_pushdown ||
284
0
               _query_options.enable_segment_limit_pushdown;
285
0
    }
286
287
0
    bool mysql_row_binary_format() const {
288
0
        return _query_options.__isset.mysql_row_binary_format &&
289
0
               _query_options.mysql_row_binary_format;
290
0
    }
291
292
0
    bool enable_short_circuit_query_access_column_store() const {
293
0
        return _query_options.__isset.enable_short_circuit_query_access_column_store &&
294
0
               _query_options.enable_short_circuit_query_access_column_store;
295
0
    }
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
25
    void cancel(const Status& reason) {
313
25
        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
25
            LOG(WARNING) << "Task is cancelled, instance: "
317
25
                         << PrintInstanceStandardInfo(_query_id, _fragment_instance_id)
318
25
                         << ", st = " << reason;
319
25
        } 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
25
    }
326
327
2
    void set_backend_id(int64_t backend_id) { _backend_id = backend_id; }
328
2
    int64_t backend_id() const { return _backend_id; }
329
330
78
    void set_be_number(int be_number) { _be_number = be_number; }
331
131
    int be_number(void) const { return _be_number; }
332
333
0
    std::vector<std::string>& output_files() { return _output_files; }
334
335
0
    void set_import_label(const std::string& import_label) { _import_label = import_label; }
336
337
0
    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
0
    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
0
    void set_wal_id(int64_t wal_id) { _wal_id = wal_id; }
346
347
0
    int64_t wal_id() const { return _wal_id; }
348
349
0
    void set_content_length(size_t content_length) { _content_length = content_length; }
350
351
0
    size_t content_length() const { return _content_length; }
352
353
0
    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
2
    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
0
    int64_t num_bytes_load_total() { return _num_bytes_load_total.load(); }
372
373
0
    int64_t num_finished_range() { return _num_finished_scan_range.load(); }
374
375
0
    int64_t num_rows_load_total() { return _num_rows_load_total.load(); }
376
377
0
    int64_t num_rows_load_filtered() { return _num_rows_load_filtered.load(); }
378
379
0
    int64_t num_rows_load_unselected() { return _num_rows_load_unselected.load(); }
380
381
0
    int64_t num_rows_filtered_in_strict_mode_partial_update() {
382
0
        return _num_rows_filtered_in_strict_mode_partial_update;
383
0
    }
384
385
0
    int64_t num_rows_load_success() {
386
0
        return num_rows_load_total() - num_rows_load_filtered() - num_rows_load_unselected();
387
0
    }
388
389
2
    void update_num_rows_load_total(int64_t num_rows) { _num_rows_load_total.fetch_add(num_rows); }
390
391
0
    void set_num_rows_load_total(int64_t num_rows) { _num_rows_load_total.store(num_rows); }
392
393
2
    void update_num_bytes_load_total(int64_t bytes_load) {
394
2
        _num_bytes_load_total.fetch_add(bytes_load);
395
2
    }
396
397
0
    void update_num_finished_scan_range(int64_t finished_range) {
398
0
        _num_finished_scan_range.fetch_add(finished_range);
399
0
    }
400
401
0
    void update_num_rows_load_filtered(int64_t num_rows) {
402
0
        _num_rows_load_filtered.fetch_add(num_rows);
403
0
    }
404
405
0
    void update_num_rows_load_unselected(int64_t num_rows) {
406
0
        _num_rows_load_unselected.fetch_add(num_rows);
407
0
    }
408
409
0
    void set_num_rows_filtered_in_strict_mode_partial_update(int64_t num_rows) {
410
0
        _num_rows_filtered_in_strict_mode_partial_update = num_rows;
411
0
    }
412
413
7
    void set_per_fragment_instance_idx(int idx) { _per_fragment_instance_idx = idx; }
414
415
17
    int per_fragment_instance_idx() const { return _per_fragment_instance_idx; }
416
417
7
    void set_num_per_fragment_instances(int num_instances) {
418
7
        _num_per_fragment_instances = num_instances;
419
7
    }
420
421
2
    int num_per_fragment_instances() const { return _num_per_fragment_instances; }
422
423
7
    void set_load_stream_per_node(int load_stream_per_node) {
424
7
        _load_stream_per_node = load_stream_per_node;
425
7
    }
426
427
2
    int load_stream_per_node() const { return _load_stream_per_node; }
428
429
7
    void set_total_load_streams(int total_load_streams) {
430
7
        _total_load_streams = total_load_streams;
431
7
    }
432
433
2
    int total_load_streams() const { return _total_load_streams; }
434
435
8
    void set_num_local_sink(int num_local_sink) { _num_local_sink = num_local_sink; }
436
437
2
    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
    int32_t runtime_filter_max_in_num() const { return _query_options.runtime_filter_max_in_num; }
448
449
1.17k
    int be_exec_version() const {
450
1.17k
        DCHECK(_query_options.__isset.be_exec_version &&
451
1.17k
               BeExecVersionManager::check_be_exec_version(_query_options.be_exec_version));
452
1.17k
        return _query_options.be_exec_version;
453
1.17k
    }
454
2
    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
2
        return _query_options.__isset.enable_local_shuffle && _query_options.enable_local_shuffle &&
457
2
               (!_query_options.__isset.enable_local_shuffle_planner ||
458
2
                !_query_options.enable_local_shuffle_planner);
459
2
    }
460
461
3
    MOCK_FUNCTION bool enable_local_exchange() const {
462
3
        return _query_options.__isset.enable_local_exchange && _query_options.enable_local_exchange;
463
3
    }
464
465
718
    bool trim_tailing_spaces_for_external_table_query() const {
466
718
        return _query_options.trim_tailing_spaces_for_external_table_query;
467
718
    }
468
469
6
    bool return_object_data_as_binary() const {
470
6
        return _query_options.return_object_data_as_binary;
471
6
    }
472
473
2
    bool enable_fuzzy_blockable_task() const {
474
2
        return _query_options.__isset.enable_fuzzy_blockable_task &&
475
2
               _query_options.enable_fuzzy_blockable_task;
476
2
    }
477
478
    segment_v2::CompressionTypePB fragement_transmission_compression_type() const;
479
480
0
    bool skip_storage_engine_merge() const {
481
0
        return _query_options.__isset.skip_storage_engine_merge &&
482
0
               _query_options.skip_storage_engine_merge;
483
0
    }
484
485
0
    bool skip_delete_predicate() const {
486
0
        return _query_options.__isset.skip_delete_predicate && _query_options.skip_delete_predicate;
487
0
    }
488
489
36
    bool skip_delete_bitmap() const {
490
36
        return _query_options.__isset.skip_delete_bitmap && _query_options.skip_delete_bitmap;
491
36
    }
492
493
0
    bool skip_missing_version() const {
494
0
        return _query_options.__isset.skip_missing_version && _query_options.skip_missing_version;
495
0
    }
496
497
14
    int64_t data_queue_max_blocks() const {
498
14
        return _query_options.__isset.data_queue_max_blocks ? _query_options.data_queue_max_blocks
499
14
                                                            : 1;
500
14
    }
501
502
    bool enable_page_cache() const;
503
504
0
    bool enable_prefer_cached_rowset() const {
505
0
        return _query_options.__isset.enable_prefer_cached_rowset &&
506
0
               _query_options.enable_prefer_cached_rowset;
507
0
    }
508
509
0
    int64_t query_freshness_tolerance_ms() const {
510
0
        return _query_options.query_freshness_tolerance_ms;
511
0
    }
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
0
    std::vector<TTabletCommitInfo> tablet_commit_infos() const {
519
0
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
520
0
        return _tablet_commit_infos;
521
0
    }
522
523
0
    void add_tablet_commit_infos(std::vector<TTabletCommitInfo>& commit_infos) {
524
0
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
525
0
        _tablet_commit_infos.insert(_tablet_commit_infos.end(),
526
0
                                    std::make_move_iterator(commit_infos.begin()),
527
0
                                    std::make_move_iterator(commit_infos.end()));
528
0
    }
529
530
0
    std::vector<TErrorTabletInfo> error_tablet_infos() const {
531
0
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
532
0
        return _error_tablet_infos;
533
0
    }
534
535
0
    void add_error_tablet_infos(std::vector<TErrorTabletInfo>& tablet_infos) {
536
0
        std::lock_guard<std::mutex> lock(_tablet_infos_mutex);
537
0
        _error_tablet_infos.insert(_error_tablet_infos.end(),
538
0
                                   std::make_move_iterator(tablet_infos.begin()),
539
0
                                   std::make_move_iterator(tablet_infos.end()));
540
0
    }
541
542
3
    std::vector<THivePartitionUpdate> hive_partition_updates() const {
543
3
        std::lock_guard<std::mutex> lock(_hive_partition_updates_mutex);
544
3
        return _hive_partition_updates;
545
3
    }
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
4
    void append_iceberg_commit_datas(std::vector<TIcebergCommitData>* output) const {
553
4
        std::lock_guard<std::mutex> lock(_iceberg_commit_datas_mutex);
554
4
        output->insert(output->end(), _iceberg_commit_datas.begin(), _iceberg_commit_datas.end());
555
4
    }
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
5
    void append_paimon_commit_messages(std::vector<TPaimonCommitMessage>* output) const {
568
5
        std::lock_guard<std::mutex> lock(_paimon_commit_messages_mutex);
569
5
        output->insert(output->end(), _paimon_commit_messages.begin(),
570
5
                       _paimon_commit_messages.end());
571
5
    }
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
6
    void set_external_file_report_state(std::shared_ptr<ExternalFileReportState> report_state) {
582
6
        _external_file_report_state = std::move(report_state);
583
6
    }
584
585
0
    const std::shared_ptr<ExternalFileReportState>& external_file_report_state() const {
586
0
        return _external_file_report_state;
587
0
    }
588
589
3
    std::vector<TMCCommitData> mc_commit_datas() const {
590
3
        std::lock_guard<std::mutex> lock(_mc_commit_datas_mutex);
591
3
        return _mc_commit_datas;
592
3
    }
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
14.0k
    RuntimeFilterMgr* local_runtime_filter_mgr() { return _runtime_filter_mgr; }
603
604
    RuntimeFilterMgr* global_runtime_filter_mgr();
605
606
244
    void set_runtime_filter_mgr(RuntimeFilterMgr* runtime_filter_mgr) {
607
244
        _runtime_filter_mgr = runtime_filter_mgr;
608
244
    }
609
610
252k
    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
0
    void set_query_mem_tracker(const std::shared_ptr<MemTrackerLimiter>& tracker) {
618
0
        _query_mem_tracker = tracker;
619
0
    }
620
621
5.85k
    void set_query_options(const TQueryOptions& query_options) { _query_options = query_options; }
622
623
187
    bool enable_profile() const {
624
187
        return _query_options.__isset.enable_profile && _query_options.enable_profile;
625
187
    }
626
627
0
    int cte_max_recursion_depth() const {
628
0
        return _query_options.__isset.cte_max_recursion_depth
629
0
                       ? _query_options.cte_max_recursion_depth
630
0
                       : 0;
631
0
    }
632
633
0
    bool enable_streaming_agg_hash_join_force_passthrough() const {
634
0
        return _query_options.__isset.enable_streaming_agg_hash_join_force_passthrough &&
635
0
               _query_options.enable_streaming_agg_hash_join_force_passthrough;
636
0
    }
637
638
3
    bool enable_local_exchange_before_agg() const {
639
3
        return _query_options.__isset.enable_local_exchange_before_agg &&
640
3
               _query_options.enable_local_exchange_before_agg;
641
3
    }
642
643
1
    bool enable_local_exchange_before_streaming_agg() const {
644
1
        return _query_options.__isset.enable_local_exchange_before_streaming_agg &&
645
1
               _query_options.enable_local_exchange_before_streaming_agg;
646
1
    }
647
648
0
    bool enable_distinct_streaming_agg_force_passthrough() const {
649
0
        return _query_options.__isset.enable_distinct_streaming_agg_force_passthrough &&
650
0
               _query_options.enable_distinct_streaming_agg_force_passthrough;
651
0
    }
652
653
1
    bool enable_broadcast_join_force_passthrough() const {
654
1
        return _query_options.__isset.enable_broadcast_join_force_passthrough &&
655
1
               _query_options.enable_broadcast_join_force_passthrough;
656
1
    }
657
658
0
    int rpc_verbose_profile_max_instance_count() const {
659
0
        return _query_options.__isset.rpc_verbose_profile_max_instance_count
660
0
                       ? _query_options.rpc_verbose_profile_max_instance_count
661
0
                       : 0;
662
0
    }
663
664
0
    MOCK_FUNCTION bool enable_share_hash_table_for_broadcast_join() const {
665
0
        return _query_options.__isset.enable_share_hash_table_for_broadcast_join &&
666
0
               _query_options.enable_share_hash_table_for_broadcast_join;
667
0
    }
668
669
2
    bool enable_parallel_scan() const {
670
2
        return _query_options.__isset.enable_parallel_scan && _query_options.enable_parallel_scan;
671
2
    }
672
673
20
    bool enable_aggregate_function_null_v2() const {
674
20
        return _query_options.__isset.enable_aggregate_function_null_v2 &&
675
20
               _query_options.enable_aggregate_function_null_v2;
676
20
    }
677
678
125
    bool enable_prune_nested_column() const {
679
125
        return _query_options.__isset.enable_prune_nested_column &&
680
125
               _query_options.enable_prune_nested_column;
681
125
    }
682
683
2
    bool is_read_csv_empty_line_as_null() const {
684
2
        return _query_options.__isset.read_csv_empty_line_as_null &&
685
2
               _query_options.read_csv_empty_line_as_null;
686
2
    }
687
688
0
    int parallel_scan_max_scanners_count() const {
689
0
        return _query_options.__isset.parallel_scan_max_scanners_count
690
0
                       ? _query_options.parallel_scan_max_scanners_count
691
0
                       : 0;
692
0
    }
693
694
431
    int partition_topn_max_partitions() const {
695
431
        return _query_options.__isset.partition_topn_max_partitions
696
431
                       ? _query_options.partition_topn_max_partitions
697
431
                       : 1024;
698
431
    }
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
0
    int64_t parallel_scan_min_rows_per_scanner() const {
707
0
        return _query_options.__isset.parallel_scan_min_rows_per_scanner
708
0
                       ? _query_options.parallel_scan_min_rows_per_scanner
709
0
                       : 0;
710
0
    }
711
712
2
    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
75.4k
    void set_task_execution_context(std::shared_ptr<TaskExecutionContext> context) {
735
75.4k
        _task_execution_context_inited = true;
736
75.4k
        _task_execution_context = context;
737
75.4k
    }
738
739
80
    bool task_execution_context_inited() const { return _task_execution_context_inited; }
740
741
154
    std::weak_ptr<TaskExecutionContext> get_task_execution_context() {
742
154
        CHECK(_task_execution_context_inited)
743
0
                << "_task_execution_context_inited == false, the ctx is not inited";
744
154
        return _task_execution_context;
745
154
    }
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
19.1k
    bool enable_spill() const {
758
19.1k
        return (_query_options.__isset.enable_force_spill && _query_options.enable_force_spill) ||
759
19.1k
               (_query_options.__isset.enable_spill && _query_options.enable_spill);
760
19.1k
    }
761
762
30.1k
    bool enable_force_spill() const {
763
30.1k
        return _query_options.__isset.enable_force_spill && _query_options.enable_force_spill;
764
30.1k
    }
765
766
72
    int64_t spill_min_revocable_mem() const {
767
72
        if (_query_options.__isset.min_revocable_mem) {
768
72
            return std::max(_query_options.min_revocable_mem, (int64_t)1 << 20);
769
72
        }
770
0
        return 32 << 20;
771
72
    }
772
773
39
    int spill_aggregation_partition_count() const {
774
39
        if (_query_options.__isset.spill_aggregation_partition_count) {
775
39
            return std::min(std::max(2, _query_options.spill_aggregation_partition_count), 32);
776
39
        }
777
0
        return 8;
778
39
    }
779
780
9
    int spill_hash_join_partition_count() const {
781
9
        if (_query_options.__isset.spill_hash_join_partition_count) {
782
9
            return std::min(std::max(2, _query_options.spill_hash_join_partition_count), 32);
783
9
        }
784
0
        return 8;
785
9
    }
786
787
23
    int spill_repartition_max_depth() const {
788
23
        if (_query_options.__isset.spill_repartition_max_depth) {
789
            // Clamp to a reasonable range: [1, 128]
790
23
            return std::max(1, std::min(_query_options.spill_repartition_max_depth, 128));
791
23
        }
792
0
        return 8;
793
23
    }
794
795
200k
    int64_t spill_buffer_size_bytes() const {
796
        // clamp to [1MB, 256MB]
797
200k
        constexpr int64_t kMin = 1LL * 1024 * 1024;
798
200k
        constexpr int64_t kMax = 256LL * 1024 * 1024;
799
200k
        if (_query_options.__isset.spill_buffer_size_bytes) {
800
200k
            int64_t v = _query_options.spill_buffer_size_bytes;
801
200k
            if (v < kMin) return kMin;
802
200k
            if (v > kMax) return kMax;
803
200k
            return v;
804
200k
        }
805
0
        return 8LL * 1024 * 1024;
806
200k
    }
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
16
    int64_t spill_aggregation_sink_mem_limit_bytes() const {
823
16
        constexpr int64_t kMin = 1LL * 1024 * 1024;
824
16
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
825
16
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
826
16
        if (_query_options.__isset.spill_aggregation_sink_mem_limit_bytes) {
827
16
            int64_t v = _query_options.spill_aggregation_sink_mem_limit_bytes;
828
16
            return std::min(std::max(v, kMin), kMax);
829
16
        }
830
0
        return kDefault;
831
16
    }
832
833
8
    int64_t spill_sort_sink_mem_limit_bytes() const {
834
8
        constexpr int64_t kMin = 1LL * 1024 * 1024;
835
8
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
836
8
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
837
8
        if (_query_options.__isset.spill_sort_sink_mem_limit_bytes) {
838
8
            int64_t v = _query_options.spill_sort_sink_mem_limit_bytes;
839
8
            return std::min(std::max(v, kMin), kMax);
840
8
        }
841
0
        return kDefault;
842
8
    }
843
844
114
    int64_t spill_analytic_sink_mem_limit_bytes() const {
845
114
        constexpr int64_t kMin = 1LL * 1024 * 1024;
846
114
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
847
114
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
848
114
        if (_query_options.__isset.spill_analytic_sink_mem_limit_bytes) {
849
114
            int64_t v = _query_options.spill_analytic_sink_mem_limit_bytes;
850
114
            return std::min(std::max(v, kMin), kMax);
851
114
        }
852
0
        return kDefault;
853
114
    }
854
855
14
    int64_t spill_sort_merge_mem_limit_bytes() const {
856
14
        constexpr int64_t kMin = 1LL * 1024 * 1024;
857
14
        constexpr int64_t kMax = 4LL * 1024 * 1024 * 1024;
858
14
        constexpr int64_t kDefault = 64LL * 1024 * 1024;
859
14
        if (_query_options.__isset.spill_sort_merge_mem_limit_bytes) {
860
14
            int64_t v = _query_options.spill_sort_merge_mem_limit_bytes;
861
14
            return std::min(std::max(v, kMin), kMax);
862
14
        }
863
0
        return kDefault;
864
14
    }
865
866
0
    int64_t low_memory_mode_buffer_limit() const {
867
0
        if (_query_options.__isset.low_memory_mode_buffer_limit) {
868
0
            return std::max(_query_options.low_memory_mode_buffer_limit, (int64_t)1);
869
0
        }
870
0
        return 32L * 1024 * 1024;
871
0
    }
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
0
    MOCK_FUNCTION bool enable_shared_exchange_sink_buffer() const {
881
0
        return _query_options.__isset.enable_shared_exchange_sink_buffer &&
882
0
               _query_options.enable_shared_exchange_sink_buffer;
883
0
    }
884
885
2.41M
    size_t minimum_operator_memory_required_bytes() const {
886
2.41M
        if (_query_options.__isset.minimum_operator_memory_required_kb) {
887
2.41M
            return _query_options.minimum_operator_memory_required_kb * 1024;
888
2.41M
        } else {
889
            // refer other database
890
0
            return 4 * 1024 * 1024;
891
0
        }
892
2.41M
    }
893
894
0
    MOCK_FUNCTION bool enable_use_hybrid_sort() const {
895
0
        return _query_options.__isset.enable_use_hybrid_sort &&
896
0
               _query_options.enable_use_hybrid_sort;
897
0
    }
898
899
72.1k
    void set_max_operator_id(int max_operator_id) { _max_operator_id = max_operator_id; }
900
901
21
    int max_operator_id() const { return _max_operator_id; }
902
903
25
    void set_task_id(int id) { _task_id = id; }
904
905
251
    int task_id() const { return _task_id; }
906
907
10
    void set_task_num(int task_num) { _task_num = task_num; }
908
909
10
    int task_num() const { return _task_num; }
910
911
5
    int profile_level() const { return _profile_level; }
912
913
2
    std::shared_ptr<IdFileMap>& get_id_file_map() { return _id_file_map; }
914
915
    void set_id_file_map();
916
40
    VectorSearchUserParams get_vector_search_params() const {
917
40
        VectorSearchUserParams params;
918
40
        params.hnsw_ef_search = _query_options.hnsw_ef_search;
919
40
        params.hnsw_check_relative_distance = _query_options.hnsw_check_relative_distance;
920
40
        params.hnsw_bounded_queue = _query_options.hnsw_bounded_queue;
921
40
        params.ivf_nprobe = _query_options.ivf_nprobe;
922
40
        params.ann_index_candidate_rows_threshold =
923
40
                _query_options.__isset.ann_index_candidate_rows_threshold
924
40
                        ? _query_options.ann_index_candidate_rows_threshold
925
40
                        : 0;
926
40
        params.ann_index_candidate_rows_percent_threshold =
927
40
                _query_options.__isset.ann_index_candidate_rows_percent_threshold
928
40
                        ? _query_options.ann_index_candidate_rows_percent_threshold
929
40
                        : 0.3;
930
40
        return params;
931
40
    }
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
403k
    do {                                         \
1086
403k
        if (UNLIKELY((state)->is_cancelled())) { \
1087
18
            return (state)->cancel_reason();     \
1088
18
        }                                        \
1089
403k
    } while (false)
1090
1091
} // namespace doris