RDB : When Redis save dump.rdb
a file, Redis server to do the following
- Redis call focks (), this time have a parent and child processes
- Data is written to take advantage of the child process (IO) a temporary file rdb
- When the child process finishes writing, redis will replace the old with the new rdb file and delete the old file rdb
Disadvantages :
- Easy to lose data (data integrity)
- When writing a large amount of data can not be timely response to client requests
AOF rewrite and RDB create a snapshot, as it is the clever use of copy-on-write mechanism:
- Redis execute fork (), and now have both parent and child processes.
- The contents of the new child process began AOF file written to a temporary file.
- For all new write command execution, the parent process while they accumulate into a memory cache, while these changes will append to the existing file AOF , even in this kind of rewriting halfway down the existing file AOF still safe.
- When the child process is complete rewrite work, it sends a signal to the parent process, the parent process after receiving the signal, all of the additional data in cache memory to the end of the new AOF file.
- Now Redis atomically replace the old file with a new file, after all of the commands will be added directly to the end of the new AOF file.
pending upgrade…