Remove all references to PS handling before 1.4

Handling of prepared statements changed a lot in 1.4 , as a lot of code was rewritten.
Old code was still present, and was possible to toggle it on and off based on PROXYSQL_STMT_V14 .
Because only the new code is maintained, all references to old code are now removed,
including PROXYSQL_STMT_V14
This commit is contained in:
René Cannaò 2017-12-30 17:29:46 +01:00
Родитель 232bec9ad4
Коммит 3520dbbacc
9 изменённых файлов: 0 добавлений и 536 удалений

Просмотреть файл

@ -38,8 +38,6 @@ To summarie the most important classes:
// it is an internal representation of prepared statement
// it include all metadata associated with it
#define PROXYSQL_STMT_V14
class MySQL_STMT_Global_info {
private:
void compute_hash();
@ -55,11 +53,7 @@ class MySQL_STMT_Global_info {
unsigned int hostgroup_id;
int ref_count_client;
int ref_count_server;
#ifndef PROXYSQL_STMT_V14
uint32_t statement_id;
#else
uint64_t statement_id;
#endif
uint16_t num_columns;
uint16_t num_params;
uint16_t warning_count;
@ -71,12 +65,8 @@ class MySQL_STMT_Global_info {
} properties;
bool is_select_NOT_for_update;
MYSQL_BIND **params; // seems unused (?)
#ifndef PROXYSQL_STMT_V14
MySQL_STMT_Global_info(uint32_t id, unsigned int h, char *u, char *s, char *q, unsigned int ql, MYSQL_STMT *stmt, uint64_t _h);
#else
MySQL_STMT_Global_info(uint64_t id, unsigned int h, char *u, char *s, char *q, unsigned int ql, MYSQL_STMT *stmt, uint64_t _h);
void update_metadata(MYSQL_STMT *stmt);
#endif
~MySQL_STMT_Global_info();
};
@ -175,76 +165,8 @@ class MySQL_STMTs_meta {
}
};
#ifndef PROXYSQL_STMT_V14
// 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, uint32_t> client_stmt_to_global_id;
std::map<uint32_t, MYSQL_STMT *> m;
public:
MySQL_Session *sess;
MySQL_STMTs_local(bool _ic) {
sess=NULL;
is_client=_ic;
num_entries=0;
client_stmt_to_global_id = std::map<uint32_t, uint32_t>();
m = std::map<uint32_t, MYSQL_STMT *>();
}
void set_is_client(MySQL_Session *_s) {
sess=_s;
is_client=true;
}
~MySQL_STMTs_local();
void insert(uint32_t global_statement_id, MYSQL_STMT *stmt);
// we declare it here to be inline
MYSQL_STMT * find(uint32_t global_statement_id) {
auto s=m.find(global_statement_id);
if (s!=m.end()) { // found
return s->second;
}
return NULL; // not found
}
uint32_t generate_new_stmt_id(uint32_t global_statement_id);
uint32_t find_original_id(uint32_t client_stmt_id);
bool exists(uint32_t global_statement_id) {
auto s=m.find(global_statement_id);
if (s!=m.end()) { // found
return true;
}
return false; // not found
}
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; }
};
class MySQL_STMT_Manager {
private:
uint32_t next_statement_id;
rwlock_t rwlock;
std::map<uint32_t, MySQL_STMT_Global_info *> m; // map using statement id
std::map<uint64_t, MySQL_STMT_Global_info *> h; // map using hashes
std::stack<uint32_t> free_stmt_ids;
public:
MySQL_STMT_Manager();
~MySQL_STMT_Manager();
uint32_t generate_new_stmt_id() {
return __sync_add_and_fetch(&next_statement_id,1);
}
int ref_count(uint32_t statement_id, int cnt, bool lock, bool is_client);
MySQL_STMT_Global_info * add_prepared_statement(bool *is_new, unsigned int h, char *u, char *s, char *q, unsigned int ql, MYSQL_STMT *stmt, bool lock=true);
MySQL_STMT_Global_info * add_prepared_statement(bool *is_new, unsigned int h, char *u, char *s, char *q, unsigned int ql, MYSQL_STMT *stmt, int _cache_ttl, int _timeout, int _delay, bool lock=true);
MySQL_STMT_Global_info * find_prepared_statement_by_stmt_id(uint32_t id, bool lock=true);
MySQL_STMT_Global_info * find_prepared_statement_by_hash(uint64_t hash, bool lock=true);
uint32_t total_prepared_statements() { return next_statement_id-1; }
void active_prepared_statements(uint32_t *unique, uint32_t *total);
};
#else // PROXYSQL_STMT_V14
class MySQL_STMTs_local_v14 {
private:
bool is_client_;
@ -320,6 +242,5 @@ class MySQL_STMT_Manager_v14 {
void get_metrics(uint64_t *c_unique, uint64_t *c_total, uint64_t *stmt_max_stmt_id, uint64_t *cached, uint64_t *s_unique, uint64_t *s_total);
SQLite3_result * get_prepared_statements_global_infos();
};
#endif // PROXYSQL_STMT_V14
#endif /* CLASS_MYSQL_PREPARED_STATEMENT_H */

Просмотреть файл

@ -38,11 +38,7 @@ class Query_Info {
MYSQL_STMT *mysql_stmt;
stmt_execute_metadata_t *stmt_meta;
#ifndef PROXYSQL_STMT_V14
uint32_t stmt_global_id;
#else
uint64_t stmt_global_id;
#endif
MySQL_STMT_Global_info *stmt_info;
int QueryLength;

Просмотреть файл

@ -65,11 +65,7 @@ class MySQL_Connection {
unsigned long long last_time_used;
unsigned long long timeout;
int fd;
#ifndef PROXYSQL_STMT_V14
MySQL_STMTs_local *local_stmts; // local view of prepared statements
#else
MySQL_STMTs_local_v14 *local_stmts; // local view of prepared statements
#endif
MYSQL *mysql;
MYSQL *ret_mysql;
MYSQL_RES *mysql_result;

Просмотреть файл

@ -1225,11 +1225,7 @@ void MySQL_HostGroups_Manager::push_MyConn_to_pool(MySQL_Connection *c, bool _lo
}
if (mysrvc->status==MYSQL_SERVER_STATUS_ONLINE) {
if (c->async_state_machine==ASYNC_IDLE) {
#ifndef PROXYSQL_STMT_V14
if (c->local_stmts->get_num_entries() > (unsigned int)GloMTH->variables.max_stmts_per_connection) {
#else
if (c->local_stmts->get_num_backend_stmts() > (unsigned int)GloMTH->variables.max_stmts_per_connection) {
#endif
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Destroying MySQL_Connection %p, server %s:%d with status %d because has too many prepared statements\n", c, mysrvc->address, mysrvc->port, mysrvc->status);
// delete c;
mysrvc->ConnectionsUsed->add(c);

Просмотреть файл

@ -3,7 +3,6 @@
#include "SpookyV2.h"
//#ifndef PROXYSQL_STMT_V14
//extern MySQL_STMT_Manager *GloMyStmt;
//static uint32_t add_prepared_statement_calls = 0;
//static uint32_t find_prepared_statement_by_hash_calls = 0;
@ -133,11 +132,7 @@ void *StmtLongDataHandler::get(uint32_t _stmt_id, uint16_t _param_id,
return NULL;
}
//#ifndef PROXYSQL_STMT_V14
//MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint32_t id, unsigned int h,
//#else
MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
//#endif
char *u, char *s, char *q,
unsigned int ql,
MYSQL_STMT *stmt, uint64_t _h) {
@ -223,7 +218,6 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
}
}
#ifdef PROXYSQL_STMT_V14
void MySQL_STMT_Global_info::update_metadata(MYSQL_STMT *stmt) {
int i;
bool need_refresh = false;
@ -407,7 +401,6 @@ void MySQL_STMT_Global_info::update_metadata(MYSQL_STMT *stmt) {
// till here is copied from constructor
}
}
#endif
MySQL_STMT_Global_info::~MySQL_STMT_Global_info() {
free(username);
@ -464,300 +457,7 @@ MySQL_STMT_Global_info::~MySQL_STMT_Global_info() {
digest_text = NULL;
}
}
/*
#ifndef PROXYSQL_STMT_V14
uint64_t MySQL_STMTs_local::compute_hash(unsigned int hostgroup, char *user,
char *schema, char *query,
unsigned int query_length) {
uint64_t hash;
hash = stmt_compute_hash(hostgroup, user, schema, query, query_length);
return hash;
}
MySQL_STMTs_local::~MySQL_STMTs_local() {
// Note: we do not free the prepared statements because we assume that
// if we call this destructor the connection is being destroyed anyway
for (std::map<uint32_t, MYSQL_STMT *>::iterator it = m.begin();
it != m.end(); ++it) {
uint32_t stmt_id = it->first;
MYSQL_STMT *stmt = it->second;
if (stmt) { // is a server
if (stmt->mysql) {
stmt->mysql->stmts =
list_delete(stmt->mysql->stmts, &stmt->list);
}
// we do a hack here: we pretend there is no server associate
// the connection will be dropped anyway immediately after
stmt->mysql = NULL;
mysql_stmt_close(stmt);
GloMyStmt->ref_count(stmt_id, -1, true, false);
} else { // is a client
GloMyStmt->ref_count(stmt_id, -1, true, true);
}
}
m.erase(m.begin(), m.end());
}
uint32_t MySQL_STMTs_local::generate_new_stmt_id(uint32_t global_statement_id) {
uint32_t new_id;
new_id = GloMyStmt->generate_new_stmt_id();
client_stmt_to_global_id.insert(std::make_pair(global_statement_id, new_id));
return new_id;
}
uint32_t MySQL_STMTs_local::find_original_id(uint32_t client_stmt_id) {
auto s = client_stmt_to_global_id.find(client_stmt_id);
if (s != client_stmt_to_global_id.end()) {
uint32_t ret=s->second;
return ret;
}
return 0;
}
bool MySQL_STMTs_local::erase(uint32_t global_statement_id) {
auto s = m.find(global_statement_id);
if (s != m.end()) { // found
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);
m.erase(s);
num_entries--;
return true; // we truly removed the prepared statement
}
}
return false; // we don't really remove the prepared statement
}
void MySQL_STMTs_local::insert(uint32_t global_statement_id, MYSQL_STMT *stmt) {
std::pair<std::map<uint32_t, MYSQL_STMT *>::iterator, bool> ret;
ret = m.insert(std::make_pair(global_statement_id, stmt));
if (ret.second == true) {
num_entries++;
}
if (stmt == NULL) { // only for clients
GloMyStmt->ref_count(global_statement_id, 1, true, true);
}
}
MySQL_STMT_Manager::MySQL_STMT_Manager() {
spinlock_rwlock_init(&rwlock);
next_statement_id =
33; // we initialize this as 33, leaving the first 32 reserved for special prepared statements (future use)
}
MySQL_STMT_Manager::~MySQL_STMT_Manager() {
for (std::map<uint32_t, MySQL_STMT_Global_info *>::iterator it = m.begin();
it != m.end(); ++it) {
MySQL_STMT_Global_info *a = it->second;
delete a;
}
m.erase(m.begin(), m.end());
// we do not loop in h because all the MySQL_STMT_Global_info() were already
// deleted
h.erase(h.begin(), h.end());
}
void MySQL_STMT_Manager::active_prepared_statements(uint32_t *unique,
uint32_t *total) {
uint32_t u = 0;
uint32_t t = 0;
spin_wrlock(&rwlock);
// fprintf(stderr,"%u , %u , %u , %u\n",
// find_prepared_statement_by_hash_calls, add_prepared_statement_calls,
// m.size(), total_prepared_statements());
for (std::map<uint32_t, MySQL_STMT_Global_info *>::iterator it = m.begin();
it != m.end(); ++it) {
MySQL_STMT_Global_info *a = it->second;
if (a->ref_count_client) {
u++;
t += a->ref_count_client;
#ifdef DEBUG
fprintf(stderr, "stmt %d , client_ref_count %d\n", a->statement_id,
a->ref_count_client);
#endif
}
}
spin_wrunlock(&rwlock);
*unique = u;
*total = t;
}
int MySQL_STMT_Manager::ref_count(uint32_t statement_id, int cnt, bool lock,
bool is_client) {
int ret = -1;
if (lock) {
spin_wrlock(&rwlock);
}
auto s = m.find(statement_id);
if (s != m.end()) {
MySQL_STMT_Global_info *a = s->second;
if (is_client) {
ret = __sync_add_and_fetch(&a->ref_count_client, cnt);
//__sync_fetch_and_add(&a->ref_count_client,cnt);
// ret=a->ref_count_client;
if (m.size() > (unsigned)mysql_thread___max_stmts_cache) {
int max_purge = m.size() / 20; // purge up to 5%
int i = -1;
uint32_t *torem =
(uint32_t *)malloc(max_purge * sizeof(uint32_t));
for (std::map<uint32_t, MySQL_STMT_Global_info *>::iterator it =
m.begin();
it != m.end(); ++it) {
if (i == (max_purge - 1)) continue;
MySQL_STMT_Global_info *a = it->second;
if (__sync_add_and_fetch(&a->ref_count_client, 0) == 0) {
uint64_t hash = a->hash;
auto s2 = h.find(hash);
if (s2 != h.end()) {
h.erase(s2);
}
// m.erase(it);
// delete a;
i++;
torem[i] = it->first;
}
}
while (i >= 0) {
uint32_t id = torem[i];
auto s3 = m.find(id);
MySQL_STMT_Global_info *a = s3->second;
if (a->ref_count_server == 0) {
free_stmt_ids.push(id);
}
m.erase(s3);
delete a;
i--;
}
free(torem);
}
} else {
__sync_fetch_and_add(&a->ref_count_server, cnt);
ret = a->ref_count_server;
}
}
if (lock) {
spin_wrunlock(&rwlock);
}
return ret;
}
MySQL_STMT_Global_info *MySQL_STMT_Manager::add_prepared_statement(
bool *is_new, unsigned int _h, char *u, char *s, char *q, unsigned int ql,
MYSQL_STMT *stmt, bool lock) {
return add_prepared_statement(is_new, _h, u, s, q, ql, stmt, -1, -1, -1,
lock);
}
MySQL_STMT_Global_info *MySQL_STMT_Manager::add_prepared_statement(
bool *is_new, unsigned int _h, char *u, char *s, char *q, unsigned int ql,
MYSQL_STMT *stmt, int _cache_ttl, int _timeout, int _delay, bool lock) {
MySQL_STMT_Global_info *ret = NULL;
uint64_t hash = stmt_compute_hash(
_h, u, s, q, ql); // this identifies the prepared statement
if (lock) {
spin_wrlock(&rwlock);
}
// try to find the statement
auto f = h.find(hash);
if (f != h.end()) {
// found it!
// MySQL_STMT_Global_info *a=f->second;
// ret=a->statement_id;
ret = f->second;
*is_new = false;
} else {
// we need to create a new one
bool free_id_avail = false;
free_id_avail = free_stmt_ids.size();
uint32_t next_id = 0;
if (free_id_avail) {
next_id = free_stmt_ids.top();
free_stmt_ids.pop();
} else {
// next_id = next_statement_id;
// next_statement_id++;
__sync_fetch_and_add(&next_statement_id, 1);
}
MySQL_STMT_Global_info *a =
new MySQL_STMT_Global_info(next_id, _h, u, s, q, ql, stmt, hash);
a->properties.cache_ttl = _cache_ttl;
a->properties.timeout = _timeout;
a->properties.delay = _delay;
// insert it in both maps
m.insert(std::make_pair(a->statement_id, a));
h.insert(std::make_pair(a->hash, a));
// ret=a->statement_id;
ret = a;
// next_statement_id++; // increment it
//__sync_fetch_and_add(&ret->ref_count_client,1); // increase reference
//count
__sync_fetch_and_add(&ret->ref_count_client,
1); // increase reference count
*is_new = true;
}
__sync_fetch_and_add(&add_prepared_statement_calls, 1);
__sync_fetch_and_add(&ret->ref_count_server,
1); // increase reference count
if (lock) {
spin_wrunlock(&rwlock);
}
return ret;
}
MySQL_STMT_Global_info *MySQL_STMT_Manager::find_prepared_statement_by_stmt_id(
uint32_t id, bool lock) {
MySQL_STMT_Global_info *ret = NULL; // assume we do not find it
if (lock) {
spin_wrlock(&rwlock);
}
auto s = m.find(id);
if (s != m.end()) {
ret = s->second;
//__sync_fetch_and_add(&ret->ref_count,1); // increase reference count
}
if (lock) {
spin_wrunlock(&rwlock);
}
return ret;
}
MySQL_STMT_Global_info *MySQL_STMT_Manager::find_prepared_statement_by_hash(
uint64_t hash, bool lock) {
MySQL_STMT_Global_info *ret = NULL; // assume we do not find it
if (lock) {
spin_wrlock(&rwlock);
}
auto s = h.find(hash);
if (s != h.end()) {
ret = s->second;
//__sync_fetch_and_add(&ret->ref_count_client,1); // increase reference
//count
__sync_fetch_and_add(&find_prepared_statement_by_hash_calls, 1);
__sync_fetch_and_add(&ret->ref_count_client, 1);
}
if (lock) {
spin_wrunlock(&rwlock);
}
return ret;
}
#else // PROXYSQL_STMT_V14
*/
extern MySQL_STMT_Manager_v14 *GloMyStmt;
void MySQL_STMTs_local_v14::backend_insert(uint64_t global_statement_id, MYSQL_STMT *stmt) {
@ -1106,8 +806,6 @@ void MySQL_STMT_Manager_v14::get_metrics(uint64_t *c_unique, uint64_t *c_total,
*s_total = s_t;
}
//#endif // PROXYSQL_STMT_V14
class PS_global_stats {
public:

Просмотреть файл

@ -21,11 +21,7 @@ extern CHARSET_INFO * proxysql_find_charset_collate_names(const char *csname, co
extern MySQL_Authentication *GloMyAuth;
extern ProxySQL_Admin *GloAdmin;
extern MySQL_Logger *GloMyLogger;
#ifndef PROXYSQL_STMT_V14
extern MySQL_STMT_Manager *GloMyStmt;
#else
extern MySQL_STMT_Manager_v14 *GloMyStmt;
#endif
extern SQLite3_Server *GloSQLite3Server;
@ -1684,11 +1680,7 @@ bool MySQL_Session::handler_again___status_CHANGING_USER_SERVER(int *_rc) {
}
// we recreate local_stmts : see issue #752
delete myconn->local_stmts;
#ifndef PROXYSQL_STMT_V14
myconn->local_stmts=new MySQL_STMTs_local(false); // false by default, it is a backend
#else
myconn->local_stmts=new MySQL_STMTs_local_v14(false); // false by default, it is a backend
#endif
int rc=myconn->async_change_user(myds->revents);
if (rc==0) {
__sync_fetch_and_add(&MyHGM->status.backend_change_user, 1);
@ -2115,21 +2107,12 @@ __get_pkts_from_client:
break;
case _MYSQL_COM_STMT_CLOSE:
{
#ifndef PROXYSQL_STMT_V14
uint32_t stmt_global_id=0;
memcpy(&stmt_global_id,(char *)pkt.ptr+5,sizeof(uint32_t));
// FIXME: no input validation
SLDH->reset(stmt_global_id);
sess_STMTs_meta->erase(stmt_global_id);
client_myds->myconn->local_stmts->erase(stmt_global_id);
#else
uint32_t client_global_id=0;
memcpy(&client_global_id,(char *)pkt.ptr+5,sizeof(uint32_t));
// FIXME: no input validation
SLDH->reset(client_global_id);
sess_STMTs_meta->erase(client_global_id);
client_myds->myconn->local_stmts->client_close(client_global_id);
#endif
}
l_free(pkt.size,pkt.ptr);
// FIXME: this is not complete. Counters should be decreased
@ -2178,48 +2161,10 @@ __get_pkts_from_client:
break;
}
if (client_myds->myconn->local_stmts==NULL) {
#ifndef PROXYSQL_STMT_V14
client_myds->myconn->local_stmts=new MySQL_STMTs_local(true);
#else
client_myds->myconn->local_stmts=new MySQL_STMTs_local_v14(true);
#endif
}
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;
#ifndef PROXYSQL_STMT_V14
stmt_info=GloMyStmt->find_prepared_statement_by_hash(hash); // find_prepared_statement_by_hash() always increase ref_count_client
if (stmt_info) {
// FIXME: there is a very interesting race condition here
// FIXME: it is possible that multiple statement have the same hash
// FIXME: we should check local_stmts to verify is this stmt_id was already sent
if (client_myds->myconn->local_stmts->exists(stmt_info->statement_id)) {
// the client is asking to prepare another identical prepared statements
__sync_fetch_and_sub(&stmt_info->ref_count_client,1); // since find_prepared_statement_by_hash() already increased red_count_client we decrease it here
stmt_info=NULL;
}
}
if (stmt_info) {
l_free(pkt.size,pkt.ptr);
client_myds->setDSS_STATE_QUERY_SENT_NET();
client_myds->myprot.generate_STMT_PREPARE_RESPONSE(client_myds->pkt_sid+1,stmt_info);
client_myds->myconn->local_stmts->insert(stmt_info->statement_id,NULL);
__sync_fetch_and_sub(&stmt_info->ref_count_client,1); // since find_prepared_statement_by_hash() already increased red_count_client before insert(), we decrease it here
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
CurrentQuery.end_time=thread->curtime;
CurrentQuery.end();
break;
} else {
mybe=find_or_create_backend(current_hostgroup);
status=PROCESSING_STMT_PREPARE;
mybe->server_myds->connect_retries_on_failure=mysql_thread___connect_retries_on_failure;
mybe->server_myds->wait_until=0;
pause_until=0;
mybe->server_myds->killed_at=0;
mybe->server_myds->mysql_real_query.init(&pkt); // fix memory leak for PREPARE in prepared statements #796
client_myds->setDSS_STATE_QUERY_SENT_NET();
}
#else // PROXYSQL_STMT_V14
// we first lock GloStmt
GloMyStmt->wrlock();
stmt_info=GloMyStmt->find_prepared_statement_by_hash(hash,false);
@ -2247,7 +2192,6 @@ __get_pkts_from_client:
}
GloMyStmt->unlock();
break; // make sure to not break before unlocking GloMyStmt
#endif // PROXYSQL_STMT_V14
}
break;
case _MYSQL_COM_STMT_EXECUTE:
@ -2264,14 +2208,6 @@ __get_pkts_from_client:
thread->status_variables.queries++;
//bool rc_break=false;
#ifndef PROXYSQL_STMT_V14
uint32_t stmt_global_id=0;
memcpy(&stmt_global_id,(char *)pkt.ptr+5,sizeof(uint32_t));
CurrentQuery.stmt_global_id=stmt_global_id;
// now we get the statement information
MySQL_STMT_Global_info *stmt_info=NULL;
stmt_info=GloMyStmt->find_prepared_statement_by_stmt_id(stmt_global_id);
#else
uint32_t client_stmt_id=0;
uint64_t stmt_global_id=0;
memcpy(&client_stmt_id,(char *)pkt.ptr+5,sizeof(uint32_t));
@ -2284,7 +2220,6 @@ __get_pkts_from_client:
// now we get the statement information
MySQL_STMT_Global_info *stmt_info=NULL;
stmt_info=GloMyStmt->find_prepared_statement_by_stmt_id(stmt_global_id);
#endif
if (stmt_info==NULL) {
// we couldn't find it
l_free(pkt.size,pkt.ptr);
@ -2554,11 +2489,7 @@ handler_again:
goto handler_again;
}
if (status==PROCESSING_STMT_EXECUTE) {
#ifndef PROXYSQL_STMT_V14
CurrentQuery.mysql_stmt=myconn->local_stmts->find(CurrentQuery.stmt_global_id);
#else
CurrentQuery.mysql_stmt=myconn->local_stmts->find_backend_stmt_by_global_id(CurrentQuery.stmt_global_id);
#endif
if (CurrentQuery.mysql_stmt==NULL) {
MySQL_STMT_Global_info *stmt_info=NULL;
// the conection we too doesn't have the prepared statements prepared
@ -2639,26 +2570,10 @@ handler_again:
{
thread->status_variables.backend_stmt_prepare++;
GloMyStmt->wrlock();
#ifndef PROXYSQL_STMT_V14
uint32_t stmid;
#else
uint32_t client_stmtid;
uint64_t global_stmtid;
#endif
//bool is_new;
MySQL_STMT_Global_info *stmt_info=NULL;
#ifndef PROXYSQL_STMT_V14
stmt_info=GloMyStmt->add_prepared_statement(&is_new, current_hostgroup,
(char *)client_myds->myconn->userinfo->username,
(char *)client_myds->myconn->userinfo->schemaname,
(char *)CurrentQuery.QueryPointer,
CurrentQuery.QueryLength,
CurrentQuery.mysql_stmt,
qpo->cache_ttl,
qpo->timeout,
qpo->delay,
true);
#else
stmt_info=GloMyStmt->add_prepared_statement(current_hostgroup,
(char *)client_myds->myconn->userinfo->username,
(char *)client_myds->myconn->userinfo->schemaname,
@ -2669,7 +2584,6 @@ handler_again:
qpo->timeout,
qpo->delay,
false);
#endif
if (CurrentQuery.QueryParserArgs.digest_text) {
if (stmt_info->digest_text==NULL) {
stmt_info->digest_text=strdup(CurrentQuery.QueryParserArgs.digest_text);
@ -2677,15 +2591,10 @@ handler_again:
stmt_info->MyComQueryCmd=CurrentQuery.MyComQueryCmd; // copy MyComQueryCmd
}
}
#ifndef PROXYSQL_STMT_V14
stmid=stmt_info->statement_id;
myds->myconn->local_stmts->insert(stmid,CurrentQuery.mysql_stmt);
#else
global_stmtid=stmt_info->statement_id;
myds->myconn->local_stmts->backend_insert(global_stmtid,CurrentQuery.mysql_stmt);
if (previous_status.size() == 0)
client_stmtid=client_myds->myconn->local_stmts->generate_new_client_stmt_id(global_stmtid);
#endif
GloMyStmt->unlock();
CurrentQuery.mysql_stmt=NULL;
enum session_status st=status;
@ -2697,13 +2606,7 @@ handler_again:
previous_status.pop();
NEXT_IMMEDIATE(st);
} else {
#ifndef PROXYSQL_STMT_V14
client_myds->myprot.generate_STMT_PREPARE_RESPONSE(client_myds->pkt_sid+1,stmt_info);
client_myds->myconn->local_stmts->insert(stmt_info->statement_id,NULL);
if (is_new) __sync_fetch_and_sub(&stmt_info->ref_count_client,1);
#else
client_myds->myprot.generate_STMT_PREPARE_RESPONSE(client_myds->pkt_sid+1,stmt_info,client_stmtid);
#endif
}
}
break;

Просмотреть файл

@ -143,11 +143,7 @@ extern ProxySQL_Admin *GloAdmin;
extern Query_Processor *GloQPro;
extern MySQL_Threads_Handler *GloMTH;
extern MySQL_Logger *GloMyLogger;
#ifndef PROXYSQL_STMT_V14
extern MySQL_STMT_Manager *GloMyStmt;
#else
extern MySQL_STMT_Manager_v14 *GloMyStmt;
#endif
extern MySQL_Monitor *GloMyMon;
extern ProxySQL_Cluster *GloProxyCluster;
@ -5035,31 +5031,6 @@ void ProxySQL_Admin::stats___mysql_global() {
statsdb->execute(query);
free(query);
#ifndef PROXYSQL_STMT_V14
if (GloMyStmt) {
uint32_t stmt_active_unique=0;
uint32_t stmt_active_total=0;
GloMyStmt->active_prepared_statements(&stmt_active_unique,&stmt_active_total);
vn=(char *)"Stmt_Active_Total";
sprintf(bu,"%u",stmt_active_total);
query=(char *)malloc(strlen(a)+strlen(vn)+strlen(bu)+16);
sprintf(query,a,vn,bu);
statsdb->execute(query);
free(query);
vn=(char *)"Stmt_Active_Unique";
sprintf(bu,"%u",stmt_active_unique);
query=(char *)malloc(strlen(a)+strlen(vn)+strlen(bu)+16);
sprintf(query,a,vn,bu);
statsdb->execute(query);
free(query);
vn=(char *)"Stmt_Max_Stmt_id";
sprintf(bu,"%u",GloMyStmt->total_prepared_statements());
query=(char *)malloc(strlen(a)+strlen(vn)+strlen(bu)+16);
sprintf(query,a,vn,bu);
statsdb->execute(query);
free(query);
}
#else
if (GloMyStmt) {
uint64_t stmt_client_active_unique = 0;
uint64_t stmt_client_active_total = 0;
@ -5105,7 +5076,6 @@ void ProxySQL_Admin::stats___mysql_global() {
statsdb->execute(query);
free(query);
}
#endif
resultset=GloQC->SQL3_getStats();
if (resultset) {

Просмотреть файл

@ -191,11 +191,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);
#ifndef PROXYSQL_STMT_V14
local_stmts=new MySQL_STMTs_local(false); // false by default, it is a backend
#else
local_stmts=new MySQL_STMTs_local_v14(false); // false by default, it is a backend
#endif
};
MySQL_Connection::~MySQL_Connection() {
@ -1700,9 +1696,5 @@ void MySQL_Connection::reset() {
}
}
delete local_stmts;
#ifndef PROXYSQL_STMT_V14
local_stmts=new MySQL_STMTs_local(false);
#else
local_stmts=new MySQL_STMTs_local_v14(false);
#endif
}

Просмотреть файл

@ -201,11 +201,7 @@ Query_Processor *GloQPro;
ProxySQL_Admin *GloAdmin;
MySQL_Threads_Handler *GloMTH;
#ifndef PROXYSQL_STMT_V14
MySQL_STMT_Manager *GloMyStmt;
#else
MySQL_STMT_Manager_v14 *GloMyStmt;
#endif
MySQL_Monitor *GloMyMon;
std::thread *MyMon_thread = NULL;
@ -400,11 +396,7 @@ void ProxySQL_Main_init_main_modules() {
MyHGM=new MySQL_HostGroups_Manager();
GloMTH=new MySQL_Threads_Handler();
GloMyLogger = new MySQL_Logger();
#ifndef PROXYSQL_STMT_V14
GloMyStmt=new MySQL_STMT_Manager();
#else
GloMyStmt=new MySQL_STMT_Manager_v14();
#endif
}