I. what is it
Log each write as a log
, record all the write instructions executed by redis (no record of read operation), only add files but not write files. At the beginning of redis startup, it will read the file and rebuild the data. In other words, when redis restarts, it will execute the write instructions from the front to the back according to the contents of the log file to complete the data recovery.
II. Appendix.aof file
- To configure
Turn on appendonly yes by default
- priority
Both RDB and AOF modes are enabled at the same time, and AOF takes precedence
III. AOF startup / repair / recovery
- Normal recovery
Start: set yes
Copy an AOF file of the data and save it to the corresponding directory
Restore: restart redis and reload - Abnormal recovery
Start: set yes
Backup the written bad AOF file
Repair: redis check AOF — fix
Restore: restart redis and reload
IV. rewrite
- What’s this
Aof adopts the method of file appending, and the file will be larger and larger. To avoid this, a rewrite mechanism is added. When the size of AOF file exceeds the set threshold, redis will start the content compression of AOF file, and only the minimum instruction set that can recover data can be reserved. You can use the command bgrewriteaof#Appendfsync always // every data change will be recorded to the disk immediately. The data with poor performance will be saved completely
Appendfsync everysec // factory default setting, asynchronous operation, recording per second, one second downtime, data loss
#appendfsync no
- Rewriting principle
When the AOF file continues to grow and is too large, it will fork out a new process to rewrite the file (also write the temporary file first and then rename), traverse the data in memory of the new process, and each record has a set statement. The operation of rewriting the AOF file does not read the old AOF file, but rewrites a new AOF file in the way of command for the data content in the whole memory, which is similar to the snapshot - Trigger mechanism
Redis will record the AOF size at the time of last rewrite. The default configuration is triggered when the AOF file size is twice the size after last rewrite and the file size is greater than 64MAuto AOF rewrite percentage 100 // set the overridden benchmark value
Auto AOF rewrite min size 64MB // set the overridden benchmark value