@@ -55,6 +55,195 @@ const FILE_TYPE: &str = "file";
55
55
/// Metrics type key for selector result cache.
56
56
const SELECTOR_RESULT_TYPE : & str = "selector_result" ;
57
57
58
+ /// Cache strategies that may only enable a subset of caches.
59
+ #[ derive( Clone ) ]
60
+ pub enum CacheStrategy {
61
+ /// Strategy for normal operations.
62
+ /// Doesn't disable any cache.
63
+ EnableAll ( CacheManagerRef ) ,
64
+ /// Strategy for compaction.
65
+ /// Disables some caches during compaction to avoid affecting queries.
66
+ /// Enables the write cache so that the compaction can read files cached
67
+ /// in the write cache and write the compacted files back to the write cache.
68
+ Compaction ( CacheManagerRef ) ,
69
+ /// Do not use any cache.
70
+ Disabled ,
71
+ }
72
+
73
+ impl CacheStrategy {
74
+ /// Calls [CacheManager::get_parquet_meta_data()].
75
+ pub async fn get_parquet_meta_data (
76
+ & self ,
77
+ region_id : RegionId ,
78
+ file_id : FileId ,
79
+ ) -> Option < Arc < ParquetMetaData > > {
80
+ match self {
81
+ CacheStrategy :: EnableAll ( cache_manager) => {
82
+ cache_manager
83
+ . get_parquet_meta_data ( region_id, file_id)
84
+ . await
85
+ }
86
+ CacheStrategy :: Compaction ( cache_manager) => {
87
+ cache_manager
88
+ . get_parquet_meta_data ( region_id, file_id)
89
+ . await
90
+ }
91
+ CacheStrategy :: Disabled => None ,
92
+ }
93
+ }
94
+
95
+ /// Calls [CacheManager::get_parquet_meta_data_from_mem_cache()].
96
+ pub fn get_parquet_meta_data_from_mem_cache (
97
+ & self ,
98
+ region_id : RegionId ,
99
+ file_id : FileId ,
100
+ ) -> Option < Arc < ParquetMetaData > > {
101
+ match self {
102
+ CacheStrategy :: EnableAll ( cache_manager) => {
103
+ cache_manager. get_parquet_meta_data_from_mem_cache ( region_id, file_id)
104
+ }
105
+ CacheStrategy :: Compaction ( cache_manager) => {
106
+ cache_manager. get_parquet_meta_data_from_mem_cache ( region_id, file_id)
107
+ }
108
+ CacheStrategy :: Disabled => None ,
109
+ }
110
+ }
111
+
112
+ /// Calls [CacheManager::put_parquet_meta_data()].
113
+ pub fn put_parquet_meta_data (
114
+ & self ,
115
+ region_id : RegionId ,
116
+ file_id : FileId ,
117
+ metadata : Arc < ParquetMetaData > ,
118
+ ) {
119
+ match self {
120
+ CacheStrategy :: EnableAll ( cache_manager) => {
121
+ cache_manager. put_parquet_meta_data ( region_id, file_id, metadata) ;
122
+ }
123
+ CacheStrategy :: Compaction ( cache_manager) => {
124
+ cache_manager. put_parquet_meta_data ( region_id, file_id, metadata) ;
125
+ }
126
+ CacheStrategy :: Disabled => { }
127
+ }
128
+ }
129
+
130
+ /// Calls [CacheManager::remove_parquet_meta_data()].
131
+ pub fn remove_parquet_meta_data ( & self , region_id : RegionId , file_id : FileId ) {
132
+ match self {
133
+ CacheStrategy :: EnableAll ( cache_manager) => {
134
+ cache_manager. remove_parquet_meta_data ( region_id, file_id) ;
135
+ }
136
+ CacheStrategy :: Compaction ( cache_manager) => {
137
+ cache_manager. remove_parquet_meta_data ( region_id, file_id) ;
138
+ }
139
+ CacheStrategy :: Disabled => { }
140
+ }
141
+ }
142
+
143
+ /// Calls [CacheManager::get_repeated_vector()].
144
+ /// It returns None if the strategy is [CacheStrategy::Compaction] or [CacheStrategy::Disabled].
145
+ pub fn get_repeated_vector (
146
+ & self ,
147
+ data_type : & ConcreteDataType ,
148
+ value : & Value ,
149
+ ) -> Option < VectorRef > {
150
+ match self {
151
+ CacheStrategy :: EnableAll ( cache_manager) => {
152
+ cache_manager. get_repeated_vector ( data_type, value)
153
+ }
154
+ CacheStrategy :: Compaction ( _) | CacheStrategy :: Disabled => None ,
155
+ }
156
+ }
157
+
158
+ /// Calls [CacheManager::put_repeated_vector()].
159
+ /// It does nothing if the strategy isn't [CacheStrategy::EnableAll].
160
+ pub fn put_repeated_vector ( & self , value : Value , vector : VectorRef ) {
161
+ if let CacheStrategy :: EnableAll ( cache_manager) = self {
162
+ cache_manager. put_repeated_vector ( value, vector) ;
163
+ }
164
+ }
165
+
166
+ /// Calls [CacheManager::get_pages()].
167
+ /// It returns None if the strategy is [CacheStrategy::Compaction] or [CacheStrategy::Disabled].
168
+ pub fn get_pages ( & self , page_key : & PageKey ) -> Option < Arc < PageValue > > {
169
+ match self {
170
+ CacheStrategy :: EnableAll ( cache_manager) => cache_manager. get_pages ( page_key) ,
171
+ CacheStrategy :: Compaction ( _) | CacheStrategy :: Disabled => None ,
172
+ }
173
+ }
174
+
175
+ /// Calls [CacheManager::put_pages()].
176
+ /// It does nothing if the strategy isn't [CacheStrategy::EnableAll].
177
+ pub fn put_pages ( & self , page_key : PageKey , pages : Arc < PageValue > ) {
178
+ if let CacheStrategy :: EnableAll ( cache_manager) = self {
179
+ cache_manager. put_pages ( page_key, pages) ;
180
+ }
181
+ }
182
+
183
+ /// Calls [CacheManager::get_selector_result()].
184
+ /// It returns None if the strategy is [CacheStrategy::Compaction] or [CacheStrategy::Disabled].
185
+ pub fn get_selector_result (
186
+ & self ,
187
+ selector_key : & SelectorResultKey ,
188
+ ) -> Option < Arc < SelectorResultValue > > {
189
+ match self {
190
+ CacheStrategy :: EnableAll ( cache_manager) => {
191
+ cache_manager. get_selector_result ( selector_key)
192
+ }
193
+ CacheStrategy :: Compaction ( _) | CacheStrategy :: Disabled => None ,
194
+ }
195
+ }
196
+
197
+ /// Calls [CacheManager::put_selector_result()].
198
+ /// It does nothing if the strategy isn't [CacheStrategy::EnableAll].
199
+ pub fn put_selector_result (
200
+ & self ,
201
+ selector_key : SelectorResultKey ,
202
+ result : Arc < SelectorResultValue > ,
203
+ ) {
204
+ if let CacheStrategy :: EnableAll ( cache_manager) = self {
205
+ cache_manager. put_selector_result ( selector_key, result) ;
206
+ }
207
+ }
208
+
209
+ /// Calls [CacheManager::write_cache()].
210
+ /// It returns None if the strategy is [CacheStrategy::Disabled].
211
+ pub fn write_cache ( & self ) -> Option < & WriteCacheRef > {
212
+ match self {
213
+ CacheStrategy :: EnableAll ( cache_manager) => cache_manager. write_cache ( ) ,
214
+ CacheStrategy :: Compaction ( cache_manager) => cache_manager. write_cache ( ) ,
215
+ CacheStrategy :: Disabled => None ,
216
+ }
217
+ }
218
+
219
+ /// Calls [CacheManager::index_cache()].
220
+ /// It returns None if the strategy is [CacheStrategy::Compaction] or [CacheStrategy::Disabled].
221
+ pub fn index_cache ( & self ) -> Option < & InvertedIndexCacheRef > {
222
+ match self {
223
+ CacheStrategy :: EnableAll ( cache_manager) => cache_manager. index_cache ( ) ,
224
+ CacheStrategy :: Compaction ( _) | CacheStrategy :: Disabled => None ,
225
+ }
226
+ }
227
+
228
+ /// Calls [CacheManager::bloom_filter_index_cache()].
229
+ /// It returns None if the strategy is [CacheStrategy::Compaction] or [CacheStrategy::Disabled].
230
+ pub fn bloom_filter_index_cache ( & self ) -> Option < & BloomFilterIndexCacheRef > {
231
+ match self {
232
+ CacheStrategy :: EnableAll ( cache_manager) => cache_manager. bloom_filter_index_cache ( ) ,
233
+ CacheStrategy :: Compaction ( _) | CacheStrategy :: Disabled => None ,
234
+ }
235
+ }
236
+
237
+ /// Calls [CacheManager::puffin_metadata_cache()].
238
+ /// It returns None if the strategy is [CacheStrategy::Compaction] or [CacheStrategy::Disabled].
239
+ pub fn puffin_metadata_cache ( & self ) -> Option < & PuffinMetadataCacheRef > {
240
+ match self {
241
+ CacheStrategy :: EnableAll ( cache_manager) => cache_manager. puffin_metadata_cache ( ) ,
242
+ CacheStrategy :: Compaction ( _) | CacheStrategy :: Disabled => None ,
243
+ }
244
+ }
245
+ }
246
+
58
247
/// Manages cached data for the engine.
59
248
///
60
249
/// All caches are disabled by default.
0 commit comments