Scanner C++ API
table_meta_cache.h
1 /* Copyright 2017 Carnegie Mellon University
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include "scanner/engine/metadata.h"
19 
20 #include <map>
21 #include <mutex>
22 
23 namespace scanner {
24 namespace internal {
25 
27  public:
28  TableMetaCache(storehouse::StorageBackend* storage,
29  const DatabaseMetadata& meta);
30 
31  const TableMetadata& at(const std::string& table_name) const;
32 
33  const TableMetadata& at(i32 table_id) const;
34 
35  bool exists(const std::string& table_name) const;
36 
37  bool exists(i32 table_id) const;
38 
39  bool has(const std::string& table_name) const;
40 
41  void update(const TableMetadata& meta);
42 
43  void prefetch(const std::vector<std::string>& table_names);
44 
45  void write_megafile();
46 
47  private:
48  void memoized_read(const std::string& table_name) const;
49 
50  void memoized_read(i32 table_id) const;
51 
52  storehouse::StorageBackend* storage_;
53  const DatabaseMetadata& meta_;
54  mutable std::mutex lock_;
55  mutable std::unordered_map<i32, TableMetadata> cache_;
56 };
57 
58 }
59 }
Definition: database.cpp:36
Definition: metadata.h:223
Definition: table_meta_cache.h:26
Definition: metadata.h:106