Bug #62262 LOCK_bytes_sent, LOCK_bytes_received unused
Submitted: 25 Aug 2011 19:51 Modified: 26 Aug 2011 7:24
Reporter: Justin Tolmer Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Locking Severity:S3 (Non-critical)
Version:5.1.58 OS:Any
Assigned to: Marc ALFF CPU Architecture:Any
Tags: Contribution

[25 Aug 2011 19:51] Justin Tolmer
Description:
2 mutexes, LOCK_bytes_sent and LOCK_bytes_received are declared, initialized and destroyed but never used.

How to repeat:
In the root directory of the MySQL source code:

$ grep -r LOCK_bytes_sent *
sql/net_serv.cc:extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
sql/mysql_priv.h:       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
sql/mysqld.cc:		LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received,
sql/mysqld.cc:  (void) pthread_mutex_destroy(&LOCK_bytes_sent);
sql/mysqld.cc:  (void) pthread_mutex_init(&LOCK_bytes_sent,MY_MUTEX_INIT_FAST);

$ grep -r LOCK_bytes_received *
sql/net_serv.cc:extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
sql/mysql_priv.h:       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
sql/mysqld.cc:		LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received,
sql/mysqld.cc:  (void) pthread_mutex_destroy(&LOCK_bytes_received);
sql/mysqld.cc:  (void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST);

Note the lack of any pthread_mutext_[un]lock calls in the results

Suggested fix:
Apply this diff:

=== modified file 'client/mysqlbinlog.cc'
--- client/mysqlbinlog.cc	2011-05-05 22:48:15 +0000
+++ client/mysqlbinlog.cc	2011-08-25 19:49:27 +0000
@@ -45,9 +45,6 @@
 char server_version[SERVER_VERSION_LENGTH];
 ulong server_id = 0;
 
-// needed by net_serv.c
-ulong bytes_sent = 0L, bytes_received = 0L;
-ulong mysqld_net_retry_count = 10L;
 ulong open_files_limit;
 uint test_flags = 0; 
 static uint opt_protocol= 0;
@@ -2137,4 +2134,3 @@
 #include "my_decimal.cc"
 #include "log_event.cc"
 #include "log_event_old.cc"
-

=== modified file 'sql/mysql_priv.h'
--- sql/mysql_priv.h	2011-06-06 13:53:46 +0000
+++ sql/mysql_priv.h	2011-08-25 19:49:27 +0000
@@ -2031,7 +2031,7 @@
        LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
        LOCK_global_system_variables, LOCK_user_conn,
        LOCK_prepared_stmt_count,
-       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
+       LOCK_connection_count;
 extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count;
 #ifdef HAVE_OPENSSL
 extern pthread_mutex_t LOCK_des_key_file;

=== modified file 'sql/mysqld.cc'
--- sql/mysqld.cc	2011-06-06 13:53:46 +0000
+++ sql/mysqld.cc	2011-08-25 19:49:27 +0000
@@ -683,7 +683,7 @@
 		LOCK_mapped_file, LOCK_status, LOCK_global_read_lock,
 		LOCK_error_log, LOCK_uuid_generator,
 		LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
-		LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received,
+		LOCK_crypt,
 	        LOCK_global_system_variables,
 		LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
                 LOCK_connection_count;
@@ -1457,8 +1457,6 @@
   (void) pthread_mutex_destroy(&LOCK_delayed_create);
   (void) pthread_mutex_destroy(&LOCK_manager);
   (void) pthread_mutex_destroy(&LOCK_crypt);
-  (void) pthread_mutex_destroy(&LOCK_bytes_sent);
-  (void) pthread_mutex_destroy(&LOCK_bytes_received);
   (void) pthread_mutex_destroy(&LOCK_user_conn);
   (void) pthread_mutex_destroy(&LOCK_connection_count);
   Events::destroy_mutexes();
@@ -3635,8 +3633,6 @@
   (void) pthread_mutex_init(&LOCK_delayed_create,MY_MUTEX_INIT_SLOW);
   (void) pthread_mutex_init(&LOCK_manager,MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_crypt,MY_MUTEX_INIT_FAST);
-  (void) pthread_mutex_init(&LOCK_bytes_sent,MY_MUTEX_INIT_FAST);
-  (void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);

=== modified file 'sql/net_serv.cc'
--- sql/net_serv.cc	2011-01-25 14:42:40 +0000
+++ sql/net_serv.cc	2011-08-25 19:49:27 +0000
@@ -85,8 +85,6 @@
   live with this for a while.
 */
 extern uint test_flags;
-extern ulong bytes_sent, bytes_received, net_big_packet_count;
-extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
 #ifndef MYSQL_INSTANCE_MANAGER
 #ifdef HAVE_QUERY_CACHE
 #define USE_QUERY_CACHE
[26 Aug 2011 3:23] Valeriy Kravchuk
Verified just as described:

macbook-pro:mysql-5.1 openxs$ grep -r LOCK_bytes_sent *
client/mysql_priv.h:       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
sql/mysql_priv.h:       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
sql/mysqld.cc:		LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received,
sql/mysqld.cc:  (void) pthread_mutex_destroy(&LOCK_bytes_sent);
sql/mysqld.cc:  (void) pthread_mutex_init(&LOCK_bytes_sent,MY_MUTEX_INIT_FAST);
sql/net_serv.cc:extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;

They are removed in 5.5:

macbook-pro:mysql-5.1 openxs$ cd ../mysql-5.5
macbook-pro:mysql-5.5 openxs$ grep -r LOCK_bytes_sent *
macbook-pro:mysql-5.5 openxs$
[26 Aug 2011 7:24] Marc ALFF
Duplicate of bug#38968, which is closed (fixed in 5.5 and up)