In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Redis6.x persistence AOF example analysis, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Overview of AOF
The default AOF persistence policy is to fsync once per second, and fsync refers to recording the write instructions in the cache to disk, in which case Redis can still maintain high performance.
Of course, because OS caches changes made by write in the kernel, it may not be written to disk immediately. In this way, it is still possible to lose some of the changes in aof persistence. However, you can tell Redis through the configuration file when you want to force os to write to disk through the fsync function.
AOF mode in the case of the same data scale, the size of AOF files is larger than that of RDB files, so the recovery speed of AOF mode is slower than that of RDB mode.
Advantages and disadvantages of AOF
Advantages of AOF:
Better protection against data loss, high performance, and emergency recovery
Disadvantages of AOF:
The file is larger than the RDB file, and the written QPS is lower than the RDB AOF configuration.
1:appendonly: whether to enable AOF
2:appendfilename: sets the log file name of AOF
3:appendfsync: sets how the AOF log is synchronized to disk. The fsync () call tells the operating system to write the cached instructions to disk immediately. There are three options:
(1) always: fsync is forced to be called every time you write. In this mode, redis is relatively slow, but the data is the most secure. (2) everysec: enable fsync once per second (3) no: do not call fsync (). Instead, it is up to the operating system to decide the timing of the sync. In this mode, redis will have the fastest performance.
4:no-appendfsync-on-rewrite: sets whether appendsync is allowed when redis is in rewrite. Because when the redis process is doing AOF rewriting, the call to fsync () in the main process will be blocked, that is, the persistence function of redis is temporarily disabled. The default is no, which ensures data security
5:auto-aof-rewrite-min-size: set a minimum size to prevent rewriting from being triggered when aof is very small
6:auto-aof-rewrite-percentage: sets the baseline value for automatic AOF rewriting, that is, the AOF file size at startup. If redis has not been rewritten since startup, the aof file size at startup will be used as the benchmark value. This baseline value is compared with the current aof size. If the current aof size exceeds the set growth ratio, an override is triggered. If auto-aof-rewrite-percentage is set to 0, this rewriting feature will be turned off
AOF log recovery
If you happen to encounter a situation such as full disk space or power outage when adding logs, resulting in incomplete log writes, it doesn't matter. Redis provides a redis-check-aof tool, which can be used to repair logs. The basic steps are as follows:
1: backup the bad AOF file 2: run redis-check-aof-fix to repair 3: use diff-u to see the difference between the two files, confirm the problem point 4: restart redis, load the repaired AOF file AOF rewrite
AOF uses file appends, which will cause AOF files to become larger and larger.
For this reason, Redis provides an AOF file rewriting (rewrite) mechanism, that is, when the size of the AOF file exceeds the set threshold, Redis will start the content compression of the AOF file, keeping only the minimum instruction set that can recover the data.
You can use the command bgrewriteaof
Trigger mechanism of AOF rewriting
Here's how Redis works:
Redis records the AOF size of the last override.
If it has not been rewritten since startup, the size of the AOF file at startup will be used as the benchmark value, which will be compared with the current AOF size, and will trigger if the current AOF size exceeds the set growth ratio.
In addition, you need to set a minimum size to prevent rewriting from being triggered when the AOF is very small.
The basic principles of AOF rewriting
1: before the rewrite starts, redis creates a "rewrite child process" that reads the existing AOF file, parses and compresses the instructions it contains, and writes them to a temporary file.
2: at the same time, the main process will accumulate the newly received write instructions into the memory buffer and continue to write to the original AOF file, which ensures the availability of the original AOF file and avoids accidents in the rewriting process.
3: when the "rewrite child process" finishes rewriting, it will send a signal to the parent process. When the parent process receives the signal, it will append the write instruction cached in memory to the new AOF file.
4: when the append is finished, redis will replace the old AOF file with a new AOF file, and then a new write instruction will be appended to the new AOF file
5: the operation of rewriting the aof file does not read the old aof file, but rewrites the entire database contents in memory to a new aof file by command, which is a bit similar to the snapshot
Overview of RDB+AOF mixing methods
The mixed way of RDB+AOF is to first use RDB for snapshot storage, then use AOF persistence to record all writes, and store the latest data as new RDB records when the rewrite policy satisfies or manually triggers the rewrite.
In this way, data will be recovered from both RDB and AOF when the service is restarted, which not only ensures data integrity, but also improves the performance of data recovery.
Enable mixing mode:
Set the value of aof-use-rdb-preamble to the recovery order of yes data 1: determine whether AOF persistence is enabled. If AOF is enabled, use AOF persistence file to recover data 2: if AOF file does not exist, otherwise use RDB persistence file to recover data 3: if neither AOF file nor RDB file exists, start Redis4 directly: if there is an error in AOF or RDB file Then the error message returned from startup failure is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.