0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Private Types | Private Attributes | List of all members
Hypertable::QueryCache Class Reference

Query cache. More...

#include <QueryCache.h>

Collaboration diagram for Hypertable::QueryCache:
Collaboration graph
[legend]

Classes

class  Key
 Hash key to query cache. More...
 
struct  KeyHash
 
class  QueryCacheEntry
 Internal cache entry. More...
 
class  RowKey
 Row key information. More...
 
struct  RowKeyHash
 

Public Member Functions

 QueryCache (uint64_t max_memory)
 Constructor. More...
 
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. More...
 
bool lookup (Key *key, boost::shared_array< uint8_t > &result, uint32_t *lenp, uint32_t *cell_count)
 Lookup. More...
 
void invalidate (const char *tablename, const char *row, std::set< uint8_t > &columns)
 Invalidates cache entries. More...
 
uint64_t available_memory ()
 Gets available memory. More...
 
uint64_t memory_used ()
 Gets memory used. More...
 
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. More...
 
void dump_keys (std::ofstream &out)
 Dumps keys to output file. More...
 

Private Types

typedef
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
 
typedef Cache::nth_index< 0 >::type Sequence
 
typedef Cache::nth_index< 1 >::type LookupHashIndex
 
typedef Cache::nth_index< 2 >::type InvalidateHashIndex
 

Private Attributes

MutexWithStatistics m_mutex
 Mutex to serialize member access More...
 
Cache m_cache
 Internal cache data structure. More...
 
uint64_t m_max_memory {}
 Maximum memory to be used by cache. More...
 
uint64_t m_avail_memory {}
 Available memory. More...
 
uint64_t m_total_lookup_count {}
 Total lookup count. More...
 
uint64_t m_total_hit_count {}
 Total hit count. More...
 
uint32_t m_recent_hit_count {}
 Recent hit count (for logging) More...
 

Detailed Description

Query cache.

Definition at line 47 of file QueryCache.h.

Member Typedef Documentation

typedef 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> > > Hypertable::QueryCache::Cache
private

Definition at line 223 of file QueryCache.h.

typedef Cache::nth_index<2>::type Hypertable::QueryCache::InvalidateHashIndex
private

Definition at line 227 of file QueryCache.h.

typedef Cache::nth_index<1>::type Hypertable::QueryCache::LookupHashIndex
private

Definition at line 226 of file QueryCache.h.

typedef Cache::nth_index<0>::type Hypertable::QueryCache::Sequence
private

Definition at line 225 of file QueryCache.h.

Constructor & Destructor Documentation

QueryCache::QueryCache ( uint64_t  max_memory)

Constructor.

Initializes m_max_memory and m_avail_memory to max_memory.

Parameters
max_memoryMaximum amount of memory to be used by the cache

Definition at line 40 of file QueryCache.cc.

Member Function Documentation

uint64_t Hypertable::QueryCache::available_memory ( )
inline

Gets available memory.

Returns m_avail_memory

Returns
Available memory

Definition at line 152 of file QueryCache.h.

void QueryCache::dump_keys ( std::ofstream &  out)

Dumps keys to output file.

Parameters
outOutput file to dump keys to

Definition at line 137 of file QueryCache.cc.

void QueryCache::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.

Parameters
max_memorypAddress of variable to hold max memory.
available_memorypAddress of variable to hold available memory.
total_lookupspAddress of variable to hold total lookups.
total_hitspAddress of variable to hold total hits.
total_waitersAddress of variable to hold number of threads waiting on the mutex

Definition at line 125 of file QueryCache.cc.

bool QueryCache::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.

If the size of the entry is greater than m_max_memory, then the function returns without modifying the cache. Then the old entry is removed, if there was one. Then room is created in the cache for the new entry by removing the oldest entries until enough space is available. Finally, a new cache entry is created and inserted into the cache. This function also maintains the m_avail_memory value which represents how much room is available in the cache. It is computed as m_max_memory minus an approximation of how much space is taken up by the existing cache entries.

Parameters
keyHash key for entry to be inserted
tablenameTable name for entry to be inserted (must remain valid for lifetime of cache entry)
rowRow of entry to be inserted (must remain valid for lifetime of cache entry)
columnsSet of column IDs from scan specification used to create entry to be inserted
cell_countCount of cells in entry to be inserted
resultQuery result
result_lengthLength of query result
Returns
true if result was inserted, false otherwise.

Definition at line 47 of file QueryCache.cc.

void QueryCache::invalidate ( const char *  tablename,
const char *  row,
std::set< uint8_t > &  columns 
)

Invalidates cache entries.

Creates a RowKey object from tablename and row and finds all matching entires in the cache. For each matching cache entry whose columns intersect with columns, the entry is invalidated. The entry is also invalidated if either columns is empty or the cache entries columns are empty.

Parameters
tablenameTable of entries to invalidate
rowRow entries to invalidate
columnsColumns of entries to invalidate

HT_ASSERT(strcmp((*p.first).row_key.tablename, tablename) == 0 && strcmp((*p.first).row_key.row.c_str(), row) == 0);

Definition at line 162 of file QueryCache.cc.

bool QueryCache::lookup ( Key key,
boost::shared_array< uint8_t > &  result,
uint32_t *  lenp,
uint32_t *  cell_count 
)

Lookup.

Looks up the entry with key key, and if found, returns the query result and associated information in result, lenp, and cell_count. Also, if a cache entry is found, it is removed and re-inserted for LRU ordering.

Parameters
keyHash key
resultReference to shared array to hold result
lenpPointer to variable to hold result length
cell_countPointer to variable to hold count of cells in result
Returns
true if an entry was found, false otherwise

Definition at line 91 of file QueryCache.cc.

uint64_t Hypertable::QueryCache::memory_used ( )
inline

Gets memory used.

Memory used is calculated as m_max_memory minus m_avail_memory.

Returns
Memory used

Definition at line 160 of file QueryCache.h.

Member Data Documentation

uint64_t Hypertable::QueryCache::m_avail_memory {}
private

Available memory.

Definition at line 239 of file QueryCache.h.

Cache Hypertable::QueryCache::m_cache
private

Internal cache data structure.

Definition at line 233 of file QueryCache.h.

uint64_t Hypertable::QueryCache::m_max_memory {}
private

Maximum memory to be used by cache.

Definition at line 236 of file QueryCache.h.

MutexWithStatistics Hypertable::QueryCache::m_mutex
private

Mutex to serialize member access

Definition at line 230 of file QueryCache.h.

uint32_t Hypertable::QueryCache::m_recent_hit_count {}
private

Recent hit count (for logging)

Definition at line 248 of file QueryCache.h.

uint64_t Hypertable::QueryCache::m_total_hit_count {}
private

Total hit count.

Definition at line 245 of file QueryCache.h.

uint64_t Hypertable::QueryCache::m_total_lookup_count {}
private

Total lookup count.

Definition at line 242 of file QueryCache.h.


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