22 #ifndef Hypertable_RangeServer_FileBlockCache_h
23 #define Hypertable_RangeServer_FileBlockCache_h
29 #include <boost/multi_index_container.hpp>
30 #include <boost/multi_index/hashed_index.hpp>
31 #include <boost/multi_index/mem_fun.hpp>
32 #include <boost/multi_index/sequenced_index.hpp>
46 : m_min_memory(min_memory), m_max_memory(max_memory), m_limit(max_memory),
47 m_available(max_memory), m_accesses(0), m_hits(0), m_compressed(compressed)
53 bool checkout(
int file_id, uint64_t file_offset, uint8_t **blockp,
55 void checkin(
int file_id, uint64_t file_offset);
56 bool insert(
int file_id, uint64_t file_offset,
57 uint8_t *block, uint32_t length,
58 const EventPtr &event,
bool checkout);
59 bool contains(
int file_id, uint64_t file_offset);
61 void increase_limit(int64_t amount);
71 int64_t decrease_limit(int64_t amount);
74 std::lock_guard<std::mutex> lock(m_mutex);
83 std::lock_guard<std::mutex> lock(m_mutex);
84 int64_t memory_used = m_limit - m_available;
85 if (memory_used > m_min_memory) {
86 m_limit -= m_available;
90 m_limit = m_min_memory;
91 m_available = m_limit - memory_used;
96 std::lock_guard<std::mutex> lock(m_mutex);
97 return (int64_t)(m_limit - m_available);
101 std::lock_guard<std::mutex> lock(m_mutex);
106 return ++ms_next_file_id;
108 void get_stats(uint64_t *max_memoryp, uint64_t *available_memoryp,
109 uint64_t *accessesp, uint64_t *hitsp);
112 int64_t make_room(int64_t amount);
114 inline static int64_t
make_key(
int file_id, uint64_t file_offset) {
117 return ((int64_t)file_id << 36) | (int64_t)file_offset;
124 : file_id(id), file_offset(offset), event(e) {}
128 uint64_t file_offset {};
130 uint32_t ref_count {};
143 return (std::size_t)((x >> 32) * 31) ^ (std::size_t)x;
147 typedef boost::multi_index_container<
151 hashed_unique<const_mem_fun<BlockCacheEntry, int64_t,
152 &BlockCacheEntry::key>, HashI64>
172 #endif // Hypertable_RangeServer_FileBlockCache_h
FileBlockCache(int64_t min_memory, int64_t max_memory, bool compressed)
void operator()(BlockCacheEntry &entry)
static std::atomic< int > ms_next_file_id
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
boost::multi_index_container< BlockCacheEntry, indexed_by< sequenced<>, hashed_unique< const_mem_fun< BlockCacheEntry, int64_t,&BlockCacheEntry::key >, HashI64 > > > BlockCache
static int64_t make_key(int file_id, uint64_t file_offset)
Logging routines and macros.
void cap_memory_use()
Sets limit to memory currently used, it will not reduce the limit below min_memory.
BlockCache::nth_index< 0 >::type Sequence
std::size_t operator()(int64_t x) const
BlockCacheEntry(int id, uint64_t offset, const EventPtr &e)
static int get_next_file_id()
BlockCache::nth_index< 1 >::type HashIndex