OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChunkMetadataRecycler Class Reference

#include <ChunkMetadataRecycler.h>

+ Inheritance diagram for ChunkMetadataRecycler:
+ Collaboration diagram for ChunkMetadataRecycler:

Public Member Functions

 ChunkMetadataRecycler ()
 
 std::numeric_limits ()
 
 std::numeric_limits ()
 
std::optional< ChunkMetadataMapgetItemFromCache (QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) override
 
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
 
void initCache () override
 
void clearCache () override
 
void markCachedItemAsDirty (size_t table_key, std::unordered_set< QueryPlanHash > &key_set, CacheItemType item_type, DeviceIdentifier device_identifier) override
 
std::string toString () const override
 
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
 
void removeTableKeyInfoFromQueryPlanDagMap (size_t table_key)
 
- Public Member Functions inherited from DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >
 DataRecycler (const std::vector< CacheItemType > &item_types, size_t total_cache_size, size_t max_item_size, int num_gpus)
 
virtual ~DataRecycler ()=default
 
void markCachedItemAsDirtyImpl (QueryPlanHash key, CachedItemContainer &m) const
 
bool isCachedItemDirty (QueryPlanHash key, CachedItemContainer &m) const
 
std::shared_ptr
< CachedItemContainer
getCachedItemContainer (CacheItemType item_type, DeviceIdentifier device_identifier) const
 
std::optional< CachedItem
< std::optional
< ChunkMetadataMap >
, ChunkMetadataMetaInfo > > 
getCachedItemWithoutConsideringMetaInfo (QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, CachedItemContainer &m, std::lock_guard< std::mutex > &lock)
 
size_t getCurrentNumCachedItems (CacheItemType item_type, DeviceIdentifier device_identifier) const
 
size_t getCurrentNumDirtyCachedItems (CacheItemType item_type, DeviceIdentifier device_identifier) const
 
size_t getCurrentNumCleanCachedItems (CacheItemType item_type, DeviceIdentifier device_identifier) const
 
size_t getCurrentCacheSizeForDevice (CacheItemType item_type, DeviceIdentifier device_identifier) const
 
std::shared_ptr< CacheItemMetricgetCachedItemMetric (CacheItemType item_type, DeviceIdentifier device_identifier, QueryPlanHash key) const
 
void setTotalCacheSize (CacheItemType item_type, size_t new_total_cache_size)
 
void setMaxCacheItemSize (CacheItemType item_type, size_t new_max_cache_item_size)
 

Private Member Functions

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 removeItemFromCache (QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::lock_guard< std::mutex > &lock, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) 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
 

Private Attributes

std::unordered_map< size_t,
std::unordered_set< size_t > > 
table_key_to_query_plan_dag_map_
 

Additional Inherited Members

- Public Types inherited from DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >
using CachedItemContainer = std::vector< CachedItem< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >>
 
using PerDeviceCacheItemContainer = std::unordered_map< DeviceIdentifier, std::shared_ptr< CachedItemContainer >>
 
using PerTypeCacheItemContainer = std::unordered_map< CacheItemType, std::shared_ptr< PerDeviceCacheItemContainer >>
 
using PerTypeCacheMetricTracker = std::unordered_map< CacheItemType, CacheMetricTracker >
 
- Protected Member Functions inherited from DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >
void removeCachedItemFromBeginning (CacheItemType item_type, DeviceIdentifier device_identifier, int offset)
 
void sortCacheContainerByQueryMetric (CacheItemType item_type, DeviceIdentifier device_identifier)
 
std::mutex & getCacheLock () const
 
CacheMetricTrackergetMetricTracker (CacheItemType item_type)
 
CacheMetricTracker const & getMetricTracker (CacheItemType item_type) const
 
std::unordered_set
< CacheItemType > const & 
getCacheItemType () const
 
PerTypeCacheItemContainer const & getItemCache () const
 

Detailed Description

Definition at line 33 of file ChunkMetadataRecycler.h.

Constructor & Destructor Documentation

ChunkMetadataRecycler::ChunkMetadataRecycler ( )
inline

Definition at line 40 of file ChunkMetadataRecycler.h.

References CHUNK_METADATA.

DataRecycler(const std::vector< CacheItemType > &item_types, size_t total_cache_size, size_t max_item_size, int num_gpus)
Definition: DataRecycler.h:460

Member Function Documentation

void ChunkMetadataRecycler::addQueryPlanDagForTableKeys ( size_t  hashed_query_plan_dag,
const std::unordered_set< size_t > &  table_keys,
std::lock_guard< std::mutex > &  lock 
)

