OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HashingSchemeRecycler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2021 OmniSci, 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 #include "HashingSchemeRecycler.h"
19 
20 std::optional<HashType> HashingSchemeRecycler::getItemFromCache(
21  QueryPlanHash key,
22  CacheItemType item_type,
23  DeviceIdentifier device_identifier,
24  std::optional<EMPTY_META_INFO> meta_info) const {
27  return std::nullopt;
28  }
30  std::lock_guard<std::mutex> lock(getCacheLock());
31  auto layout_cache = getCachedItemContainer(item_type, device_identifier);
32  auto candidate_layout = getCachedItem(key, *layout_cache);
33  if (candidate_layout) {
34  VLOG(1) << "[" << DataRecyclerUtil::toStringCacheItemType(item_type) << ", "
36  << "] Recycle hashtable layout for the join qual: "
37  << HashJoin::getHashTypeString(*candidate_layout->cached_item);
38  return candidate_layout->cached_item;
39  }
40  return std::nullopt;
41 }
42 
44  std::optional<HashType> item,
45  CacheItemType item_type,
46  DeviceIdentifier device_identifier,
47  size_t item_size,
48  size_t compute_time,
49  std::optional<EMPTY_META_INFO> meta_info) {
52  return;
53  }
55  std::lock_guard<std::mutex> lock(getCacheLock());
56  auto layout_cache = getCachedItemContainer(item_type, device_identifier);
57  auto candidate_layout = getCachedItem(key, *layout_cache);
58  if (candidate_layout) {
59  return;
60  }
61  layout_cache->emplace_back(key, item, nullptr, meta_info);
62  VLOG(1) << "[" << DataRecyclerUtil::toStringCacheItemType(item_type) << ", "
64  << "] Put hashtable layout for the join qual to cache: "
66  return;
67 }
68 
70  std::lock_guard<std::mutex> lock(getCacheLock());
71  auto layout_cache_container = getCachedItemContainer(CacheItemType::HT_HASHING_SCHEME,
73  layout_cache_container->clear();
74 }
75 
76 std::string HashingSchemeRecycler::toString() const {
77  auto layout_cache_container = getCachedItemContainer(CacheItemType::HT_HASHING_SCHEME,
79  std::ostringstream oss;
80  oss << "Hashing scheme cache:\n";
81  oss << "Device: "
83  << "\n";
84  for (auto& kv : *layout_cache_container) {
85  oss << "\tkey: " << kv.key
86  << ", layout: " << HashJoin::getHashTypeString(*kv.cached_item) << "\n";
87  }
88  return oss.str();
89 }
90 
92  QueryPlanHash key,
93  CacheItemType item_type,
94  DeviceIdentifier device_identifier,
95  std::lock_guard<std::mutex>& lock,
96  std::optional<EMPTY_META_INFO> meta_info) const {
99  return false;
100  }
102  auto layout_cache = getCachedItemContainer(item_type, device_identifier);
103  return getCachedItem(key, *layout_cache).has_value();
104 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
size_t DeviceIdentifier
Definition: DataRecycler.h:111
static std::string getDeviceIdentifierString(DeviceIdentifier device_identifier)
Definition: DataRecycler.h:134
static std::string_view toStringCacheItemType(CacheItemType item_type)
Definition: DataRecycler.h:127
bool hasItemInCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::lock_guard< std::mutex > &lock, std::optional< EMPTY_META_INFO > meta_info=std::nullopt) const override
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
constexpr DeviceIdentifier LAYOUT_CACHE_DEVICE_IDENTIFIER
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:446
bool g_enable_data_recycler
Definition: Execute.cpp:139
void putItemToCache(QueryPlanHash key, std::optional< HashType > item, CacheItemType item_type, DeviceIdentifier device_identifier, size_t item_size, size_t compute_time, std::optional< EMPTY_META_INFO > meta_info=std::nullopt) override
CacheItemType
Definition: DataRecycler.h:36
virtual std::optional< HashType > getItemFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::optional< EMPTY_META_INFO > meta_info=std::nullopt) const =0
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:134
size_t QueryPlanHash
std::optional< CachedItem< std::optional< HashType >, EMPTY_META_INFO > > getCachedItem(QueryPlanHash key, CachedItemContainer &m) const
Definition: DataRecycler.h:460
std::string toString() const override
bool g_use_hashtable_cache
Definition: Execute.cpp:140
#define VLOG(n)
Definition: Logger.h:303