redis对于posix信号的处理


链接来源自redis官方文档的传送门
备注:The information contained in this document is only applicable to Redis version 2.6 or greater.

1.Handling of SIGTERM and SIGINT(signals to tell Redis to shutdown gracefully)

  • 1.redis会优雅的退出,The SIGTERM and SIGINT signals tell Redis to shutdown gracefully. When this signal is received the server does not immediately exit as a result, but it schedules a shutdown very similar to the one performed when the SHUTDOWN command is called.

shutdown会做的事:
①Stop all the clients.
②Perform a blocking SAVE if at least one save point is configured.
③Flush the Append Only File if AOF is enabled.
④Quit the server.

  • 2.当优雅的退出时,下面就是要做的事:

①If there is a background child saving the RDB file or performing an AOF rewrite, the child is killed.杀死rdb持久化和aof持久化的子进程
②If the AOF is active, Redis calls the fsync system call on the AOF file descriptor in order to flush the buffers on disk.
③If Redis is configured to persist on disk using RDB files, a synchronous (blocking) save is performed. Since the save is performed in a synchronous way no additional memory is used.
④If the server is daemonized, the pid file is removed.
⑤If the Unix domain socket is enabled, it gets removed.
The server exits with an exit code of zero.

  • 备注:为了防止RDB 文件无法保存,关闭失败,服务器继续运行以确保不会丢失数据。由于 Redis 2.6.11 不会进一步尝试关闭,除非收到新的SIGTERM通知或发布关闭命令

2.Handling of SIGSEGV, SIGBUS, SIGFPE and SIGILL(redis crash)

  • 1.以下信号,redis遇到就会认为是redis崩溃了

SIGSEGV
SIGBUS
SIGFPE
SIGILL

  • 2.结果:

1)日志打印a stack trace, dump of registers, and information about the state of clients.
2)Since Redis 2.8 a fast memory test is performed as a first check of the reliability of the crashing system.
3)If the server was daemonized, the pid file is removed.
4)最后,服务器为接收的信号而将其信号处理程序重新注册,并再次向自己发送相同的信号,以确保执行默认操作,例如将内核倾倒在文件系统上。

3.What happens when a child process gets killed(当子进程被杀,会发生什么事情)

  • 1.当aof重写的进程被杀,redis会丢弃还没重写玩的aof文件,会等会再重启aof重写的进程(When the child performing the Append Only File rewrite gets killed by a signal, Redis handles this as an error and discards the (probably partial or corrupted) AOF file. The rewrite will be re-triggered again later.)
  • 2.当rdb持久化的进程被杀,redis认为这是比杀死aof重写进程更严重的情况
  • 3.当上述情况发生,redis就会:

1)redis只能反馈读命令
2)redis面对写命令会返回MISCONFIG错误

4.Killing the RDB file without triggering an error condition(在没有错误产生的情况下杀死rdb持久化的进程-SIGUSR1)

  • 1.However sometimes the user may want to kill the RDB saving child without generating an error.
  • 2.Since Redis version 2.6.10 this can be done using the special signal SIGUSR1 that is handled in a special way: it kills the child process as any other signal,
    –用SIGUSR1杀死进行RDB持久化的子进程
  • 3.but the parent process will not detect this as a critical error and will continue to serve write requests as usually.
    –主进程不会认为用SIGUSR1杀死rdb持久化子进程的这个行为是个错误,仍然照常执行任务
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值