4.2、在session1中的gdb设置insert的断点 (gdb) b Sql_cmd_insert::mysql_insert Breakpoint 1 at 0x17bd1b9: file /root/mysql-server/sql/sql_insert.cc, line 423.
4.3、查看断点信息,从下往上看,使用到了多个MySQL函数。 (gdb) bt #0 0x00007f8801dfd383 in poll () from /lib64/libc.so.6 #1 0x00000000016c1155 in Mysqld_socket_listener::listen_for_connection_event (this=0x45d8870) at /root/mysql-server/sql/conn_handler/socket_connection.cc:852 #2 0x0000000000ece89c in Connection_acceptor<Mysqld_socket_listener>::connection_event_loop (this=0x45b5ec0) at /root/mysql-server/sql/conn_handler/connection_acceptor.h:66 #3 0x0000000000ec6226 in mysqld_main (argc=17, argv=0x3ab4248) at /root/mysql-server/sql/mysqld.cc:5045 #4 0x0000000000ebd2d4 in main (argc=9, argv=0x7fffb2aa7408) at /root/mysql-server/sql/main.cc:25
4.4、在设置了断点之后,在另一个session2中登录数据库,发现无法登录,hung住了,在gdb中执行next(执行下一步代码),可以看到在socket_connection.cc源码第859行无法继续,代码大致是说要获取系统的socket,还有一些监听信息,由于太多了,直接在gdb中执行continue(到下一个可执行的代码),此时session2已经登录成功。 (gdb) n Single stepping until exit from function poll, which has no line number information. Mysqld_socket_listener::listen_for_connection_event (this=0x45d8870) at /root/mysql-server/sql/conn_handler/socket_connection.cc:859 859 if (retval < 0 && socket_errno != SOCKET_EINTR) (gdb) n 871 if (retval < 0 || abort_loop) (gdb) n 876 MYSQL_SOCKET listen_sock= MYSQL_INVALID_SOCKET; (gdb) n 877 bool is_unix_socket= false; (gdb) n 879 for (uint i= 0; i < m_socket_map.size(); ++i) (gdb) n 881 if (m_poll_info.m_fds[i].revents & POLLIN) (gdb) n 879 for (uint i= 0; i < m_socket_map.size(); ++i) (gdb) n 881 if (m_poll_info.m_fds[i].revents & POLLIN) (gdb) n 883 listen_sock= m_poll_info.m_pfs_fds[i]; (gdb) n 884 is_unix_socket= m_socket_map[listen_sock]; (gdb) n 885 break; (gdb) n 904 for (uint retry= 0; retry < MAX_ACCEPT_RETRY; retry++) (gdb) n 906 socket_len_t length= sizeof(struct sockaddr_storage); (gdb) n 908 (struct sockaddr *)(&cAddr), &length); (gdb) n 909 if (mysql_socket_getfd(connect_sock) != INVALID_SOCKET || (gdb) n … ... (gdb) c Continuing.
4.5、session2此时的select操作都是一切正常的 [root@localhost:(none)][11:41:15am] MySQL-> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed [root@localhost:test][11:49:12am] MySQL-> show tables; +----------------+ | Tables_in_test | +----------------+ | t | | t1 | +----------------+ 2 rows in set (0.00 sec)
[root@localhost:test][11:49:16am] MySQL-> select * from t; +------+------+ | id | name | +------+------+ | 1 | aaa | | 2 | aaa | | 3 | aaa | | 4 | aaa | +------+------+ 4 rows in set (0.00 sec)
4.6、session2做insert操作的时候,又一次hung住了,session1打印出了断点的信息,在mysql_insert:423行,直到执行continue,session2才能正常插入数据。 (gdb) c Continuing. [Switching to Thread 0x7f87e00b4700 (LWP 24824)]
Breakpoint 1, Sql_cmd_insert::mysql_insert (this=0x7f87f40147b8, thd=0x7f87f401bc60, table_list=0x7f87f4013fe0) at /root/mysql-server/sql/sql_insert.cc:423 423 DBUG_ENTER("mysql_insert"); (gdb) n 425 LEX *const lex= thd->lex; (gdb) n 427 bool err= true; (gdb) c Continuing.