MySQL_STMTs_local is aware of being client or not

The called of MySQL_STMTs_local functions doesn't must specify if it is a client or a backend.
Added also a function in MySQL_Connection to make the connection aware it is a client.
pull/739/head
René Cannaò 10 years ago
parent b917da91a9
commit 016b596a0f

@ -145,14 +145,20 @@ class MySQL_STMTs_meta {
};
// class MySQL_STMTs_local associates a global statement ID with a local statement ID for a specific connection
class MySQL_STMTs_local {
private:
unsigned int num_entries;
bool is_client;
std::map<uint32_t, MYSQL_STMT *> m;
public:
MySQL_STMTs_local() {
MySQL_STMTs_local(bool _ic) {
is_client=_ic;
num_entries=0;
}
void set_is_client() {
is_client=true;
}
~MySQL_STMTs_local();
void insert(uint32_t global_statement_id, MYSQL_STMT *stmt);
/*
@ -180,8 +186,9 @@ class MySQL_STMTs_local {
}
return false; // not found
}
bool erase(uint32_t global_statement_id, bool client);
bool erase(uint32_t global_statement_id);
uint64_t compute_hash(unsigned int hostgroup, char *user, char *schema, char *query, unsigned int query_length);
unsigned int get_num_entries() { return num_entries; }
};

@ -148,5 +148,8 @@ class MySQL_Connection {
void ProcessQueryAndSetStatusFlags(char *query_digest_text);
void optimize();
void close_mysql();
void set_is_client(); // used for local_stmts
};
#endif /* __CLASS_MYSQL_CONNECTION_H */

@ -78,15 +78,17 @@ MySQL_STMTs_local::~MySQL_STMTs_local() {
m.erase(m.begin(),m.end());
}
bool MySQL_STMTs_local::erase(uint32_t global_statement_id, bool client) {
bool MySQL_STMTs_local::erase(uint32_t global_statement_id) {
auto s=m.find(global_statement_id);
if (s!=m.end()) { // found
if (client) {
if (is_client) {
// we are removing it from a client, not backend
GloMyStmt->ref_count(global_statement_id,-1,true, true);
m.erase(s);
return true;
}
// the following seems deprecated for now. Asserting
assert(0);
if (num_entries>1000) {
MYSQL_STMT *stmt=s->second;
mysql_stmt_close(stmt);

@ -1492,7 +1492,7 @@ __get_pkts_from_client:
memcpy(&stmt_global_id,(char *)pkt.ptr+5,sizeof(uint32_t));
// FIXME: no input validation
//sess_STMTs_meta->erase(stmt_global_id);
client_myds->myconn->local_stmts->erase(stmt_global_id, true);
client_myds->myconn->local_stmts->erase(stmt_global_id);
}
l_free(pkt.size,pkt.ptr);
// FIXME: this is not complete. Counters should be decreased
@ -1533,7 +1533,7 @@ __get_pkts_from_client:
// Session_STMT_Manager = new MySQL_STMT_Manager();
// }
if (client_myds->myconn->local_stmts==NULL) {
client_myds->myconn->local_stmts=new MySQL_STMTs_local();
client_myds->myconn->local_stmts=new MySQL_STMTs_local(true);
}
uint64_t hash=client_myds->myconn->local_stmts->compute_hash(current_hostgroup,(char *)client_myds->myconn->userinfo->username,(char *)client_myds->myconn->userinfo->schemaname,(char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength);
MySQL_STMT_Global_info *stmt_info=NULL;

@ -1611,7 +1611,8 @@ MySQL_Session * MySQL_Thread::create_new_session_and_client_data_stream(int _fd)
#endif
//sess->client_myds->myconn=new MySQL_Connection();
//MySQL_Connection *myconn=sess->client_myds->myconn;
MySQL_Connection *myconn=new MySQL_Connection;
MySQL_Connection *myconn=new MySQL_Connection();
myconn->set_is_client(); // this is used for prepared statements
sess->client_myds->attach_connection(myconn);
//myconn=new MySQL_Connection(); // 20141011
// if (mysql_thread___have_compress) {

@ -179,7 +179,7 @@ MySQL_Connection::MySQL_Connection() {
creation_time=0;
processing_multi_statement=false;
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 4, "Creating new MySQL_Connection %p\n", this);
local_stmts=new MySQL_STMTs_local();
local_stmts=new MySQL_STMTs_local(false); // false by default, it is a backend
};
MySQL_Connection::~MySQL_Connection() {
@ -513,6 +513,10 @@ void MySQL_Connection::store_result_cont(short event) {
async_exit_status = mysql_store_result_cont(&mysql_result , mysql , mysql_status(event, true));
}
void MySQL_Connection::set_is_client() {
local_stmts->set_is_client();
}
#define NEXT_IMMEDIATE(new_st) do { async_state_machine = new_st; goto handler_again; } while (0)
MDB_ASYNC_ST MySQL_Connection::handler(short event) {

Loading…
Cancel
Save