Redis Learning--persistence of RDB and AOF

Source: Internet
Author: User
Tags compact time interval

Rdb:

Writes a snapshot of an in-memory dataset to disk at a specified time interval, which is the jargon-snapshot snapshot, which, when restored, reads the snapshot file directly into memory. The RDB holds the Dump.rdb file

How the RDB works:

Redis creates (fork) a child process to persist, writes the data to a temporary file, finishes the persistence process, and replaces the last persisted file with the temporary file. Throughout the process, the main process is not performing any IO operations, which ensures very high performance, if large-scale data recovery is required and the integrity of the data recovery is not very sensitive, the RDB party
, the formula is more efficient than the aof way. The disadvantage of an RDB is that the last persisted data may be lost.

The role of Fork:fork is to replicate a process that is the same as the current process. All data for the new process (variables, environment variables, program counters, etc.)
Values are consistent with the original process, but are a completely new process and as a child of the original process

redis.conf Configuration Location:

################################ snapshotting  ################################     //Snapshot
# Save the DB on disk:## save <seconds> <changes># # would save the DBIfBoth the given number of seconds and the given# number ofWriteOperations against the DB occurred.## in the example below the behaviour would be is to save:# Aftersec (min)if at least1Key changed# aftersec (5 min)if at leastTenkeys changed# after sec   if at least   10000   keys changed# Save <seconds > <changes>
# Save 900 1
# Save 60 10000
# represents 1 changes in 900 seconds (15 minutes), 5 changes in 300 seconds (10 minutes), and 60 changes in 10,000 seconds, respectively.
......................

Command Save or Bgsave

Save when Save:save, all the rest, all blocked

the Bgsave:redis will perform the snapshot operations asynchronously in the background, snapshots can also respond to client requests. The last time the snapshot was successfully executed can be obtained through the Lastsave command

Stop RDB: command: REDIS-CLI config set save ""
AOF:

record each write in the form of a log, recording all the write instructions that Redis has performed (the read operation is not logged),
To append files but not to overwrite files, Redis startup early reads the file to reconstruct the data, in other words, Redis
If you restart, the write instruction is executed from front to back according to the contents of the log file to complete the recovery of the data. AoF saved is appendonly.aof file

redis.conf Configuration Location:

############################## APPEND only MODE ###############################Append aof# By default Redis asynchronously dumps the dataset on disk. This mode is# good enoughInchMany applications, but an issue with the Redis process or# a power outage could result into a few minutes of writes lost (DE Pending on# the configured save points). # # The Append only File is a alternative persistence mode that provides# much bet ter durability. For instance using the default data Fsync policy# (see laterIn the ConfigFile) Redis can lose just one second of writesIncha# Dramatic event like a server power outage, or a singleWriteIfsomething# wrong with the Redis process itself happens, but the operating system is# still running correctly.## AOF and RD B persistence can is enabled at the sametime without problems.# If the AOF is enabled on startup Redis would load the AOF, that's the file# with T He better durability guarantees.## Please check the http://Redis.io/topics/persistence for moreinformation.  AppendOnly no default aof backup policy off # The name of the append only file (default: "appendonly.aof") appendf Ilename "appendonly.aof" default backup file name: "appendonly.aof"      

.
.
.
.
Working principle

The AOF rewrite, like the RDB snapshot, cleverly leverages the write-time replication mechanism:

    • Redis executes fork () and now has both parent and child processes.
    • The child process begins writing the contents of the new AOF file to a temporary file.
    • For all newly executed write commands, the parent process accumulates them into a memory cache while appending these changes to the end of the existing AOF file, which is still safe even if there is an outage in the middle of the rewrite.
    • When a child process finishes rewriting work, it sends a signal to the parent process that the parent process appends all the data in the memory cache to the end of the new AOF file after it receives the signal.
    • Now Redis atomically replaces the old file with the new file, and all commands are appended directly to the end of the new AOF file.
AOF have a backup policy?

You can configure how long Redis will fsync data to disk once. There are three ways of doing this:

    • Appendfsync always: Executes Fsync once a new command is appended to the AOF file: very slow and very secure
    • appendfsync everysec: fsync per second: fast enough (almost as long as the RDB is persisted), and only 1 seconds of data are lost in the case of a failure.
    • Appendfsync No: never Fsync: Give the data to the operating system for processing. Faster and less secure choice.
    • The recommended (and also the default) measure is Fsync per second, and this fsync strategy can take into account speed and security.

RDB and AoF File repair
$ redis-check-dump–fix <filename>   //dump.rdb File Repair $ redis-check-aof–fix  <filename>   //appendonly.aof File Repair
RDB Switch to AOF mode
execute the following two commands: Redis-CLI config set appendonly yesredis-cli config set save ""
Interaction between the AOF and the RDB
When Redis is started, if both RDB persistence and AOF persistence are turned on, the program takes precedence over the AOF file to recover the dataset, because the data that is stored in the AOF file is usually the most complete.
Advantages and disadvantages of RDB and aof (difference)

RDB Benefits:

1) The RDB is a very compact file that holds a data set at a point in time and is ideal for backup of datasets.

2) RDB is a compact single file, it is easy to transfer to another remote data center, without regard to data integrity, consistency, suitable for large-scale recovery of data, high efficiency

3) When an RDB saves an RDB file, the only thing the parent process needs to do is fork out a sub-process, and the next work is done by the child process, and the parent process does not need to do other IO operations.

RDB Disadvantages:
1) With Redis unplanned downtime, you may lose a few minutes of data, and you will lose all modifications after the last snapshot.
2) fork, the data in memory is cloned a copy, roughly twice times the expansion of the need to consider.

AOF Advantages:
1) AOF will make your redis more durable: You can use different Fsync strategies: no Fsync, Fsync per second, Fsync every time you write. With the default Fsync policy per second, Redis is still performing well and, in the event of a failure,
You lose up to 1 seconds of data.

AoF Disadvantages:
1) for the same data set, the volume of the AOF file is usually larger than the size of the RDB file.
2) AOF operation efficiency is slower than RDB, the synchronization strategy per second (Appendfsync everysec) is more efficient, the synchronization efficiency is the same as the RDB.



Redis Learning--persistence of RDB and AOF

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.