be/src/exprs/function/dictionary_factory.cpp
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 | | #include "exprs/function/dictionary_factory.h" |
19 | | |
20 | | #include <gen_cpp/DataSinks_types.h> |
21 | | |
22 | | #include "runtime/memory/mem_tracker_limiter.h" |
23 | | #include "runtime/thread_context.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | DictionaryFactory::DictionaryFactory() |
28 | 6 | : _mem_tracker(MemTrackerLimiter::create_shared(MemTrackerLimiter::Type::GLOBAL, |
29 | 6 | "GLOBAL_DICT_FACTORY")) { |
30 | 6 | SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_mem_tracker); |
31 | 6 | } |
32 | | |
33 | 6 | DictionaryFactory::~DictionaryFactory() { |
34 | 6 | SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_mem_tracker); |
35 | 6 | _dict_id_to_dict_map.clear(); |
36 | 6 | _dict_id_to_version_id_map.clear(); |
37 | 6 | } |
38 | | |
39 | | void DictionaryFactory::get_dictionary_status(std::vector<TDictionaryStatus>& result, |
40 | 4 | std::vector<int64_t> dict_ids) { |
41 | 4 | std::shared_lock lc(_mutex); |
42 | 4 | if (dict_ids.empty()) { // empty means ALL |
43 | 2 | for (const auto& [dict_id, dict] : _dict_id_to_dict_map) { |
44 | 2 | TDictionaryStatus status; |
45 | 2 | status.__set_dictionary_id(dict_id); |
46 | 2 | status.__set_version_id(_dict_id_to_version_id_map[dict_id]); |
47 | 2 | status.__set_dictionary_memory_size(dict->allocated_bytes()); |
48 | 2 | result.emplace_back(std::move(status)); |
49 | 2 | } |
50 | 3 | } else { |
51 | 6 | for (auto dict_id : dict_ids) { |
52 | 6 | if (_dict_id_to_dict_map.contains(dict_id)) { |
53 | 5 | TDictionaryStatus status; |
54 | 5 | status.__set_dictionary_id(dict_id); |
55 | 5 | status.__set_version_id(_dict_id_to_version_id_map[dict_id]); |
56 | 5 | status.__set_dictionary_memory_size( |
57 | 5 | _dict_id_to_dict_map[dict_id]->allocated_bytes()); |
58 | 5 | result.emplace_back(std::move(status)); |
59 | 5 | } |
60 | 6 | } |
61 | 3 | } |
62 | 4 | } |
63 | | |
64 | | } // namespace doris |