diff --git a/include/MySQL_PreparedStatement.h b/include/MySQL_PreparedStatement.h index 8986f1e63..ea9e10672 100644 --- a/include/MySQL_PreparedStatement.h +++ b/include/MySQL_PreparedStatement.h @@ -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 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; } }; diff --git a/include/mysql_connection.h b/include/mysql_connection.h index 78391b844..184a9599a 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -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 */ diff --git a/lib/MySQL_PreparedStatement.cpp b/lib/MySQL_PreparedStatement.cpp index 3e21c97e0..522771fa2 100644 --- a/lib/MySQL_PreparedStatement.cpp +++ b/lib/MySQL_PreparedStatement.cpp @@ -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); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 2db397b92..7ce3f104e 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -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; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 69f41a4f8..124b2ab79 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -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) { diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 8365cf35f..545dda109 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -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) {