22 #ifndef Hypertable_RangeServer_QueryCache_h
23 #define Hypertable_RangeServer_QueryCache_h
28 #include <boost/multi_index_container.hpp>
29 #include <boost/multi_index/hashed_index.hpp>
30 #include <boost/multi_index/mem_fun.hpp>
31 #include <boost/multi_index/sequenced_index.hpp>
32 #include <boost/multi_index/member.hpp>
33 #include <boost/shared_array.hpp>
60 return memcmp(digest, other.
digest, 16) == 0;
77 RowKey(
const char *t,
const char *r) : tablename(t), row(r) {
84 return !strcmp(tablename, other.
tablename) && !strcmp(row, other.
row);
121 bool insert(
Key *key,
const char *tablename,
const char *row,
122 std::set<uint8_t> &columns, uint32_t cell_count,
123 boost::shared_array<uint8_t> &result, uint32_t result_length);
135 bool lookup(
Key *key, boost::shared_array<uint8_t> &result, uint32_t *lenp,
136 uint32_t *cell_count);
147 void invalidate(
const char * tablename,
const char *row, std::set<uint8_t> &columns);
153 std::lock_guard<MutexWithStatistics> lock(m_mutex);
154 return m_avail_memory;
161 std::lock_guard<MutexWithStatistics> lock(m_mutex);
162 return m_max_memory-m_avail_memory;
172 void get_stats(uint64_t *max_memoryp, uint64_t *available_memoryp,
173 uint64_t *total_lookupsp, uint64_t *total_hitsp,
174 int32_t *total_waiters);
178 void dump_keys(std::ofstream &out);
186 std::set<uint8_t> &column_ids, uint32_t cells,
187 boost::shared_array<uint8_t> &res, uint32_t rlen) :
188 key(k), row_key(tname, rw), result(res), result_length(rlen), cell_count(cells) {
189 columns.swap(column_ids);
193 void dump() { std::cout << row_key.tablename <<
":" << row_key.row <<
"\n"; }
204 return (std::size_t)k.
digest[0];
214 typedef boost::multi_index_container<
218 hashed_unique<const_mem_fun<QueryCacheEntry,
Key,
219 &QueryCacheEntry::lookup_key>, KeyHash>,
220 hashed_non_unique<const_mem_fun<QueryCacheEntry, RowKey,
221 &QueryCacheEntry::invalidate_key>, RowKeyHash>
236 uint64_t m_max_memory {};
239 uint64_t m_avail_memory {};
242 uint64_t m_total_lookup_count {};
245 uint64_t m_total_hit_count {};
248 uint32_t m_recent_hit_count {};
259 #endif // Hypertable_RangeServer_QueryCache_h
QueryCacheEntry(Key &k, const char *tname, const char *rw, std::set< uint8_t > &column_ids, uint32_t cells, boost::shared_array< uint8_t > &res, uint32_t rlen)
boost::multi_index_container< QueryCacheEntry, indexed_by< sequenced<>, hashed_unique< const_mem_fun< QueryCacheEntry, Key,&QueryCacheEntry::lookup_key >, KeyHash >, hashed_non_unique< const_mem_fun< QueryCacheEntry, RowKey,&QueryCacheEntry::invalidate_key >, RowKeyHash > > > Cache
MutexWithStatistics m_mutex
Mutex to serialize member access
bool operator==(const Key &other) const
Equality operator.
Cache::nth_index< 2 >::type InvalidateHashIndex
uint32_t fletcher32(const void *data8, size_t len8)
Compute fletcher32 checksum for arbitary data.
const char * tablename
Table name
std::size_t operator()(const RowKey k) const
uint32_t hash
Hash code computed from tablename and row.
Cache::nth_index< 0 >::type Sequence
std::set< uint8_t > columns
boost::shared_array< uint8_t > result
std::shared_ptr< QueryCache > QueryCachePtr
Smart pointer to QueryCache.
bool operator==(const RowKey &other) const
Equality operator.
Mutex that maintains wait threads count.
RowKey(const char *t, const char *r)
Constructor.
Implementation of checksum routines.
Scoped lockers for recursive and non-recursive mutexes.
Provides access to internal components of opaque key.
Cache m_cache
Internal cache data structure.
Cache::nth_index< 1 >::type LookupHashIndex
RowKey invalidate_key() const
uint64_t memory_used()
Gets memory used.
uint64_t available_memory()
Gets available memory.
std::size_t operator()(const Key k) const
uint64_t digest[2]
Hash digest.