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