41 : m_max_memory(max_memory), m_avail_memory(max_memory) {
48 std::set<uint8_t> &columns, uint32_t cell_count,
49 boost::shared_array<uint8_t> &result,
50 uint32_t result_length) {
51 lock_guard<MutexWithStatistics> lock(
m_mutex);
53 LookupHashIndex::iterator lookup_iter;
54 uint64_t length = result_length +
OVERHEAD + strlen(row);
59 if ((lookup_iter = hash_index.find(*key)) != hash_index.end()) {
61 hash_index.erase(lookup_iter);
66 Cache::iterator iter =
m_cache.begin();
79 result, result_length);
81 auto insert_result =
m_cache.push_back(entry);
82 assert(insert_result.second);
92 uint32_t *lenp, uint32_t *cell_count) {
93 lock_guard<MutexWithStatistics> lock(
m_mutex);
95 LookupHashIndex::iterator iter;
98 HT_INFOF(
"QueryCache hit rate over last 1000 lookups, cumulative = %f, %f",
106 if ((iter = hash_index.find(*key)) == hash_index.end())
111 hash_index.erase(iter);
113 pair<Sequence::iterator, bool> insert_result =
m_cache.push_back(entry);
114 assert(insert_result.second);
116 result = (*insert_result.first).result;
117 *lenp = (*insert_result.first).result_length;
118 *cell_count = (*insert_result.first).cell_count;
126 uint64_t *total_lookupsp, uint64_t *total_hitsp,
127 int32_t *total_waiters)
129 lock_guard<MutexWithStatistics> lock(
m_mutex);
138 lock_guard<MutexWithStatistics> lock(
m_mutex);
140 out <<
"\nQuery Cache:\n";
141 for (
auto &entry : sequence_index) {
142 out << entry.row_key.tablename <<
"['" << entry.row_key.row <<
"'] cols={";
144 for (uint8_t cf : entry.columns) {
151 out <<
"} Length=" << entry.result_length <<
" CellCount=" << entry.cell_count;
152 if (entry.cell_count > 0) {
154 serkey.
ptr = (uint8_t *)(entry.result.get() + 4);
156 out <<
" FirstKey=(" << key <<
")";
163 lock_guard<MutexWithStatistics> lock(
m_mutex);
165 InvalidateHashIndex::iterator iter;
166 RowKey row_key(tablename, row);
167 pair<InvalidateHashIndex::iterator, InvalidateHashIndex::iterator> p = hash_index.equal_range(row_key);
169 vector<uint8_t> intersection;
170 bool do_invalidation {};
172 intersection.reserve(columns.size());
174 while (p.first != p.second) {
175 do_invalidation = p.first->columns.empty() || columns.empty();
176 if (!do_invalidation) {
177 intersection.clear();
178 set_intersection(columns.begin(), columns.end(), p.first->columns.begin(),
179 p.first->columns.end(), back_inserter(intersection));
180 do_invalidation = !intersection.empty();
182 if (do_invalidation) {
183 length = (*p.first).result_length +
OVERHEAD + strlen((*p.first).row_key.row);
187 p.first = hash_index.erase(p.first);
bool lookup(Key *key, boost::shared_array< uint8_t > &result, uint32_t *lenp, uint32_t *cell_count)
Lookup.
void dump_keys(std::ofstream &out)
Dumps keys to output file.
PropertiesPtr properties
This singleton map stores all options.
void invalidate(const char *tablename, const char *row, std::set< uint8_t > &columns)
Invalidates cache entries.
uint64_t m_total_hit_count
Total hit count.
void set_statistics_enabled(bool val)
MutexWithStatistics m_mutex
Mutex to serialize member access
int32_t get_waiting_threads()
uint64_t m_total_lookup_count
Total lookup count.
Cache::nth_index< 2 >::type InvalidateHashIndex
uint64_t m_max_memory
Maximum memory to be used by cache.
QueryCache(uint64_t max_memory)
Constructor.
Cache::nth_index< 0 >::type Sequence
Compatibility Macros for C/C++.
void get_stats(uint64_t *max_memoryp, uint64_t *available_memoryp, uint64_t *total_lookupsp, uint64_t *total_hitsp, int32_t *total_waiters)
Gets cache statistics.
const uint8_t * ptr
The pointer to the serialized data.
#define HT_INFOF(msg,...)
bool insert(Key *key, const char *tablename, const char *row, std::set< uint8_t > &columns, uint32_t cell_count, boost::shared_array< uint8_t > &result, uint32_t result_length)
Inserts a query result.
Provides access to internal components of opaque key.
uint64_t m_avail_memory
Available memory.
Cache m_cache
Internal cache data structure.
Cache::nth_index< 1 >::type LookupHashIndex
uint32_t m_recent_hit_count
Recent hit count (for logging)