Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

AOF data persistence (theory)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Persistence principle:

AOF has better persistence than the RDB approach.

Redis appends every write command received to the end of the file through the write function, similar to msyql's binlog.

When redis restarts, the contents of the entire database are rebuilt in memory by re-executing the write command saved in the file.

Advantages: higher data integrity can be maintained.

If the time for appending file is set to 1s, then redis fails and a maximum of 1s of data will be lost.

If the log write is incomplete, redis-check-aof is supported for log repair.

Before the AOF file is rewrite (the command will be merged and rewritten if the file is too large)

You can delete some of these commands (such as misoperated flushall).

Disadvantages: AOF files are larger and slower to recover than RDB files.

AOF is off by default.

Profile related parameters:

Appendonly yes

Appendfilename "" # the file name saved by AOF

Configuration related to synchronization mode:

Once appendfsync always # inserts the command, it is synchronized to disk immediately. It is completely persistent, but the speed is slow. It is not recommended.

Appendfsync everysec # AOF synchronizes every second

Appendfsync no # does not synchronize automatically and has the best performance, but persistence is not guaranteed

Stored procedure:

Append the contents of the snapshot to the AOF file as a command

So as you append, the AOF file gets bigger and bigger, and the saved AOF file stores all the commands executed.

So you can modify the file to undo the mistyped command (there is no way to rewrite it before rewriting)

Rewrite the AOF file: (solve the growing problem of the AOF file)

Redis-cli-h ip-p port bgrewriteaof

The process of rewriting a command:

After the current snapshot is saved, start a child process to rewrite the AOF file

Merge set commands and other operations into a temporary file to achieve the purpose of reducing the file size.

After the rewrite, replace the temporary file with the new AOF file.

(if there is a new redis operation command during the rewrite, it will be submitted to the cache and appended to the AOF file after the rewrite.)

Note: for redis2.4 or above, the rewriting mechanism is triggered automatically. The relevant redis.conf configurations triggered are as follows:

Auto-aof-rewrite-percentage 100

Rewrite when the current AOF file size exceeds a few percent of the size of the last rewritten file

If it has not been rebooted, it is based on the AOF file size at startup)

Auto-aof-rewrite-min-size 64mb (minimum AOF file size allowed for overrides)

Data recovery:

Restart the redis service, provided that the configuration file must have appendonly yes set, and then load the file from the appendfile file.

Instead, the data is loaded from the RDB.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report