Changes on QC

Summary:
removed KV_Btree_Array.cpp
removed query_SQL from MySQL_Data_Stream
added some documentation for QC_entry_t
Query_Cache::get() and Query_Cache::set() now requires also the length of the key
Query_Cache::get() and Query_Cache::set() now process hk (the hash key) using the length of the key

Query Cache enhancement on user/schema

Query Cache now supports distinct entries based on user/schema .
This is achieved passing to Query_Cache::set() and Query_Cache::get() the hash that identifies user and schema

Test Plan: None

Reviewers: rene

Differential Revision: http://phab.sysown.com/D3
SQLiteServer
René Cannaò 11 years ago
parent 60ddf5d8e4
commit 5eff88f24f

@ -72,8 +72,8 @@ class Query_Cache {
Query_Cache();
~Query_Cache();
void print_version();
bool set(const unsigned char *, uint32_t, unsigned char *, uint32_t, time_t);
unsigned char * get(const unsigned char *, const uint32_t, uint32_t *);
bool set(uint64_t , const unsigned char *, uint32_t, unsigned char *, uint32_t, time_t);
unsigned char * get(uint64_t , const unsigned char *, const uint32_t, uint32_t *);
uint64_t flush();
};
#endif /* __CLASS_QUERY_CACHE_H */

@ -1641,7 +1641,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
// memcpy(client_myds->query_SQL,(unsigned char *)pkt->ptr+sizeof(mysql_hdr)+1,pkt->size-sizeof(mysql_hdr)-1);
// client_myds->query_SQL[pkt->size-sizeof(mysql_hdr)-1]=0;
uint32_t resbuf=0;
unsigned char *aa=GloQC->get((const unsigned char *)client_myds->mysql_real_query.QueryPtr , client_myds->mysql_real_query.QuerySize , &resbuf);
unsigned char *aa=GloQC->get( client_myds->myconn->userinfo->hash, (const unsigned char *)client_myds->mysql_real_query.QueryPtr , client_myds->mysql_real_query.QuerySize , &resbuf);
if (aa) {
l_free(pkt->size,pkt->ptr);
// l_free(strlen((char *)client_myds->query_SQL)+1,client_myds->query_SQL);
@ -1798,7 +1798,7 @@ void MySQL_Session::MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *My
client_myds->resultset_length=MyRS->resultset_size;
unsigned char *aa=client_myds->resultset2buffer(false);
while (client_myds->resultset->len) client_myds->resultset->remove_index(client_myds->resultset->len-1,NULL);
GloQC->set((const unsigned char *)client_myds->mysql_real_query.QueryPtr , client_myds->mysql_real_query.QuerySize , aa,client_myds->resultset_length,qpo->cache_ttl);
GloQC->set( client_myds->myconn->userinfo->hash , (const unsigned char *)client_myds->mysql_real_query.QueryPtr , client_myds->mysql_real_query.QuerySize , aa,client_myds->resultset_length,qpo->cache_ttl);
l_free(client_myds->resultset_length,aa);
client_myds->resultset_length=0;
// l_free(strlen((char *)client_myds->query_SQL)+1,client_myds->query_SQL);

@ -259,10 +259,10 @@ Query_Cache::~Query_Cache() {
unsigned char * Query_Cache::get(const unsigned char *kp, const uint32_t kl, uint32_t *lv) {
unsigned char * Query_Cache::get(uint64_t user_hash, const unsigned char *kp, const uint32_t kl, uint32_t *lv) {
unsigned char *result=NULL;
uint64_t hk=SpookyHash::Hash64(kp, kl,0);
uint64_t hk=SpookyHash::Hash64(kp, kl, user_hash);
unsigned char i=hk%SHARED_QUERY_CACHE_HASH_TABLES;
QC_entry_t *entry=KVs[i].lookup(hk);
@ -280,7 +280,7 @@ unsigned char * Query_Cache::get(const unsigned char *kp, const uint32_t kl, uin
return result;
}
bool Query_Cache::set(const unsigned char *kp, uint32_t kl, unsigned char *vp, uint32_t vl, time_t expire) {
bool Query_Cache::set(uint64_t user_hash, const unsigned char *kp, uint32_t kl, unsigned char *vp, uint32_t vl, time_t expire) {
QC_entry_t *entry = (QC_entry_t *)malloc(sizeof(QC_entry_t));
entry->klen=kl;
entry->length=vl;
@ -295,7 +295,7 @@ bool Query_Cache::set(const unsigned char *kp, uint32_t kl, unsigned char *vp, u
} else {
entry->expire=QCnow+expire; // expire is seconds
}
uint64_t hk=SpookyHash::Hash64(kp, kl, 0);
uint64_t hk=SpookyHash::Hash64(kp, kl, user_hash);
unsigned char i=hk%SHARED_QUERY_CACHE_HASH_TABLES;
entry->key=hk;
KVs[i].replace(hk, entry);

Loading…
Cancel
Save