Definition at line 184 of file ChunkMetadataRecycler.cpp.

References table_key_to_query_plan_dag_map_.

Referenced by putItemToCache().

187  {
188  for (auto table_key : table_keys) {
189  auto itr = table_key_to_query_plan_dag_map_.try_emplace(table_key).first;
190  itr->second.insert(hashed_query_plan_dag);
191  }
192 }
std::unordered_map< size_t, std::unordered_set< size_t > > table_key_to_query_plan_dag_map_

+ Here is the caller graph for this function:

void ChunkMetadataRecycler::cleanupCacheForInsertion ( CacheItemType  item_type,
DeviceIdentifier  device_identifier,
size_t  required_size,
std::lock_guard< std::mutex > &  lock,
std::optional< ChunkMetadataMetaInfo meta_info = std::nullopt 
)
inlineoverrideprivatevirtual
void ChunkMetadataRecycler::clearCache ( )
overridevirtual

Implements DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >.

Definition at line 121 of file ChunkMetadataRecycler.cpp.

References CHUNK_METADATA, CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER, DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCachedItemContainer(), DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCacheLock(), DataRecyclerUtil::getDeviceIdentifierString(), and VLOG.

121  {
122  std::lock_guard<std::mutex> lock(getCacheLock());
123  auto metadata_cache_container = getCachedItemContainer(
125 
126  if (!metadata_cache_container->empty()) {
127  VLOG(1) << "[" << CacheItemType::CHUNK_METADATA << ", "
130  << "] clear cache (# items: " << metadata_cache_container->size() << ")";
131  metadata_cache_container->clear();
132  }
133 }
static std::string getDeviceIdentifierString(DeviceIdentifier device_identifier)
Definition: DataRecycler.h:138
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:530
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

std::optional< ChunkMetadataMap > ChunkMetadataRecycler::getItemFromCache ( QueryPlanHash  key,
CacheItemType  item_type,
DeviceIdentifier  device_identifier,
std::optional< ChunkMetadataMetaInfo meta_info = std::nullopt 
)
overridevirtual

Implements DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >.

Definition at line 19 of file ChunkMetadataRecycler.cpp.

References CHECK, CHECK_EQ, CHUNK_METADATA, CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER, EMPTY_HASHED_PLAN_DAG_KEY, g_enable_data_recycler, g_use_chunk_metadata_cache, DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCachedItemContainer(), DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCacheLock(), DataRecyclerUtil::getDeviceIdentifierString(), removeItemFromCache(), and VLOG.

23  {
26  return std::nullopt;
27  }
30  std::lock_guard<std::mutex> lock(getCacheLock());
31  auto chunk_metadata_cache = getCachedItemContainer(item_type, device_identifier);
32  CHECK(chunk_metadata_cache);
33  auto candidate_it =
34  std::find_if(chunk_metadata_cache->begin(),
35  chunk_metadata_cache->end(),
36  [&key](const auto& cached_item) { return cached_item.key == key; });
37  if (candidate_it != chunk_metadata_cache->end()) {
38  if (candidate_it->isDirty()) {
40  key, item_type, device_identifier, lock, candidate_it->meta_info);
41  return std::nullopt;
42  }
43  auto candidate_chunk_metadata = candidate_it->cached_item;
44  candidate_it->item_metric->incRefCount();
45  VLOG(1) << "[" << item_type << ", "
47  << "] Get cached item from cache (key: " << key << ")";
48  return candidate_chunk_metadata;
49  }
50  return std::nullopt;
51 }
void removeItemFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::lock_guard< std::mutex > &lock, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) override
#define CHECK_EQ(x, y)
Definition: Logger.h:230
static std::string getDeviceIdentifierString(DeviceIdentifier device_identifier)
Definition: DataRecycler.h:138
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:530
bool g_enable_data_recycler
Definition: Execute.cpp:146
bool g_use_chunk_metadata_cache
Definition: Execute.cpp:149
#define CHECK(condition)
Definition: Logger.h:222
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

std::optional< std::unordered_set< size_t > > ChunkMetadataRecycler::getMappedQueryPlanDagsWithTableKey ( size_t  table_key) const

Definition at line 195 of file ChunkMetadataRecycler.cpp.

References DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCacheLock(), and table_key_to_query_plan_dag_map_.

195  {
196  std::lock_guard<std::mutex> lock(getCacheLock());
197  auto it = table_key_to_query_plan_dag_map_.find(table_key);
198  return it != table_key_to_query_plan_dag_map_.end() ? std::make_optional(it->second)
199  : std::nullopt;
200 }
std::unordered_map< size_t, std::unordered_set< size_t > > table_key_to_query_plan_dag_map_

