From 61f0c4636bf42d2cd39ac2c1b802c8981dc6ba8c Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Mon, 7 Aug 2023 20:09:47 +0000 Subject: [PATCH 1/4] various warnings fixes --- lib/MySQL_HostGroups_Manager.cpp | 20 ++++++++++---------- lib/MySQL_Monitor.cpp | 1 - lib/MySQL_Session.cpp | 6 +++--- lib/Query_Processor.cpp | 1 - src/SQLite3_Server.cpp | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 0d00650ce5..3627903140 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -410,12 +410,12 @@ bool GTID_Server_Data::read_next_gtid() { } else { strncpy(rec_msg,data+pos,l); pos += l+1; - rec_msg[l]=0; + rec_msg[l] = 0; //int rc = write(1,data+pos,l+1); //fprintf(stdout,"%s\n", rec_msg); if (rec_msg[0]=='I') { //char rec_uuid[80]; - uint64_t rec_trxid; + uint64_t rec_trxid = 0; char *a = NULL; int ul = 0; switch (rec_msg[1]) { @@ -1768,7 +1768,7 @@ bool MySQL_HostGroups_Manager::commit( } if (atoi(r->fields[7])!=atoi(r->fields[17])) { if (GloMTH->variables.hostgroup_manager_verbose) - proxy_info("Changing max_connections for server %d:%s:%d (%s:%d) from %d (%d) to %d\n" , mysrvc->myhgc->hid , mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[7]) , mysrvc->max_connections , atoi(r->fields[17])); + proxy_info("Changing max_connections for server %d:%s:%d (%s:%d) from %d (%ld) to %d\n" , mysrvc->myhgc->hid , mysrvc->address, mysrvc->port, r->fields[1], atoi(r->fields[2]), atoi(r->fields[7]) , mysrvc->max_connections , atoi(r->fields[17])); mysrvc->max_connections=atoi(r->fields[17]); } if (atoi(r->fields[8])!=atoi(r->fields[18])) { @@ -2234,7 +2234,7 @@ void MySQL_HostGroups_Manager::generate_mysql_servers_table(int *_onlyhg) { st=(char *)"SHUNNED"; break; } - fprintf(stderr,"HID: %d , address: %s , port: %d , gtid_port: %d , weight: %d , status: %s , max_connections: %u , max_replication_lag: %u , use_ssl: %u , max_latency_ms: %u , comment: %s\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, mysrvc->gtid_port, mysrvc->weight, st, mysrvc->max_connections, mysrvc->max_replication_lag, mysrvc->use_ssl, mysrvc->max_latency_us*1000, mysrvc->comment); + fprintf(stderr,"HID: %d , address: %s , port: %d , gtid_port: %d , weight: %ld , status: %s , max_connections: %ld , max_replication_lag: %u , use_ssl: %u , max_latency_ms: %u , comment: %s\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port, mysrvc->gtid_port, mysrvc->weight, st, mysrvc->max_connections, mysrvc->max_replication_lag, mysrvc->use_ssl, mysrvc->max_latency_us*1000, mysrvc->comment); } lst->add(mysrvc); if (lst->len==32) { @@ -6920,7 +6920,7 @@ T j_get_srv_default_int_val( proxy_error( "Invalid type '%s'(%hhu) supplied for 'mysql_hostgroup_attributes.servers_defaults.%s' for hostgroup %d." " Value NOT UPDATED.\n", - type_name, val_type, key.c_str(), hid + type_name, (int) val_type, key.c_str(), hid ); } } @@ -7561,7 +7561,7 @@ void MySQL_HostGroups_Manager::update_aws_aurora_set_writer(int _whid, int _rhid if (mysrvc->max_connections > max_max_connections) { max_max_connections = mysrvc->max_connections; } - if (mysrvc->use_ssl > max_use_ssl) { + if (mysrvc->use_ssl > (int32_t) max_use_ssl) { max_use_ssl = mysrvc->use_ssl; } } @@ -7708,7 +7708,7 @@ void MySQL_HostGroups_Manager::update_aws_aurora_set_reader(int _whid, int _rhid if (mysrvc->max_connections > max_max_connections) { max_max_connections = mysrvc->max_connections; } - if (mysrvc->use_ssl > max_use_ssl) { + if (mysrvc->use_ssl > (int32_t) max_use_ssl) { max_use_ssl = mysrvc->use_ssl; } if (strcmp(mysrvc->address,full_hostname)==0 && mysrvc->port==aurora_port) { @@ -7908,7 +7908,7 @@ MySrvC* MySQL_HostGroups_Manager::HostGroup_Server_Mapping::insert_HGM(unsigned proxy_info( "Found server node in Host Group Container %s:%d as 'OFFLINE_HARD', setting back as 'ONLINE' with:" " hostgroup_id=%d, gtid_port=%d, weight=%ld, compression=%d, max_connections=%ld, use_ssl=%d," - " max_replication_lag=%ld, max_latency_ms=%ld, comment=%s\n", + " max_replication_lag=%d, max_latency_ms=%d, comment=%s\n", mysrvc->address, mysrvc->port, hostgroup_id, mysrvc->gtid_port, mysrvc->weight, mysrvc->compression, mysrvc->max_connections, mysrvc->use_ssl, mysrvc->max_replication_lag, (mysrvc->max_latency_us / 1000), mysrvc->comment @@ -7922,10 +7922,10 @@ MySrvC* MySQL_HostGroups_Manager::HostGroup_Server_Mapping::insert_HGM(unsigned if (!ret_srv) { if (GloMTH->variables.hostgroup_manager_verbose) { - proxy_info("Creating new server in HG %d : %s:%d , gtid_port=%d, weight=%d, status=%d\n", hostgroup_id, srv->address, srv->port, srv->gtid_port, srv->weight, srv->status); + proxy_info("Creating new server in HG %d : %s:%d , gtid_port=%d, weight=%ld, status=%d\n", hostgroup_id, srv->address, srv->port, srv->gtid_port, srv->weight, srv->status); } - proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 5, "Adding new server %s:%d , weight=%d, status=%d, mem_ptr=%p into hostgroup=%d\n", srv->address, srv->port, srv->weight, srv->status, srv, hostgroup_id); + proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 5, "Adding new server %s:%d , weight=%ld, status=%d, mem_ptr=%p into hostgroup=%d\n", srv->address, srv->port, srv->weight, srv->status, srv, hostgroup_id); ret_srv = new MySrvC(srv->address, srv->port, srv->gtid_port, srv->weight, srv->status, srv->compression, srv->max_connections, srv->max_replication_lag, srv->use_ssl, (srv->max_latency_us / 1000), srv->comment); diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 8afc846150..0bd5de67f0 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -3572,7 +3572,6 @@ gr_node_info_t gr_update_hosts_map( // NOTE: This isn't specified in the initializer list due to current standard limitations gr_node_info_t node_info {}; node_info.srv_st = gr_srv_st; - MySQL_Monitor_State_Data_Task_Result task_result = mmsd->get_task_result(); // Consider 'time_now' to be 'now - fetch_duration' unsigned long long time_now=realtime_time(); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index b65cc171c6..bea422e6fd 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -923,7 +923,7 @@ bool MySQL_Session::handler_CommitRollback(PtrSize_t *pkt) { // specific connection, for that, we update 'current_hostgroup' with the first active transaction we are // able to find. If more transactions are simultaneously open for the session, more 'COMMIT|ROLLBACK' // commands are required to be issued by the client to continue ending transactions. - unsigned int hg = FindOneActiveTransaction(true); + int hg = FindOneActiveTransaction(true); if (hg != -1) { // there is an active transaction, we must forward the request current_hostgroup = hg; @@ -4739,8 +4739,8 @@ int MySQL_Session::handler() { bool wrong_pass=false; if (to_process==0) return 0; // this should be redundant if the called does the same check proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p -- Processing session %p\n" , this->thread, this, this); - PtrSize_t pkt; - pktH=&pkt; + pktH = new PtrSize_t(); + PtrSize_t pkt = *pktH; //unsigned int j; //unsigned char c; diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp index fbe289da26..768dcc45d9 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -1163,7 +1163,6 @@ unsigned long long Query_Processor::purge_query_digests_async(char **msg) { digest_umap.swap(digest_umap_aux); digest_text_umap.swap(digest_text_umap_aux); pthread_rwlock_unlock(&digest_rwlock); - int num_rows = 0; unsigned long long curtime1=monotonic_time(); size_t map1_size = digest_umap_aux.size(); size_t map2_size = digest_text_umap_aux.size(); diff --git a/src/SQLite3_Server.cpp b/src/SQLite3_Server.cpp index c7e72aa013..44566aa5b7 100644 --- a/src/SQLite3_Server.cpp +++ b/src/SQLite3_Server.cpp @@ -1091,7 +1091,7 @@ static void * sqlite3server_main_loop(void *arg) if ( pthread_create(&child, &attr, child_func[callback_func[i]], client) != 0 ) perror("Thread creation"); } else { - proxy_error("accept() error:\n", strerror(errno)); + proxy_error("accept() error: %s\n", strerror(errno)); } } fds[i].revents=0; From 917154bf93ea606332686811070133c5eab57634 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Tue, 8 Aug 2023 07:38:59 +0000 Subject: [PATCH 2/4] fix pktH init/destructor --- lib/MySQL_Session.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index bea422e6fd..7370a7c437 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -589,6 +589,8 @@ MySQL_Session::MySQL_Session() { mirrorPkt.size=0; set_status(session_status___NONE); + pktH = NULL; + idle_since = 0; transaction_started_at = 0; @@ -730,6 +732,9 @@ MySQL_Session::~MySQL_Session() { delete proxysql_node_address; proxysql_node_address = NULL; } + if (pktH) { + delete pktH; + } } From b1dc534757a9c81148d8c6ab6d1598c652150ecb Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Tue, 8 Aug 2023 09:49:14 +0000 Subject: [PATCH 3/4] refactor out pktH --- include/MySQL_Session.h | 3 ++- lib/MySQL_Logger.cpp | 2 +- lib/MySQL_Session.cpp | 13 +++---------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index c5a8023409..95d22b1527 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -220,6 +220,7 @@ class MySQL_Session Query_Info CurrentQuery; PtrSize_t mirrorPkt; + PtrSize_t pkt; // uint64_t unsigned long long start_time; @@ -247,7 +248,7 @@ class MySQL_Session //this pointer is always initialized inside handler(). // it is an attempt to start simplifying the complexing of handler() - PtrSize_t *pktH; +// PtrSize_t *pktH; uint32_t thread_session_id; unsigned long long last_insert_id; diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index fc56fce6bb..6dd183846c 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -705,7 +705,7 @@ void MySQL_Logger::log_request(MySQL_Session *sess, MySQL_Data_Stream *myds) { break; case WAITING_CLIENT_DATA: { - unsigned char c=*((unsigned char *)sess->pktH->ptr+sizeof(mysql_hdr)); + unsigned char c=*((unsigned char *)sess->pkt.ptr+sizeof(mysql_hdr)); switch ((enum_mysql_command)c) { case _MYSQL_COM_STMT_PREPARE: // proxysql is responding to COM_STMT_PREPARE without diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 7370a7c437..4abfcb2252 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -589,8 +589,6 @@ MySQL_Session::MySQL_Session() { mirrorPkt.size=0; set_status(session_status___NONE); - pktH = NULL; - idle_since = 0; transaction_started_at = 0; @@ -732,9 +730,6 @@ MySQL_Session::~MySQL_Session() { delete proxysql_node_address; proxysql_node_address = NULL; } - if (pktH) { - delete pktH; - } } @@ -1589,7 +1584,7 @@ bool MySQL_Session::handler_special_queries(PtrSize_t *pkt) { } void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___create_mirror_session() { - if (pktH->size < 15*1024*1024 && (qpo->mirror_hostgroup >= 0 || qpo->mirror_flagOUT >= 0)) { + if (pkt.size < 15*1024*1024 && (qpo->mirror_hostgroup >= 0 || qpo->mirror_flagOUT >= 0)) { // check if there are too many mirror sessions in queue if (thread->mirror_queue_mysql_sessions->len >= (unsigned int)mysql_thread___mirror_max_queue_length) { return; @@ -1638,9 +1633,9 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C newsess->default_schema=strdup(default_schema); } } - newsess->mirrorPkt.size=pktH->size; + newsess->mirrorPkt.size=pkt.size; newsess->mirrorPkt.ptr=l_alloc(newsess->mirrorPkt.size); - memcpy(newsess->mirrorPkt.ptr,pktH->ptr,pktH->size); + memcpy(newsess->mirrorPkt.ptr,pkt.ptr,pkt.size); if (thread->mirror_queue_mysql_sessions->len==0) { // there are no sessions in the queue, we try to execute immediately @@ -4744,8 +4739,6 @@ int MySQL_Session::handler() { bool wrong_pass=false; if (to_process==0) return 0; // this should be redundant if the called does the same check proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p -- Processing session %p\n" , this->thread, this, this); - pktH = new PtrSize_t(); - PtrSize_t pkt = *pktH; //unsigned int j; //unsigned char c; From 4ffb96bf003a184f08908c0f9dbed42038a01e7d Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 11 Aug 2023 08:46:14 +0200 Subject: [PATCH 4/4] remove dead code --- include/MySQL_Session.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 95d22b1527..7adaa4b044 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -248,7 +248,6 @@ class MySQL_Session //this pointer is always initialized inside handler(). // it is an attempt to start simplifying the complexing of handler() -// PtrSize_t *pktH; uint32_t thread_session_id; unsigned long long last_insert_id;