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

#include <LRUEvictionAlgorithm.h>

+ Inheritance diagram for LRUEvictionAlgorithm:
+ Collaboration diagram for LRUEvictionAlgorithm:

Public Member Functions

 ~LRUEvictionAlgorithm () override
 
const ChunkKey evictNextChunk () override
 
void touchChunk (const ChunkKey &) override
 
void removeChunk (const ChunkKey &) override
 
std::string dumpEvictionQueue ()
 
- Public Member Functions inherited from CacheEvictionAlgorithm
virtual ~CacheEvictionAlgorithm ()
 

Private Attributes

std::list< ChunkKeycache_items_list_
 
std::map< const ChunkKey,
std::list< ChunkKey >
::iterator > 
cache_items_map_
 
mapd_shared_mutex cache_mutex_
 

Detailed Description

Definition at line 38 of file LRUEvictionAlgorithm.h.

Constructor & Destructor Documentation

LRUEvictionAlgorithm::~LRUEvictionAlgorithm ( )
inlineoverride

Definition at line 40 of file LRUEvictionAlgorithm.h.

40 {}

Member Function Documentation

std::string LRUEvictionAlgorithm::dumpEvictionQueue ( )

Definition at line 59 of file LRUEvictionAlgorithm.cpp.

References cache_items_list_, cache_mutex_, and show_chunk().

Referenced by File_Namespace::CachingFileMgr::dump(), File_Namespace::CachingFileMgr::dumpEvictionQueue(), and File_Namespace::CachingFileMgr::dumpTableQueue().

59  {
60  mapd_shared_lock<mapd_shared_mutex> lock(cache_mutex_);
61  std::string ret = "Eviction queue:\n{";
62  for (auto chunk : cache_items_list_) {
63  ret += show_chunk(chunk) + ", ";
64  }
65  ret += "}\n";
66  return ret;
67 }
std::list< ChunkKey > cache_items_list_
mapd_shared_mutex cache_mutex_
std::string show_chunk(const ChunkKey &key)
Definition: types.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const ChunkKey LRUEvictionAlgorithm::evictNextChunk ( )
overridevirtual

Implements CacheEvictionAlgorithm.

Definition at line 27 of file LRUEvictionAlgorithm.cpp.

References cache_items_list_, cache_items_map_, cache_mutex_, and CHECK.

Referenced by anonymous_namespace{CachingFileMgr.cpp}::evict_chunk_or_fail().

27  {
28  mapd_unique_lock<mapd_shared_mutex> lock(cache_mutex_);
29  if (cache_items_list_.size() < 1) {
30  throw NoEntryFoundException();
31  }
32  auto last = cache_items_list_.back();
33  CHECK(cache_items_map_.erase(last) > 0) << "Chunk not evicted!";
34  cache_items_list_.pop_back();
35  return last;
36 }
std::list< ChunkKey > cache_items_list_
std::map< const ChunkKey, std::list< ChunkKey >::iterator > cache_items_map_
mapd_shared_mutex cache_mutex_
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the caller graph for this function:

void LRUEvictionAlgorithm::removeChunk ( const ChunkKey key)
overridevirtual

Implements CacheEvictionAlgorithm.

Definition at line 49 of file LRUEvictionAlgorithm.cpp.

References cache_items_list_, cache_items_map_, and cache_mutex_.

49  {
50  mapd_unique_lock<mapd_shared_mutex> lock(cache_mutex_);
51  auto it = cache_items_map_.find(key);
52  if (it == cache_items_map_.end()) {
53  return;
54  }
55  cache_items_list_.erase(it->second);
56  cache_items_map_.erase(key);
57 }
std::list< ChunkKey > cache_items_list_
std::map< const ChunkKey, std::list< ChunkKey >::iterator > cache_items_map_
mapd_shared_mutex cache_mutex_
void LRUEvictionAlgorithm::touchChunk ( const ChunkKey key)
overridevirtual

Implements CacheEvictionAlgorithm.

Definition at line 38 of file LRUEvictionAlgorithm.cpp.

References cache_items_list_, cache_items_map_, and cache_mutex_.

38  {
39  mapd_unique_lock<mapd_shared_mutex> lock(cache_mutex_);
40  auto it = cache_items_map_.find(key);
41  if (it != cache_items_map_.end()) {
42  cache_items_list_.erase(it->second);
43  cache_items_map_.erase(it);
44  }
45  cache_items_list_.emplace_front(key);
46  cache_items_map_[key] = cache_items_list_.begin();
47 }
std::list< ChunkKey > cache_items_list_
std::map< const ChunkKey, std::list< ChunkKey >::iterator > cache_items_map_
mapd_shared_mutex cache_mutex_

Member Data Documentation

std::list<ChunkKey> LRUEvictionAlgorithm::cache_items_list_
private

Definition at line 51 of file LRUEvictionAlgorithm.h.

Referenced by dumpEvictionQueue(), evictNextChunk(), removeChunk(), and touchChunk().

std::map<const ChunkKey, std::list<ChunkKey>::iterator> LRUEvictionAlgorithm::cache_items_map_
private

Definition at line 52 of file LRUEvictionAlgorithm.h.

Referenced by evictNextChunk(), removeChunk(), and touchChunk().

mapd_shared_mutex LRUEvictionAlgorithm::cache_mutex_
mutableprivate

Definition at line 53 of file LRUEvictionAlgorithm.h.

Referenced by dumpEvictionQueue(), evictNextChunk(), removeChunk(), and touchChunk().


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