Friday, May 21, 2021

Redis Signal Handling

SIGTERM 
------- 

 

- Tells redis to shutdown gracefully 

- Same as using "SHUTDOWN" command 

- If RDB file can't be save, shutdown fails to ensure no data is loss 

 

Shutdown includes the ff: 

 

a. if there is a child saving RDB or performing AOF rewrite, child is killed 

b. if AOF is active, redis calls "fsync" to flush buffers to disk 

c. if using RDB files, synchronous (blocking) save is performed 

d. if daemonized, PID file is removed 

e. if using UNIX domain socket, it is removed 

f. exist with 0 code 

 

SIGSEGV, SIGBUS, SIGFPE and SIGILL 

---------------------------------- 

 

Treated as redis crashes. Once any of these signals are trapped, redis performs 

the following in order: 

 

a. bug report is produced (stack trace, register dumps, client states) 

b. fast memory test is performed on host system (redis >= 2.8) 

c. if daemonized, PID is removed 

e. unregisters own signal handler, sends same signal to itself to perform 

   default action (e.g dumping core on filesystem) 

 

What happens when a child process is killed? 

-------------------------------------------- 

 

- When child is performing AOF rewrite, redis handles error and discard 

  corrupted AOF. Rewrite will retrigger later. 

- When child is performing RDB save, redis treat this as a more severe error 

  since there is no durability. Redis will enter to a condition where no more 

  writes will be accepted. 

    * continues reply to read commands 

    * will reply to all write commands with "MISCONFIG" error 

    * will move out from this condition once RDB save is successful 

 

Killing the RDB file without triggering an error condition 

---------------------------------------------------------- 

 

- RDB saving child can be killed via SIGUSR1 signal (redis >= 2.6.10) 

- Parent will not detect this as a critical error 

    

No comments:

Post a Comment