Various code cleanup

pull/1847/head
René Cannaò 7 years ago
parent dc73e7bd5d
commit 10f38d4e2f

@ -8,7 +8,7 @@ using namespace libconfig;
class ProxySQL_ConfigFile {
private:
struct stat statbuf;
//struct stat statbuf;
char *filename;
public:
Config *cfg;

@ -135,7 +135,7 @@ void connect_cb(EV_P_ ev_io *w, int revents) {
if ((getsockopt(w->fd, SOL_SOCKET, SO_ERROR, &optval, &optlen) == -1) ||
(optval != 0)) {
/* Connection failed; try the next address in the list. */
int errnum = optval ? optval : errno;
//int errnum = optval ? optval : errno;
ev_io_stop(MyHGM->gtid_ev_loop, w);
close(w->fd);
MyHGM->gtid_missing_nodes = true;
@ -170,7 +170,7 @@ void connect_cb(EV_P_ ev_io *w, int revents) {
}
struct ev_io * new_connector(char *address, uint16_t gtid_port, uint16_t mysql_port) {
struct sockaddr_in a;
//struct sockaddr_in a;
int s;
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
@ -4321,7 +4321,7 @@ SQLite3_result * MySQL_HostGroups_Manager::get_stats_mysql_gtid_executed() {
//sprintf(buf,"%d", mysrvc->port);
string s1 = gtid_executed_to_string(gtid_si->gtid_executed);
pta[2]=strdup(s1.c_str());
sprintf(buf,"%llu", (int)gtid_si->events_read);
sprintf(buf,"%llu", gtid_si->events_read);
pta[3]=strdup(buf);
} else {
std::string s = it->first;

@ -62,7 +62,9 @@ class ConsumerThread : public Thread {
// Remove 1 item at a time and process it. Blocks if no items are
// available to process.
for (int i = 0; ( thrn ? i < thrn : 1) ; i++) {
VALGRIND_DISABLE_ERROR_REPORTING;
WorkItem* item = (WorkItem*)m_queue.remove();
VALGRIND_ENABLE_ERROR_REPORTING;
if (item==NULL) {
if (thrn) {
// we took a NULL item that wasn't meant to reach here! Add it again

@ -729,7 +729,7 @@ bool MySQL_STMTs_local_v14::client_close(uint32_t client_statement_id) {
uint64_t global_stmt_id = s->second;
client_stmt_to_global_ids.erase(s);
GloMyStmt->ref_count_client(global_stmt_id, -1);
auto s2 = global_stmt_to_client_ids.find(global_stmt_id);
//auto s2 = global_stmt_to_client_ids.find(global_stmt_id);
std::pair<std::multimap<uint64_t,uint32_t>::iterator, std::multimap<uint64_t,uint32_t>::iterator> ret;
ret = global_stmt_to_client_ids.equal_range(global_stmt_id);
for (std::multimap<uint64_t,uint32_t>::iterator it=ret.first; it!=ret.second; ++it) {
@ -816,12 +816,14 @@ MySQL_STMT_Global_info *MySQL_STMT_Manager_v14::add_prepared_statement(
void MySQL_STMT_Manager_v14::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) {
#ifdef DEBUG
uint64_t c_u = 0;
uint64_t c_t = 0;
uint64_t m = 0;
uint64_t c = 0;
uint64_t s_u = 0;
uint64_t s_t = 0;
#endif
pthread_rwlock_wrlock(&rwlock_);
statuses.cached = map_stmt_id_to_info.size();
statuses.c_unique = statuses.cached - num_stmt_with_ref_client_count_zero;
@ -897,7 +899,7 @@ class PS_global_stats {
char **get_row() {
char buf[128];
char **pta=(char **)malloc(sizeof(char *)*8);
sprintf(buf,"%llu",statement_id);
sprintf(buf,"%lu",statement_id);
pta[0]=strdup(buf);
sprintf(buf,"%u",hid);
pta[1]=strdup(buf);

@ -1273,7 +1273,7 @@ bool MySQL_Protocol::process_pkt_COM_CHANGE_USER(unsigned char *pkt, unsigned in
mysql_hdr hdr;
memcpy(&hdr,pkt,sizeof(mysql_hdr));
int default_hostgroup=-1;
bool transaction_persistent;
bool transaction_persistent = true;
bool _ret_use_ssl=false;
cur++;
user=pkt+cur;

@ -596,29 +596,30 @@ bool MySQL_Session::handler_CommitRollback(PtrSize_t *pkt) {
// FIXME: This function is currently disabled . See #469
bool MySQL_Session::handler_SetAutocommit(PtrSize_t *pkt) {
size_t sal=strlen("set autocommit");
char * _ptr = (char *)pkt->ptr;
if ( pkt->size >= 7+sal) {
if (strncasecmp((char *)"SET @@session.autocommit",(char *)pkt->ptr+5,strlen((char *)"SET @@session.autocommit"))==0) {
memmove(pkt->ptr+9, pkt->ptr+19, pkt->size - 19);
memset(pkt->ptr+pkt->size-10,' ',10);
memmove(_ptr+9, _ptr+19, pkt->size - 19);
memset(_ptr+pkt->size-10,' ',10);
}
if (strncasecmp((char *)"set autocommit",(char *)pkt->ptr+5,sal)==0) {
void *p = NULL;
for (int i=5+sal; i<pkt->size; i++) {
*((char *)pkt->ptr+i) = tolower(*((char *)pkt->ptr+i));
}
p = memmem(pkt->ptr+5+sal, pkt->size-5-sal, (void *)"false", 5);
p = memmem(_ptr+5+sal, pkt->size-5-sal, (void *)"false", 5);
if (p) {
memcpy(p,(void *)"0 ",5);
}
p = memmem(pkt->ptr+5+sal, pkt->size-5-sal, (void *)"true", 4);
p = memmem(_ptr+5+sal, pkt->size-5-sal, (void *)"true", 4);
if (p) {
memcpy(p,(void *)"1 ",4);
}
p = memmem(pkt->ptr+5+sal, pkt->size-5-sal, (void *)"off", 3);
p = memmem(_ptr+5+sal, pkt->size-5-sal, (void *)"off", 3);
if (p) {
memcpy(p,(void *)"0 ",3);
}
p = memmem(pkt->ptr+5+sal, pkt->size-5-sal, (void *)"on", 2);
p = memmem(_ptr+5+sal, pkt->size-5-sal, (void *)"on", 2);
if (p) {
memcpy(p,(void *)"1 ",2);
}
@ -4211,7 +4212,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
char buf2[32];
sprintf(buf,"%u",thread_session_id);
int l0=strlen("CONNECTION_ID()");
memcpy(buf2,pkt->ptr+5+SELECT_CONNECTION_ID_LEN-l0,l0);
memcpy(buf2,(char *)pkt->ptr+5+SELECT_CONNECTION_ID_LEN-l0,l0);
buf2[l0]=0;
unsigned int nTrx=NumActiveTransactions();
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
@ -4273,7 +4274,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
sprintf(buf,"%llu",last_insert_id);
char buf2[32];
int l0=strlen("LAST_INSERT_ID()");
memcpy(buf2,pkt->ptr+5+SELECT_LAST_INSERT_ID_LEN-l0,l0);
memcpy(buf2,(char *)pkt->ptr+5+SELECT_LAST_INSERT_ID_LEN-l0,l0);
buf2[l0]=0;
unsigned int nTrx=NumActiveTransactions();
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );

@ -2428,7 +2428,7 @@ void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) {
ProxySQL_Admin *pa=(ProxySQL_Admin *)_pa;
char *error=NULL;
int cols;
int affected_rows;
int affected_rows = 0;
bool run_query=true;
SQLite3_result *resultset=NULL;
char *strA=NULL;
@ -2460,7 +2460,7 @@ void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) {
// handle special queries from Cluster
// for bug #1188 , ProxySQL Admin needs to know the exact query
if (!strncasecmp(CLUSTER_QUERY_MYSQL_SERVERS, query_no_space, strlen(CLUSTER_QUERY_MYSQL_SERVERS))) {
ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa;
//ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa;
if (sess->session_type == PROXYSQL_SESSION_ADMIN) { // no stats
resultset=MyHGM->dump_table_mysql_servers();
if (resultset) {
@ -2472,7 +2472,7 @@ void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) {
}
}
if (!strncasecmp(CLUSTER_QUERY_MYSQL_REPLICATION_HOSTGROUPS, query_no_space, strlen(CLUSTER_QUERY_MYSQL_REPLICATION_HOSTGROUPS))) {
ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa;
//ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa;
if (sess->session_type == PROXYSQL_SESSION_ADMIN) { // no stats
resultset=MyHGM->dump_table_mysql_replication_hostgroups();
if (resultset) {
@ -2570,7 +2570,7 @@ void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) {
if ((query_no_space_length == strlen("SELECT GLOBAL_CHECKSUM()")) && (!strncasecmp("SELECT GLOBAL_CHECKSUM()", query_no_space, strlen("SELECT GLOBAL_CHECKSUM()")))) {
char buf[32];
pthread_mutex_lock(&GloVars.checksum_mutex);
sprintf(buf,"%llu",GloVars.checksums_values.global_checksum);
sprintf(buf,"%lu",GloVars.checksums_values.global_checksum);
pthread_mutex_unlock(&GloVars.checksum_mutex);
uint16_t setStatus = 0;
MySQL_Data_Stream *myds=sess->client_myds;
@ -4545,9 +4545,7 @@ void ProxySQL_Admin::flush_mysql_variables___runtime_to_database(SQLite3DB *db,
void ProxySQL_Admin::flush_ldap_variables___database_to_runtime(SQLite3DB *db, bool replace) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Flushing LDAP variables. Replace:%d\n", replace);
if (
( GloMyLdapAuth == NULL )
) {
if (GloMyLdapAuth == NULL) {
return;
}
char *error=NULL;
@ -5062,10 +5060,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub
if ((variables.mysql_ifaces==NULL) || strcasecmp(variables.mysql_ifaces,value) ) update_creds=true;
if (variables.mysql_ifaces)
free(variables.mysql_ifaces);
variables.mysql_ifaces=strdup(value);
if (update_creds && variables.mysql_ifaces) {
S_amll.update_ifaces(variables.mysql_ifaces, &S_amll.ifaces_mysql);
}
variables.mysql_ifaces=strdup(value);
if (update_creds && variables.mysql_ifaces) {
S_amll.update_ifaces(variables.mysql_ifaces, &S_amll.ifaces_mysql);
}
return true;
} else {
return false;
@ -5234,56 +5232,60 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub
}
}
if (!strcasecmp(name,"cluster_mysql_query_rules_save_to_disk")) {
bool rt = false;
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.cluster_mysql_query_rules_save_to_disk=true;
__sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_query_rules_save_to_disk, true);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_query_rules_save_to_disk, true);
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.cluster_mysql_query_rules_save_to_disk=false;
__sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_query_rules_save_to_disk, false);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_query_rules_save_to_disk, false);
return true;
}
return false;
return rt;
}
if (!strcasecmp(name,"cluster_mysql_servers_save_to_disk")) {
bool rt = false;
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.cluster_mysql_servers_save_to_disk=true;
__sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_servers_save_to_disk, true);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_servers_save_to_disk, true);
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.cluster_mysql_servers_save_to_disk=false;
__sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_servers_save_to_disk, false);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_servers_save_to_disk, false);
return true;
}
return false;
return rt;
}
if (!strcasecmp(name,"cluster_mysql_users_save_to_disk")) {
bool rt = false;
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.cluster_mysql_users_save_to_disk=true;
__sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_users_save_to_disk, true);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_users_save_to_disk, true);
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.cluster_mysql_users_save_to_disk=false;
__sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_users_save_to_disk, false);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_users_save_to_disk, false);
return true;
}
return false;
return rt;
}
if (!strcasecmp(name,"cluster_proxysql_servers_save_to_disk")) {
bool rt = false;
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.cluster_proxysql_servers_save_to_disk=true;
__sync_lock_test_and_set(&GloProxyCluster->cluster_proxysql_servers_save_to_disk, true);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_proxysql_servers_save_to_disk, true);
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.cluster_proxysql_servers_save_to_disk=false;
__sync_lock_test_and_set(&GloProxyCluster->cluster_proxysql_servers_save_to_disk, false);
rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_proxysql_servers_save_to_disk, false);
return true;
}
return false;
return rt;
}
if (!strcasecmp(name,"checksum_mysql_query_rules")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
@ -7280,7 +7282,6 @@ void ProxySQL_Admin::stats___mysql_users() {
}
void ProxySQL_Admin::stats___mysql_gtid_executed() {
int i;
statsdb->execute("DELETE FROM stats_mysql_gtid_executed");
SQLite3_result *resultset=NULL;
resultset = MyHGM->get_stats_mysql_gtid_executed();

@ -487,7 +487,6 @@ char *mysql_query_strip_comments(char *s, int _len) {
char *p_r_t = r;
char prev_char = 0;
char qutr_char = 0;
char flag = 0;

@ -807,7 +807,7 @@ int MySQL_Data_Stream::buffer2array() {
PSarrayIN->add(queueIN.pkt.ptr,queueIN.pkt.size);
} else {
// we append the packet at the end of the previous packet
memcpy(last_pkt->ptr+last_pkt->size, queue_r_ptr(queueIN) , queueIN.pkt.size);
memcpy((char *)last_pkt->ptr+last_pkt->size, queue_r_ptr(queueIN) , queueIN.pkt.size);
last_pkt->size += queueIN.pkt.size;
queue_r(queueIN, queueIN.pkt.size);

Loading…
Cancel
Save