be/src/io/fs/file_meta_cache.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 "io/file_factory.h" |
21 | | #include "io/fs/file_reader_writer_fwd.h" |
22 | | #include "util/obj_lru_cache.h" |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | // A file meta cache depends on a LRU cache. |
27 | | // Such as parsed parquet footer. |
28 | | // The capacity will limit the number of cache entries in cache. |
29 | | class FileMetaCache { |
30 | | public: |
31 | 26 | FileMetaCache(int64_t capacity) : _cache(capacity) {} |
32 | | |
33 | | FileMetaCache(const FileMetaCache&) = delete; |
34 | | const FileMetaCache& operator=(const FileMetaCache&) = delete; |
35 | | |
36 | 0 | ObjLRUCache& cache() { return _cache; } |
37 | | |
38 | | static std::string get_key(const std::string file_name, int64_t modification_time, |
39 | | int64_t file_size); |
40 | | |
41 | | static std::string get_key(io::FileReaderSPtr file_reader, |
42 | | const io::FileDescription& _file_description); |
43 | | |
44 | 67 | bool lookup(const std::string& key, ObjLRUCache::CacheHandle* handle) { |
45 | 67 | return _cache.lookup({key}, handle); |
46 | 67 | } |
47 | | |
48 | | template <typename T> |
49 | 38 | void insert(const std::string& key, T* value, ObjLRUCache::CacheHandle* handle) { |
50 | 38 | _cache.insert({key}, value, handle); |
51 | 38 | } _ZN5doris13FileMetaCache6insertIiEEvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPT_PNS_11ObjLRUCache11CacheHandleE Line | Count | Source | 49 | 1 | void insert(const std::string& key, T* value, ObjLRUCache::CacheHandle* handle) { | 50 | 1 | _cache.insert({key}, value, handle); | 51 | 1 | } |
_ZN5doris13FileMetaCache6insertINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvRKS7_PT_PNS_11ObjLRUCache11CacheHandleE Line | Count | Source | 49 | 15 | void insert(const std::string& key, T* value, ObjLRUCache::CacheHandle* handle) { | 50 | 15 | _cache.insert({key}, value, handle); | 51 | 15 | } |
_ZN5doris13FileMetaCache6insertINS_12FileMetaDataEEEvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPT_PNS_11ObjLRUCache11CacheHandleE Line | Count | Source | 49 | 22 | void insert(const std::string& key, T* value, ObjLRUCache::CacheHandle* handle) { | 50 | 22 | _cache.insert({key}, value, handle); | 51 | 22 | } |
|
52 | | |
53 | 0 | bool enabled() const { return _cache.enabled(); } |
54 | | |
55 | | private: |
56 | | ObjLRUCache _cache; |
57 | | }; |
58 | | |
59 | | } // namespace doris |