Coverage Report

Created: 2026-08-04 11:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/runtime/exec_env.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
18
#pragma once
19
20
#include <atomic>
21
#include <map>
22
#include <memory>
23
#include <mutex>
24
#include <optional>
25
#include <set>
26
#include <string>
27
#include <vector>
28
29
#include "common/config.h"
30
#include "common/multi_version.h"
31
#include "common/status.h"
32
#include "storage/tablet/tablet_fwd.h"
33
34
namespace orc {
35
class MemoryPool;
36
}
37
namespace arrow {
38
class MemoryPool;
39
}
40
41
namespace doris {
42
class VDataStreamMgr;
43
class SpillFileManager;
44
class DeltaWriterV2Pool;
45
class DictionaryFactory;
46
class TaskScheduler;
47
struct RuntimeFilterTimerQueue;
48
class WorkloadGroupMgr;
49
struct WriteCooldownMetaExecutors;
50
class TokenBucketRateLimiterHolder;
51
using S3RateLimiterHolder = TokenBucketRateLimiterHolder;
52
class MSRpcRateLimitServices;
53
class ThreadPool;
54
struct StorePath;
55
struct CachePath;
56
namespace io {
57
class FDCache;
58
class FileCacheFactory;
59
class HdfsMgr;
60
class PackedFileManager;
61
} // namespace io
62
63
namespace segment_v2 {
64
class InvertedIndexSearcherCache;
65
class InvertedIndexQueryCache;
66
class ConditionCache;
67
class AnnIndexResultCache;
68
class TmpFileDirs;
69
class EncodingInfoResolver;
70
71
namespace inverted_index {
72
class AnalysisFactoryMgr;
73
}
74
75
} // namespace segment_v2
76
77
namespace kerberos {
78
class KerberosTicketMgr;
79
}
80
81
class QueryCache;
82
class WorkloadSchedPolicyMgr;
83
class BfdParser;
84
class BrokerMgr;
85
template <class T>
86
class BrpcClientCache;
87
class ExternalScanContextMgr;
88
class FragmentMgr;
89
class ResultCache;
90
class LoadPathMgr;
91
class NewLoadStreamMgr;
92
class MemTrackerLimiter;
93
class MemTracker;
94
class MemTableMemoryLimiter;
95
struct TrackerLimiterGroup;
96
class BaseStorageEngine;
97
class ResultBufferMgr;
98
class ResultQueueMgr;
99
class RuntimeQueryStatisticsMgr;
100
class LoadChannelMgr;
101
class LoadStreamMgr;
102
class LoadStreamMapPool;
103
class StreamLoadExecutor;
104
class RoutineLoadTaskExecutor;
105
class StreamLoadRecorderManager;
106
class SmallFileMgr;
107
class BackendServiceClient;
108
class TPaloBrokerServiceClient;
109
class PBackendService_Stub;
110
class PFunctionService_Stub;
111
template <class T>
112
class ClientCache;
113
class HeartbeatFlags;
114
class ClusterInfo;
115
struct FrontendInfo;
116
// Thrift-generated types (gen_cpp), forward-declared so their headers stay out
117
// of every TU that includes ExecEnv.
118
class TFrontendInfo;
119
class TNetworkAddress;
120
class FrontendServiceClient;
121
class FileMetaCache;
122
class GroupCommitMgr;
123
class CdcClientMgr;
124
class TabletSchemaCache;
125
class TabletColumnObjectPool;
126
class UserFunctionCache;
127
class StoragePageCache;
128
class AnnIndexIVFListCache;
129
class SegmentLoader;
130
class LookupConnectionCache;
131
class RowCache;
132
class DummyLRUCache;
133
class CacheManager;
134
class IdManager;
135
class ProcessProfile;
136
class HeapProfiler;
137
class WalManager;
138
class DNSCache;
139
class IndexPolicyMgr;
140
struct SyncRowsetStats;
141
class DeleteBitmapAggCache;
142
143
// set to true when BE is shutting down
144
inline bool k_doris_exit = false;
145
// set to true after BE start ready
146
inline bool k_is_server_ready = false;
147
148
// Execution environment for queries/plan fragments.
149
// Contains all required global structures, and handles to
150
// singleton services. Clients must call StartServices exactly
151
// once to properly initialise service state.
152
class ExecEnv {
153
public:
154
    // Empty destructor because the compiler-generated one requires full
155
    // declarations for classes in scoped_ptrs.
156
    ~ExecEnv();
157
158
2.03M
    BaseStorageEngine& storage_engine() { return *_storage_engine; }
159
160
    // Initial exec environment. must call this to init all
161
    [[nodiscard]] static Status init(ExecEnv* env, const std::vector<StorePath>& store_paths,
162
                                     const std::vector<StorePath>& spill_store_paths,
163
                                     const std::set<std::string>& broken_paths);
164
165
    // Stop all threads and delete resources.
166
    void destroy();
167
168
    /// Returns the first created exec env instance. In a normal doris, this is
169
    /// the only instance. In test setups with multiple ExecEnv's per process,
170
    /// we return the most recently created instance.
171
474M
    static ExecEnv* GetInstance() {
172
474M
        static ExecEnv s_exec_env;
173
474M
        return &s_exec_env;
174
474M
    }
175
176
    // Requires ExenEnv ready
177
    /*
178
     * Parameters:
179
     * - tablet_id: the id of tablet to get
180
     * - sync_stats: the stats of sync rowset
181
     * - force_use_only_cached: whether only use cached data
182
     * - cache_on_miss: whether cache the tablet meta when missing in cache
183
     */
184
    static Result<BaseTabletSPtr> get_tablet(int64_t tablet_id,
185
                                             SyncRowsetStats* sync_stats = nullptr,
186
                                             bool force_use_only_cached = false,
187
                                             bool cache_on_miss = true);
188
189
    static Status get_tablet_meta(int64_t tablet_id, TabletMetaSharedPtr* tablet_meta,
190
                                  bool force_use_only_cached = false);
191
192
677k
    static bool ready() { return _s_ready.load(std::memory_order_acquire); }
193
2.39M
    static bool tracking_memory() { return _s_tracking_memory.load(std::memory_order_acquire); }
194
436
    static bool get_is_upgrading() { return _s_upgrading.load(std::memory_order_acquire); }
195
0
    static void set_is_upgrading() { _s_upgrading = true; }
196
    const std::string& token() const;
197
10
    ExternalScanContextMgr* external_scan_context_mgr() { return _external_scan_context_mgr; }
198
3.49M
    VDataStreamMgr* vstream_mgr() { return _vstream_mgr; }
199
987k
    ResultBufferMgr* result_mgr() { return _result_mgr; }
200
12
    ResultQueueMgr* result_queue_mgr() { return _result_queue_mgr; }
201
0
    ClientCache<BackendServiceClient>* client_cache() { return _backend_client_cache; }
202
58.1k
    ClientCache<FrontendServiceClient>* frontend_client_cache() { return _frontend_client_cache; }
203
0
    ClientCache<TPaloBrokerServiceClient>* broker_client_cache() { return _broker_client_cache; }
204
205
1.18M
    WorkloadGroupMgr* workload_group_mgr() { return _workload_group_manager; }
206
1.27k
    WorkloadSchedPolicyMgr* workload_sched_policy_mgr() { return _workload_sched_mgr; }
207
322k
    RuntimeQueryStatisticsMgr* runtime_query_statistics_mgr() {
208
322k
        return _runtime_query_statistics_mgr;
209
322k
    }
210
211
    // using template to simplify client cache management
212
    template <typename T>
213
    inline ClientCache<T>* get_client_cache() {
214
        return nullptr;
215
    }
216
217
    // Save all MemTrackerLimiters in use.
218
    // Each group corresponds to several MemTrackerLimiters and has a lock.
219
    // Multiple groups are used to reduce the impact of locks.
220
    std::vector<TrackerLimiterGroup> mem_tracker_limiter_pool;
221
    void init_mem_tracker();
222
7.37M
    std::shared_ptr<MemTrackerLimiter> orphan_mem_tracker() { return _orphan_mem_tracker; }
223
283k
    std::shared_ptr<MemTrackerLimiter> brpc_iobuf_block_memory_tracker() {
224
283k
        return _brpc_iobuf_block_memory_tracker;
225
283k
    }
226
0
    std::shared_ptr<MemTrackerLimiter> segcompaction_mem_tracker() {
227
0
        return _segcompaction_mem_tracker;
228
0
    }
229
307k
    std::shared_ptr<MemTrackerLimiter> stream_load_pipe_tracker() {
230
307k
        return _stream_load_pipe_tracker;
231
307k
    }
232
753
    std::shared_ptr<MemTrackerLimiter> tablets_no_cache_mem_tracker() {
233
753
        return _tablets_no_cache_mem_tracker;
234
753
    }
235
753
    std::shared_ptr<MemTrackerLimiter> rowsets_no_cache_mem_tracker() {
236
753
        return _rowsets_no_cache_mem_tracker;
237
753
    }
238
753
    std::shared_ptr<MemTrackerLimiter> segments_no_cache_mem_tracker() {
239
753
        return _segments_no_cache_mem_tracker;
240
753
    }
241
2.78k
    std::shared_ptr<MemTrackerLimiter> point_query_executor_mem_tracker() {
242
2.78k
        return _point_query_executor_mem_tracker;
243
2.78k
    }
244
1.73k
    std::shared_ptr<MemTrackerLimiter> query_cache_mem_tracker() {
245
1.73k
        return _query_cache_mem_tracker;
246
1.73k
    }
247
456k
    std::shared_ptr<MemTrackerLimiter> block_compression_mem_tracker() {
248
456k
        return _block_compression_mem_tracker;
249
456k
    }
250
8.41k
    std::shared_ptr<MemTrackerLimiter> rowid_storage_reader_tracker() {
251
8.41k
        return _rowid_storage_reader_tracker;
252
8.41k
    }
253
193k
    std::shared_ptr<MemTrackerLimiter> subcolumns_tree_tracker() {
254
193k
        return _subcolumns_tree_tracker;
255
193k
    }
256
149k
    std::shared_ptr<MemTrackerLimiter> s3_file_buffer_tracker() { return _s3_file_buffer_tracker; }
257
25.8k
    std::shared_ptr<MemTrackerLimiter> parquet_meta_tracker() { return _parquet_meta_tracker; }
258
259
47.5k
    ThreadPool* send_batch_thread_pool() { return _send_batch_thread_pool.get(); }
260
141
    ThreadPool* buffered_reader_prefetch_thread_pool() {
261
141
        return _buffered_reader_prefetch_thread_pool.get();
262
141
    }
263
7.15k
    ThreadPool* send_table_stats_thread_pool() { return _send_table_stats_thread_pool.get(); }
264
75.4k
    ThreadPool* s3_file_upload_thread_pool() { return _s3_file_upload_thread_pool.get(); }
265
0
    ThreadPool* lazy_release_obj_pool() { return _lazy_release_obj_pool.get(); }
266
    ThreadPool* non_block_close_thread_pool();
267
0
    ThreadPool* s3_file_system_thread_pool() { return _s3_file_system_thread_pool.get(); }
268
0
    ThreadPool* udf_close_workers_pool() { return _udf_close_workers_thread_pool.get(); }
269
843k
    ThreadPool* segment_prefetch_thread_pool() { return _segment_prefetch_thread_pool.get(); }
270
9
    ThreadPool* peer_race_s3_thread_pool() { return _peer_race_s3_thread_pool.get(); }
271
272
    void init_file_cache_factory(std::vector<doris::CachePath>& cache_paths);
273
2.03M
    io::FileCacheFactory* file_cache_factory() { return _file_cache_factory; }
274
6.96k
    UserFunctionCache* user_function_cache() { return _user_function_cache; }
275
2.43M
    FragmentMgr* fragment_mgr() { return _fragment_mgr; }
276
70.9k
    ResultCache* result_cache() { return _result_cache; }
277
362M
    ClusterInfo* cluster_info() { return _cluster_info; }
278
1.93k
    LoadPathMgr* load_path_mgr() { return _load_path_mgr; }
279
7
    BfdParser* bfd_parser() const { return _bfd_parser; }
280
0
    BrokerMgr* broker_mgr() const { return _broker_mgr; }
281
2.05M
    BrpcClientCache<PBackendService_Stub>* brpc_internal_client_cache() const {
282
2.05M
        return _internal_client_cache;
283
2.05M
    }
284
9.66k
    BrpcClientCache<PBackendService_Stub>* brpc_streaming_client_cache() const {
285
9.66k
        return _streaming_client_cache;
286
9.66k
    }
287
0
    BrpcClientCache<PFunctionService_Stub>* brpc_function_client_cache() const {
288
0
        return _function_client_cache;
289
0
    }
290
104k
    LoadChannelMgr* load_channel_mgr() { return _load_channel_mgr; }
291
5.97k
    LoadStreamMgr* load_stream_mgr() { return _load_stream_mgr.get(); }
292
37.8k
    NewLoadStreamMgr* new_load_stream_mgr() { return _new_load_stream_mgr.get(); }
293
0
    SmallFileMgr* small_file_mgr() { return _small_file_mgr; }
294
295
1.99k
    SpillFileManager* spill_file_mgr() { return _spill_file_mgr; }
296
297
1.09k
    GroupCommitMgr* group_commit_mgr() { return _group_commit_mgr; }
298
6.31k
    CdcClientMgr* cdc_client_mgr() { return _cdc_client_mgr; }
299
300
31
    const std::vector<StorePath>& store_paths() const { return _store_paths; }
301
302
15.3k
    StreamLoadExecutor* stream_load_executor() { return _stream_load_executor.get(); }
303
3.23k
    RoutineLoadTaskExecutor* routine_load_task_executor() { return _routine_load_task_executor; }
304
1.53k
    HeartbeatFlags* heartbeat_flags() { return _heartbeat_flags; }
305
96.2k
    FileMetaCache* file_meta_cache() { return _file_meta_cache; }
306
620k
    MemTableMemoryLimiter* memtable_memory_limiter() { return _memtable_memory_limiter.get(); }
307
6.70k
    WalManager* wal_mgr() { return _wal_manager.get(); }
308
2.21M
    DNSCache* dns_cache() { return _dns_cache; }
309
7
    WriteCooldownMetaExecutors* write_cooldown_meta_executors() {
310
7
        return _write_cooldown_meta_executors.get();
311
7
    }
312
313
1
    kerberos::KerberosTicketMgr* kerberos_ticket_mgr() { return _kerberos_ticket_mgr; }
314
93.3k
    io::HdfsMgr* hdfs_mgr() { return _hdfs_mgr; }
315
0
    io::PackedFileManager* packed_file_manager() { return _packed_file_manager; }
316
2.04k
    IndexPolicyMgr* index_policy_mgr() { return _index_policy_mgr; }
317
0
    S3RateLimiterHolder* warmup_download_rate_limiter() { return _warmup_download_rate_limiter; }
318
1
    MSRpcRateLimitServices* ms_rpc_rate_limit_services() {
319
1
        return _ms_rpc_rate_limit_services.get();
320
1
    }
321
322
#ifdef BE_TEST
323
    // Defined out of line on purpose: assigning the unique_ptr destroys the old
324
    // pointee, which would require TmpFileDirs to be COMPLETE in every translation
325
    // unit that includes this header -- and this header is included by most of the
326
    // backend. Keeping the body in the .cpp lets the forward declaration above
327
    // suffice.
328
    void set_tmp_file_dir(std::unique_ptr<segment_v2::TmpFileDirs> tmp_file_dirs);
329
    void set_ready() { _s_ready = true; }
330
    void set_not_ready() { _s_ready = false; }
331
    // Defined out of line: resetting the unique_ptr deletes the old pointee,
332
    // which would require MemTableMemoryLimiter to be complete here.
333
    void set_memtable_memory_limiter(MemTableMemoryLimiter* limiter);
334
    void set_cluster_info(ClusterInfo* cluster_info) { this->_cluster_info = cluster_info; }
335
    void set_new_load_stream_mgr(std::unique_ptr<NewLoadStreamMgr>&& new_load_stream_mgr);
336
    void clear_new_load_stream_mgr();
337
    void set_stream_load_executor(std::unique_ptr<StreamLoadExecutor>&& stream_load_executor);
338
    void clear_stream_load_executor();
339
340
    void set_storage_engine(std::unique_ptr<BaseStorageEngine>&& engine);
341
    void set_inverted_index_searcher_cache(
342
            segment_v2::InvertedIndexSearcherCache* inverted_index_searcher_cache);
343
    void set_inverted_index_query_cache(
344
            segment_v2::InvertedIndexQueryCache* inverted_index_query_cache) {
345
        _inverted_index_query_cache = inverted_index_query_cache;
346
    }
347
    void set_process_profile(ProcessProfile* pp) { this->_process_profile = pp; }
348
    void set_delete_bitmap_agg_cache(DeleteBitmapAggCache* c) { _delete_bitmap_agg_cache = c; }
349
    void set_storage_page_cache(StoragePageCache* c) { this->_storage_page_cache = c; }
350
    void set_ann_index_ivf_list_cache(AnnIndexIVFListCache* c) {
351
        this->_ann_index_ivf_list_cache = c;
352
    }
353
    void set_segment_loader(SegmentLoader* sl) { this->_segment_loader = sl; }
354
    void set_routine_load_task_executor(RoutineLoadTaskExecutor* r) {
355
        this->_routine_load_task_executor = r;
356
    }
357
    void set_wal_mgr(std::unique_ptr<WalManager>&& wm);
358
    void clear_wal_mgr();
359
360
    void set_write_cooldown_meta_executors();
361
    static void set_tracking_memory(bool tracking_memory) {
362
        _s_tracking_memory.store(tracking_memory, std::memory_order_release);
363
    }
364
    void set_orc_memory_pool(orc::MemoryPool* pool) { _orc_memory_pool = pool; }
365
    // Defined out of line: assigning the unique_ptr destroys the old pointee,
366
    // which would require ThreadPool to be complete here.
367
    void set_non_block_close_thread_pool(std::unique_ptr<ThreadPool>&& pool);
368
    void set_s3_file_upload_thread_pool(std::unique_ptr<ThreadPool>&& pool);
369
    void set_file_cache_factory(io::FileCacheFactory* factory) { _file_cache_factory = factory; }
370
    // Defined out of line: assigning the unique_ptr destroys the old pointee,
371
    // which would require io::FDCache to be complete here.
372
    void set_file_cache_open_fd_cache(std::unique_ptr<io::FDCache>&& fd_cache);
373
#endif
374
    // WARN: The following setter methods are intended for use in test code and
375
    // offline tools (like meta_tool) ONLY. They should NOT be called in the
376
    // production environment to avoid thread safety issues and undefined behaviors.
377
    void set_cache_manager(CacheManager* cm) { this->_cache_manager = cm; }
378
    void set_tablet_schema_cache(TabletSchemaCache* c) { this->_tablet_schema_cache = c; }
379
    void set_tablet_column_object_pool(TabletColumnObjectPool* c) {
380
        this->_tablet_column_object_pool = c;
381
    }
382
383
9.67k
    LoadStreamMapPool* load_stream_map_pool() { return _load_stream_map_pool.get(); }
384
385
9.64k
    DeltaWriterV2Pool* delta_writer_v2_pool() { return _delta_writer_v2_pool.get(); }
386
387
    void wait_for_all_tasks_done();
388
389
    void update_frontends(const std::vector<TFrontendInfo>& new_infos);
390
    std::vector<TFrontendInfo> get_frontends();
391
    std::map<TNetworkAddress, FrontendInfo> get_running_frontends();
392
393
4.17M
    TabletSchemaCache* get_tablet_schema_cache() { return _tablet_schema_cache; }
394
2.03M
    TabletColumnObjectPool* get_tablet_column_object_pool() { return _tablet_column_object_pool; }
395
14.7M
    StoragePageCache* get_storage_page_cache() { return _storage_page_cache; }
396
0
    AnnIndexIVFListCache* get_ann_index_ivf_list_cache() { return _ann_index_ivf_list_cache; }
397
2.67M
    SegmentLoader* segment_loader() { return _segment_loader; }
398
310
    LookupConnectionCache* get_lookup_connection_cache() { return _lookup_connection_cache; }
399
6
    RowCache* get_row_cache() { return _row_cache; }
400
5.19k
    CacheManager* get_cache_manager() { return _cache_manager; }
401
151k
    IdManager* get_id_manager() { return _id_manager; }
402
59.5k
    ProcessProfile* get_process_profile() { return _process_profile; }
403
0
    HeapProfiler* get_heap_profiler() { return _heap_profiler; }
404
107k
    segment_v2::InvertedIndexSearcherCache* get_inverted_index_searcher_cache() {
405
107k
        return _inverted_index_searcher_cache;
406
107k
    }
407
24.5k
    segment_v2::InvertedIndexQueryCache* get_inverted_index_query_cache() {
408
24.5k
        return _inverted_index_query_cache;
409
24.5k
    }
410
3.33M
    segment_v2::ConditionCache* get_condition_cache() { return _condition_cache; }
411
36.3M
    segment_v2::EncodingInfoResolver* get_encoding_info_resolver() {
412
36.3M
        return _encoding_info_resolver;
413
36.3M
    }
414
38
    QueryCache* get_query_cache() { return _query_cache; }
415
416
9.42k
    RuntimeFilterTimerQueue* runtime_filter_timer_queue() { return _runtime_filter_timer_queue; }
417
418
3.60k
    DictionaryFactory* dict_factory() { return _dict_factory; }
419
420
6.81k
    segment_v2::TmpFileDirs* get_tmp_file_dirs() { return _tmp_file_dirs.get(); }
421
2.56M
    io::FDCache* file_cache_open_fd_cache() const { return _file_cache_open_fd_cache.get(); }
422
423
87
    segment_v2::AnnIndexResultCache* ann_index_result_cache() { return _ann_index_result_cache; }
424
425
39.0k
    orc::MemoryPool* orc_memory_pool() { return _orc_memory_pool; }
426
30.7k
    arrow::MemoryPool* arrow_memory_pool() { return _arrow_memory_pool; }
427
428
    bool check_auth_token(const std::string& auth_token);
429
16
    void set_stream_mgr(VDataStreamMgr* vstream_mgr) { _vstream_mgr = vstream_mgr; }
430
    void clear_stream_mgr();
431
432
12.2M
    DeleteBitmapAggCache* delete_bitmap_agg_cache() { return _delete_bitmap_agg_cache; }
433
    Status init_mem_env();
434
435
private:
436
    ExecEnv();
437
438
    [[nodiscard]] Status _init(const std::vector<StorePath>& store_paths,
439
                               const std::vector<StorePath>& spill_store_paths,
440
                               const std::set<std::string>& broken_paths);
441
    void _destroy();
442
443
    Status _check_deploy_mode();
444
445
    Status _create_internal_workload_group();
446
    void _init_runtime_filter_timer_queue();
447
448
    inline static std::atomic_bool _s_ready {false};
449
    inline static std::atomic_bool _s_tracking_memory {false};
450
    std::vector<StorePath> _store_paths;
451
    std::vector<StorePath> _spill_store_paths;
452
    inline static std::atomic_bool _s_upgrading {false};
453
454
    io::FileCacheFactory* _file_cache_factory = nullptr;
455
    UserFunctionCache* _user_function_cache = nullptr;
456
    // Leave protected so that subclasses can override
457
    ExternalScanContextMgr* _external_scan_context_mgr = nullptr;
458
    VDataStreamMgr* _vstream_mgr = nullptr;
459
    ResultBufferMgr* _result_mgr = nullptr;
460
    ResultQueueMgr* _result_queue_mgr = nullptr;
461
    ClientCache<BackendServiceClient>* _backend_client_cache = nullptr;
462
    ClientCache<FrontendServiceClient>* _frontend_client_cache = nullptr;
463
    ClientCache<TPaloBrokerServiceClient>* _broker_client_cache = nullptr;
464
465
    // The default tracker consumed by mem hook. If the thread does not attach other trackers,
466
    // by default all consumption will be passed to the process tracker through the orphan tracker.
467
    // In real time, `consumption of all limiter trackers` + `orphan tracker consumption` = `process tracker consumption`.
468
    // Ideally, all threads are expected to attach to the specified tracker, so that "all memory has its own ownership",
469
    // and the consumption of the orphan mem tracker is close to 0, but greater than 0.
470
    std::shared_ptr<MemTrackerLimiter> _orphan_mem_tracker;
471
    std::shared_ptr<MemTrackerLimiter> _brpc_iobuf_block_memory_tracker;
472
    // Count the memory consumption of segment compaction tasks.
473
    std::shared_ptr<MemTrackerLimiter> _segcompaction_mem_tracker;
474
    std::shared_ptr<MemTrackerLimiter> _stream_load_pipe_tracker;
475
476
    std::shared_ptr<MemTrackerLimiter> _tablets_no_cache_mem_tracker;
477
    std::shared_ptr<MemTrackerLimiter> _rowsets_no_cache_mem_tracker;
478
    std::shared_ptr<MemTrackerLimiter> _segments_no_cache_mem_tracker;
479
480
    // Tracking memory may be shared between multiple queries.
481
    std::shared_ptr<MemTrackerLimiter> _point_query_executor_mem_tracker;
482
    std::shared_ptr<MemTrackerLimiter> _block_compression_mem_tracker;
483
    std::shared_ptr<MemTrackerLimiter> _query_cache_mem_tracker;
484
485
    // TODO, looking forward to more accurate tracking.
486
    std::shared_ptr<MemTrackerLimiter> _rowid_storage_reader_tracker;
487
    std::shared_ptr<MemTrackerLimiter> _subcolumns_tree_tracker;
488
    std::shared_ptr<MemTrackerLimiter> _s3_file_buffer_tracker;
489
490
    // Tracking memory consumption of parquet meta
491
    std::shared_ptr<MemTrackerLimiter> _parquet_meta_tracker;
492
493
    std::unique_ptr<ThreadPool> _send_batch_thread_pool;
494
    // Threadpool used to prefetch remote file for buffered reader
495
    std::unique_ptr<ThreadPool> _buffered_reader_prefetch_thread_pool;
496
    // Threadpool used to send TableStats to FE
497
    std::unique_ptr<ThreadPool> _send_table_stats_thread_pool;
498
    // Threadpool used to upload local file to s3
499
    std::unique_ptr<ThreadPool> _s3_file_upload_thread_pool;
500
    // Pool used by join node to build hash table
501
    // Pool to use a new thread to release object
502
    std::unique_ptr<ThreadPool> _lazy_release_obj_pool;
503
    std::unique_ptr<ThreadPool> _non_block_close_thread_pool;
504
    std::unique_ptr<ThreadPool> _s3_file_system_thread_pool;
505
    // for java-udf to close
506
    std::unique_ptr<ThreadPool> _udf_close_workers_thread_pool;
507
    // Threadpool used to prefetch segment file cache blocks
508
    std::unique_ptr<ThreadPool> _segment_prefetch_thread_pool;
509
    std::unique_ptr<ThreadPool> _peer_race_s3_thread_pool;
510
511
    FragmentMgr* _fragment_mgr = nullptr;
512
    WorkloadGroupMgr* _workload_group_manager = nullptr;
513
514
    ResultCache* _result_cache = nullptr;
515
    ClusterInfo* _cluster_info = nullptr;
516
    LoadPathMgr* _load_path_mgr = nullptr;
517
518
    BfdParser* _bfd_parser = nullptr;
519
    BrokerMgr* _broker_mgr = nullptr;
520
    LoadChannelMgr* _load_channel_mgr = nullptr;
521
    std::unique_ptr<LoadStreamMgr> _load_stream_mgr;
522
    std::unique_ptr<NewLoadStreamMgr> _new_load_stream_mgr;
523
    BrpcClientCache<PBackendService_Stub>* _internal_client_cache = nullptr;
524
    BrpcClientCache<PBackendService_Stub>* _streaming_client_cache = nullptr;
525
    BrpcClientCache<PFunctionService_Stub>* _function_client_cache = nullptr;
526
527
    std::unique_ptr<StreamLoadExecutor> _stream_load_executor;
528
    RoutineLoadTaskExecutor* _routine_load_task_executor = nullptr;
529
    StreamLoadRecorderManager* _stream_load_recorder_manager = nullptr;
530
    SmallFileMgr* _small_file_mgr = nullptr;
531
    HeartbeatFlags* _heartbeat_flags = nullptr;
532
533
    // To save meta info of external file, such as parquet footer.
534
    FileMetaCache* _file_meta_cache = nullptr;
535
    std::unique_ptr<MemTableMemoryLimiter> _memtable_memory_limiter;
536
    std::unique_ptr<LoadStreamMapPool> _load_stream_map_pool;
537
    std::unique_ptr<DeltaWriterV2Pool> _delta_writer_v2_pool;
538
    std::unique_ptr<WalManager> _wal_manager;
539
    DNSCache* _dns_cache = nullptr;
540
    std::unique_ptr<WriteCooldownMetaExecutors> _write_cooldown_meta_executors;
541
542
    std::mutex _frontends_lock;
543
    // ip:brpc_port -> frontend_info. Held behind unique_ptr because std::map
544
    // requires a complete mapped type, and frontend_info.h would drag
545
    // gen_cpp/HeartbeatService_types.h into every TU that includes ExecEnv.
546
    std::unique_ptr<std::map<TNetworkAddress, FrontendInfo>> _frontends;
547
    GroupCommitMgr* _group_commit_mgr = nullptr;
548
    CdcClientMgr* _cdc_client_mgr = nullptr;
549
550
    // Maybe we should use unique_ptr, but it need complete type, which means we need
551
    // to include many headers, and for some cpp file that do not need class like TabletSchemaCache,
552
    // these redundancy header could introduce potential bug, at least, more header means slow compile.
553
    // So we choose to use raw pointer, please remember to delete these pointer in deconstructor.
554
    TabletSchemaCache* _tablet_schema_cache = nullptr;
555
    TabletColumnObjectPool* _tablet_column_object_pool = nullptr;
556
    std::unique_ptr<BaseStorageEngine> _storage_engine;
557
    StoragePageCache* _storage_page_cache = nullptr;
558
    AnnIndexIVFListCache* _ann_index_ivf_list_cache = nullptr;
559
    SegmentLoader* _segment_loader = nullptr;
560
    LookupConnectionCache* _lookup_connection_cache = nullptr;
561
    RowCache* _row_cache = nullptr;
562
    CacheManager* _cache_manager = nullptr;
563
    IdManager* _id_manager = nullptr;
564
    ProcessProfile* _process_profile = nullptr;
565
    HeapProfiler* _heap_profiler = nullptr;
566
    segment_v2::InvertedIndexSearcherCache* _inverted_index_searcher_cache = nullptr;
567
    segment_v2::InvertedIndexQueryCache* _inverted_index_query_cache = nullptr;
568
    segment_v2::ConditionCache* _condition_cache = nullptr;
569
    segment_v2::EncodingInfoResolver* _encoding_info_resolver = nullptr;
570
    QueryCache* _query_cache = nullptr;
571
    std::unique_ptr<io::FDCache> _file_cache_open_fd_cache;
572
    DeleteBitmapAggCache* _delete_bitmap_agg_cache {nullptr};
573
    segment_v2::AnnIndexResultCache* _ann_index_result_cache = nullptr;
574
575
    RuntimeFilterTimerQueue* _runtime_filter_timer_queue = nullptr;
576
    DictionaryFactory* _dict_factory = nullptr;
577
578
    WorkloadSchedPolicyMgr* _workload_sched_mgr = nullptr;
579
    IndexPolicyMgr* _index_policy_mgr = nullptr;
580
581
    RuntimeQueryStatisticsMgr* _runtime_query_statistics_mgr = nullptr;
582
583
    std::unique_ptr<segment_v2::TmpFileDirs> _tmp_file_dirs;
584
585
    SpillFileManager* _spill_file_mgr = nullptr;
586
587
    orc::MemoryPool* _orc_memory_pool = nullptr;
588
    arrow::MemoryPool* _arrow_memory_pool = nullptr;
589
590
    kerberos::KerberosTicketMgr* _kerberos_ticket_mgr = nullptr;
591
    io::HdfsMgr* _hdfs_mgr = nullptr;
592
    io::PackedFileManager* _packed_file_manager = nullptr;
593
    S3RateLimiterHolder* _warmup_download_rate_limiter = nullptr;
594
    std::unique_ptr<MSRpcRateLimitServices> _ms_rpc_rate_limit_services;
595
};
596
597
template <>
598
0
inline ClientCache<BackendServiceClient>* ExecEnv::get_client_cache<BackendServiceClient>() {
599
0
    return _backend_client_cache;
600
0
}
601
template <>
602
44.1k
inline ClientCache<FrontendServiceClient>* ExecEnv::get_client_cache<FrontendServiceClient>() {
603
44.1k
    return _frontend_client_cache;
604
44.1k
}
605
template <>
606
inline ClientCache<TPaloBrokerServiceClient>*
607
0
ExecEnv::get_client_cache<TPaloBrokerServiceClient>() {
608
0
    return _broker_client_cache;
609
0
}
610
611
0
inline segment_v2::InvertedIndexQueryCache* GetInvertedIndexQueryCache() {
612
0
    return ExecEnv::GetInstance()->get_inverted_index_query_cache();
613
0
}
614
615
} // namespace doris