From 5eff88f24f2bbc3a60a2f62ffe37b3839b7b46a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 27 Dec 2015 03:19:53 +0000 Subject: [PATCH] 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 --- include/query_cache.hpp | 4 ++-- lib/MySQL_Session.cpp | 4 ++-- lib/Query_Cache.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/query_cache.hpp b/include/query_cache.hpp index 58d7d462a..8d0539ac9 100644 --- a/include/query_cache.hpp +++ b/include/query_cache.hpp @@ -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 */ diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index d4c762a04..94f01533b 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -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); diff --git a/lib/Query_Cache.cpp b/lib/Query_Cache.cpp index 1b36daca9..2748317da 100644 --- a/lib/Query_Cache.cpp +++ b/lib/Query_Cache.cpp @@ -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);