+ Here is the call graph for this function:

bool ChunkMetadataRecycler::hasItemInCache ( QueryPlanHash  key,
CacheItemType  item_type,
DeviceIdentifier  device_identifier,
std::lock_guard< std::mutex > &  lock,
std::optional< ChunkMetadataMetaInfo meta_info = std::nullopt 
) const
overrideprivatevirtual

Implements DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >.

Definition at line 164 of file ChunkMetadataRecycler.cpp.

References CHECK_EQ, CHUNK_METADATA, CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER, EMPTY_HASHED_PLAN_DAG_KEY, g_enable_data_recycler, g_use_chunk_metadata_cache, and DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCachedItemContainer().

169  {
171  key == EMPTY_HASHED_PLAN_DAG_KEY) {
172  return false;
173  }
176  auto metadata_cache = getCachedItemContainer(item_type, device_identifier);
177  auto candidate_it = std::find_if(
178  metadata_cache->begin(), metadata_cache->end(), [&key](const auto& cached_item) {
179  return cached_item.key == key;
180  });
181  return candidate_it != metadata_cache->end();
182 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:530
bool g_enable_data_recycler
Definition: Execute.cpp:146
bool g_use_chunk_metadata_cache
Definition: Execute.cpp:149
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER

+ Here is the call graph for this function:

void ChunkMetadataRecycler::initCache ( )
inlineoverridevirtual
void ChunkMetadataRecycler::markCachedItemAsDirty ( size_t  table_key,
std::unordered_set< QueryPlanHash > &  key_set,
CacheItemType  item_type,
DeviceIdentifier  device_identifier 
)
overridevirtual

Implements DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >.

Definition at line 135 of file ChunkMetadataRecycler.cpp.

References CHECK_EQ, CHUNK_METADATA, CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER, g_enable_data_recycler, g_use_chunk_metadata_cache, DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCachedItemContainer(), DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCacheLock(), and DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::markCachedItemAsDirtyImpl().

139  {
140  if (!g_enable_data_recycler || !g_use_chunk_metadata_cache || key_set.empty()) {
141  return;
142  }
145  std::lock_guard<std::mutex> lock(getCacheLock());
146  auto metadata_cache = getCachedItemContainer(item_type, device_identifier);
147  for (auto key : key_set) {
148  markCachedItemAsDirtyImpl(key, *metadata_cache);
149  }
150 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:530
void markCachedItemAsDirtyImpl(QueryPlanHash key, CachedItemContainer &m) const
Definition: DataRecycler.h:506
bool g_enable_data_recycler
Definition: Execute.cpp:146
bool g_use_chunk_metadata_cache
Definition: Execute.cpp:149
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER

+ Here is the call graph for this function:

void ChunkMetadataRecycler::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 
)
overridevirtual

Implements DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >.

Definition at line 53 of file ChunkMetadataRecycler.cpp.

References addQueryPlanDagForTableKeys(), CHECK, CHECK_EQ, CHUNK_METADATA, CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER, EMPTY_HASHED_PLAN_DAG_KEY, g_enable_data_recycler, g_use_chunk_metadata_cache, DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCachedItemContainer(), DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCacheLock(), DataRecyclerUtil::getDeviceIdentifierString(), DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getMetricTracker(), removeItemFromCache(), and VLOG.

