OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChunkMetadataRecycler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "DataMgr/ChunkMetadata.h"
20 #include "DataRecycler.h"
21 
24 
26  ChunkMetadataMetaInfo(const std::unordered_set<size_t> input_table_infos) {
27  input_table_keys.insert(input_table_infos.begin(), input_table_infos.end());
28  };
29 
30  std::unordered_set<size_t> input_table_keys;
31 };
32 
34  : public DataRecycler<std::optional<ChunkMetadataMap>, ChunkMetadataMetaInfo> {
35  public:
36  // resultset's chunk metadata recycler caches logical information instead of actual data
37  // so we do not limit its capacity
38  // thus we do not maintain a metric cache for this
39  // also, we do not classify device identifier since it is logical information
42  std::numeric_limits<size_t>::max(),
43  std::numeric_limits<size_t>::max(),
44  0) {}
45 
46  std::optional<ChunkMetadataMap> getItemFromCache(
47  QueryPlanHash key,
48  CacheItemType item_type,
49  DeviceIdentifier device_identifier,
50  std::optional<ChunkMetadataMetaInfo> meta_info = std::nullopt) override;
51 
52  void putItemToCache(
53  QueryPlanHash key,
54  std::optional<ChunkMetadataMap> item,
55  CacheItemType item_type,
56  DeviceIdentifier device_identifier,
57  size_t item_size,
58  size_t compute_time,
59  std::optional<ChunkMetadataMetaInfo> meta_info = std::nullopt) override;
60 
61  // nothing to do with hashing scheme recycler
62  void initCache() override {}
63 
64  void clearCache() override;
65 
66  void markCachedItemAsDirty(size_t table_key,
67  std::unordered_set<QueryPlanHash>& key_set,
68  CacheItemType item_type,
69  DeviceIdentifier device_identifier) override;
70 
71  std::string toString() const override;
72 
73  void addQueryPlanDagForTableKeys(size_t hashed_query_plan_dag,
74  const std::unordered_set<size_t>& table_keys,
75  std::lock_guard<std::mutex>& lock);
76 
77  std::optional<std::unordered_set<size_t>> getMappedQueryPlanDagsWithTableKey(
78  size_t table_key) const;
79 
80  void removeTableKeyInfoFromQueryPlanDagMap(size_t table_key);
81 
82  private:
83  bool hasItemInCache(
84  QueryPlanHash key,
85  CacheItemType item_type,
86  DeviceIdentifier device_identifier,
87  std::lock_guard<std::mutex>& lock,
88  std::optional<ChunkMetadataMetaInfo> meta_info = std::nullopt) const override;
89 
90  // hashing scheme recycler clears the cached layouts at once
92  QueryPlanHash key,
93  CacheItemType item_type,
94  DeviceIdentifier device_identifier,
95  std::lock_guard<std::mutex>& lock,
96  std::optional<ChunkMetadataMetaInfo> meta_info = std::nullopt) override;
97 
98  // hashing scheme recycler has unlimited capacity so we do not need this
100  CacheItemType item_type,
101  DeviceIdentifier device_identifier,
102  size_t required_size,
103  std::lock_guard<std::mutex>& lock,
104  std::optional<ChunkMetadataMetaInfo> meta_info = std::nullopt) override {}
105 
106  // keep all table keys referenced to compute cached resultset
107  std::unordered_map<size_t, std::unordered_set<size_t>> table_key_to_query_plan_dag_map_;
108 };
void removeItemFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::lock_guard< std::mutex > &lock, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) override
size_t DeviceIdentifier
Definition: DataRecycler.h:129
ChunkMetadataMetaInfo(const std::unordered_set< size_t > input_table_infos)
void addQueryPlanDagForTableKeys(size_t hashed_query_plan_dag, const std::unordered_set< size_t > &table_keys, std::lock_guard< std::mutex > &lock)
std::optional< std::unordered_set< size_t > > getMappedQueryPlanDagsWithTableKey(size_t table_key) const
std::unordered_map< size_t, std::unordered_set< size_t > > table_key_to_query_plan_dag_map_
bool hasItemInCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::lock_guard< std::mutex > &lock, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) const override
void cleanupCacheForInsertion(CacheItemType item_type, DeviceIdentifier device_identifier, size_t required_size, std::lock_guard< std::mutex > &lock, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) override
void removeTableKeyInfoFromQueryPlanDagMap(size_t table_key)
CacheItemType
Definition: DataRecycler.h:38
std::unordered_set< size_t > input_table_keys
size_t QueryPlanHash
void markCachedItemAsDirty(size_t table_key, std::unordered_set< QueryPlanHash > &key_set, CacheItemType item_type, DeviceIdentifier device_identifier) override
virtual std::optional< ChunkMetadataMap > getItemFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt)=0
void putItemToCache(QueryPlanHash key, std::optional< ChunkMetadataMap > item, CacheItemType item_type, DeviceIdentifier device_identifier, size_t item_size, size_t compute_time, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) override
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER
std::string toString() const override