美文网首页
MySQL:简单记录信号处理

MySQL:简单记录信号处理

作者: 重庆八怪 | 来源:发表于2021-01-22 12:31 被阅读0次

    码版本:5.7.29
    简单记录信号如何生效的。poll收到信号后如何中断后如何处理的,需要确认。


    初始化信号处理方式,设置信号的处理的处理方式,屏蔽某些信号,并且继承到子线程(pthread_sigmask),主要屏蔽的为SIGTERM、SIGQUIT、SIGHUP、SIGTSTP四个。其他信号按照默认处理方式,但是处理前打印crash栈,handle_fatal_signal

    对于siguser1 进行捕获,处理函数为空empty_signal_handler

    #0  my_init_signals () at /home/mysql/soft/percona-server-5.7.29-32/sql/mysqld.cc:2225
    #1  0x00000000015fefc9 in mysqld_main (argc=79, argv=0x2e22368) at /home/mysql/soft/percona-server-5.7.29-32/sql/mysqld.cc:4846
    #2  0x0000000000e8795d in main (argc=4, argv=0x7fffffffe538) at /home/mysql/soft/percona-server-5.7.29-32/sql/main.cc:32
    

    启动信号处理线程start_signal_handler线程调用函数为 signal_hand,
    使用sigwait获取未决信号集合,如果为SIGTERM和SIGQUIT,设置abort_loop= true;
    并且发送sigusr1个主线程,准备正常退出pthread_kill(main_thread_id, SIGUSR1)) //给主线程发送sigusr1信号
    如果为SIGHUP则重载一下reload_acl_and_cache相关缓存。

    start_signal_handler线程调用函数为 signal_hand

    #0  start_signal_handler () at /home/mysql/soft/percona-server-5.7.29-32/sql/mysqld.cc:2301
    #1  0x00000000015fff70 in mysqld_main (argc=79, argv=0x2e22368) at /home/mysql/soft/percona-server-5.7.29-32/sql/mysqld.cc:5407
    #2  0x0000000000e8795d in main (argc=4, argv=0x7fffffffe538) at /home/mysql/soft/percona-server-5.7.29-32/sql/main.cc:32
    

    三、

    如果为SIGTERM和SIGQUIT,主线程(main)正在poll接受连接,收到了sigusr1 信号后进行中断处理,接下来进行判断
    全局变量abort_loop,然后进入正常退出流程。

    #0  empty_signal_handler (sig=32767) at /home/mysql/soft/percona-server-5.7.29-32/sql/mysqld.cc:2219
    #1  <signal handler called>
    #2  0x00007ffff5f20c3d in poll () from /lib64/libc.so.6
    #3  0x00000000015ec077 in Mysqld_socket_listener::listen_for_connection_event (this=0x35a76f0) at /home/mysql/soft/percona-server-5.7.29-32/sql/conn_handler/socket_connection.cc:883
    #4  0x0000000001607542 in Connection_acceptor<Mysqld_socket_listener>::connection_event_loop (this=0x35a70e0)
        at /home/mysql/soft/percona-server-5.7.29-32/sql/conn_handler/connection_acceptor.h:73
    #5  0x00000000016001f2 in mysqld_main (argc=79, argv=0x2e22368) at /home/mysql/soft/percona-server-5.7.29-32/sql/mysqld.cc:5513
    #6  0x0000000000e8795d in main (argc=4, argv=0x7fffffffe538) at /home/mysql/soft/percona-server-5.7.29-32/sql/main.cc:32
    

    main thread

      mysqld_socket_acceptor->connection_event_loop(); //监听3306 端口
    #endif /* _WIN32 */
      server_operational_state= SERVER_SHUTTING_DOWN; //这里开始进行关闭处理
    
      DBUG_PRINT("info", ("No longer listening for incoming connections"));
    
      mysql_audit_notify(MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN, Mysqld_socket_listener::listen_for_connection_event
                         MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_SHUTDOWN,
                         MYSQLD_SUCCESS_EXIT);
    
      terminate_compress_gtid_table_thread();
    
    

    相关文章

      网友评论

          本文标题:MySQL:简单记录信号处理

          本文链接:https://www.haomeiwen.com/subject/cbuszktx.html