60  {
63  return;
64  }
65  CHECK(meta_info.has_value());
68  std::lock_guard<std::mutex> lock(getCacheLock());
69  auto chunk_metadata_cache = getCachedItemContainer(item_type, device_identifier);
70  CHECK(chunk_metadata_cache);
71  auto candidate_it =
72  std::find_if(chunk_metadata_cache->begin(),
73  chunk_metadata_cache->end(),
74  [&key](const auto& cached_item) { return cached_item.key == key; });
75  bool has_cached_chunk_metadata = false;
76  if (candidate_it != chunk_metadata_cache->end()) {
77  has_cached_chunk_metadata = true;
78  CHECK(candidate_it->meta_info);
79  if (candidate_it->isDirty()) {
81  key, item_type, device_identifier, lock, candidate_it->meta_info);
82  has_cached_chunk_metadata = false;
83  }
84  }
85 
86  if (!has_cached_chunk_metadata) {
87  auto& metric_tracker = getMetricTracker(item_type);
88  auto new_cache_metric_ptr = metric_tracker.putNewCacheItemMetric(
89  key, device_identifier, item_size, compute_time);
90  CHECK_EQ(item_size, new_cache_metric_ptr->getMemSize());
91  VLOG(1) << "[" << item_type << ", "
93  << "] Put item to cache (key: " << key << ")";
94  chunk_metadata_cache->emplace_back(key, item, new_cache_metric_ptr, meta_info);
95  if (!meta_info->input_table_keys.empty()) {
96  addQueryPlanDagForTableKeys(key, meta_info->input_table_keys, lock);
97  }
98  }
99  return;
100 }
void removeItemFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier, std::lock_guard< std::mutex > &lock, std::optional< ChunkMetadataMetaInfo > meta_info=std::nullopt) override
#define CHECK_EQ(x, y)
Definition: Logger.h:230
static std::string getDeviceIdentifierString(DeviceIdentifier device_identifier)
Definition: DataRecycler.h:138
CacheMetricTracker & getMetricTracker(CacheItemType item_type)
Definition: DataRecycler.h:656
void addQueryPlanDagForTableKeys(size_t hashed_query_plan_dag, const std::unordered_set< size_t > &table_keys, std::lock_guard< std::mutex > &lock)
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:530
bool g_enable_data_recycler
Definition: Execute.cpp:146
bool g_use_chunk_metadata_cache
Definition: Execute.cpp:149
#define CHECK(condition)
Definition: Logger.h:222
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

void ChunkMetadataRecycler::removeItemFromCache ( QueryPlanHash  key,
CacheItemType  item_type,
DeviceIdentifier  device_identifier,
std::lock_guard< std::mutex > &  lock,
std::optional< ChunkMetadataMetaInfo meta_info = std::nullopt 
)
overrideprivatevirtual

Implements DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >.

Definition at line 102 of file ChunkMetadataRecycler.cpp.

References CHECK_EQ, CHUNK_METADATA, CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER, DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCachedItemContainer(), DataRecyclerUtil::getDeviceIdentifierString(), and VLOG.

Referenced by getItemFromCache(), and putItemToCache().

107  {
110  auto metadata_cache = getCachedItemContainer(item_type, device_identifier);
111  auto filter = [key](auto const& item) { return item.key == key; };
112  auto itr = std::find_if(metadata_cache->cbegin(), metadata_cache->cend(), filter);
113  if (itr != metadata_cache->cend()) {
114  VLOG(1) << "[" << item_type << ", "
115  << DataRecyclerUtil::getDeviceIdentifierString(device_identifier)
116  << "] remove cached item from cache (key: " << key << ")";
117  metadata_cache->erase(itr);
118  }
119 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
static std::string getDeviceIdentifierString(DeviceIdentifier device_identifier)
Definition: DataRecycler.h:138
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:530
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ChunkMetadataRecycler::removeTableKeyInfoFromQueryPlanDagMap ( size_t  table_key)

Definition at line 202 of file ChunkMetadataRecycler.cpp.

References table_key_to_query_plan_dag_map_.

202  {
203  table_key_to_query_plan_dag_map_.erase(table_key);
204 }
std::unordered_map< size_t, std::unordered_set< size_t > > table_key_to_query_plan_dag_map_
ChunkMetadataRecycler::std::numeric_limits ( )
ChunkMetadataRecycler::std::numeric_limits ( )
std::string ChunkMetadataRecycler::toString ( ) const
overridevirtual

Implements DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >.

Definition at line 152 of file ChunkMetadataRecycler.cpp.

References CHUNK_METADATA, CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER, DataRecycler< std::optional< ChunkMetadataMap >, ChunkMetadataMetaInfo >::getCachedItemContainer(), and DataRecyclerUtil::getDeviceIdentifierString().

152  {
153  auto chunk_metadata_cache_container = getCachedItemContainer(
155  std::ostringstream oss;
156  oss << "Chunk metadata cache:\n";
157  oss << "Device: "
160  << "\n # cached chunk metadata: " << chunk_metadata_cache_container->size();
161  return oss.str();
162 }
static std::string getDeviceIdentifierString(DeviceIdentifier device_identifier)
Definition: DataRecycler.h:138
std::shared_ptr< CachedItemContainer > getCachedItemContainer(CacheItemType item_type, DeviceIdentifier device_identifier) const
Definition: DataRecycler.h:530
constexpr DeviceIdentifier CHUNK_METADATA_CACHE_DEVICE_IDENTIFIER

+ Here is the call graph for this function:

Member Data Documentation

std::unordered_map<size_t, std::unordered_set<size_t> > ChunkMetadataRecycler::table_key_to_query_plan_dag_map_
private

The documentation for this class was generated from the following files: