Redis Persistence-rdb

Source: Internet
Author: User
Tags redis version redis cluster

Redis Persistence-rdb

The persistence of Redis is divided into rdb persistence and aof persistence, and this article mainly says about RDB persistence related things.

RDB persistence is the process of saving data from the current Redis database to the hard disk.

Trigger Time

There are two ways to trigger an RDB persistence, the first being a manual trigger, and the other being an automatic trigger.

Manual Trigger

Manually trigger RBD Primary use save and bgsave commands. In fact Bgsave is an optimization of the Save command blocking problem, so you should always use the Bgsave command.

Save

saveThe command blocks the current master process until the RDB persistence process finishes executing, which can cause very long blocking of memory-larger instances, so the online environment is not used.

Bgsave

bgsaveWhen the command executes, the Redis master process will fork out the subprocess, and the process of the RDB is done by a child process, and during persistence the main process still responds to commands from the application. Blocking only happens at the stage of the fork-out subprocess.

Automatic triggeringthe Save configuration is used in the Redis configuration file

If the configuration is used in the Redis configuration file save m n (representing n data modifications in M seconds), the bgsave is triggered when the situation is satisfied.

perform a full copy operation from a node in a Redis cluster

When a full copy operation is performed from a node, the master node automatically triggers the Bgsave command to survive the Rdb file and send it to the slave node

performing debug Reload loading Redis

When performing debug reload (this time the run ID of the Redis instance does not change), it will also automatically trigger the Bgsave when the Redis is reloaded.

execute the shutdown command by default

The shutdown command is executed by default and Bgsave is performed automatically if the AOF persistence feature is not turned on.

Bgsave trigger RBD execution Process

(TODO next supplemental flowchart)

    • The main process executes the Bgsave command, first checking whether there are currently running child processes, and if so, the Bgsave command exits directly.
    • If the above conditions are met, the main process will fork out the child process, and during the fork operation, the main process will be briefly blocked, and you can use the info stats command's latest_fork_usec options to view the time spent on the most recent fork operation, in microseconds
    • When the parent process fork completes, it will continue to respond to commands from other application staff (but the save,bgsave,bgrewriteaof three commands are special and will respond differently)
    • The child process creates an RDB file, because the copy on write mechanism of the OS will share the same physical page, and when the parent process processes the write request, the OS creates a copy of the page to be modified by the parent process instead of the shared page. So the data in the child process's address space is a snapshot of the entire database at fork time.
    • After a child process writes a snapshot to a temporary file, replaces the original snapshot file with a temporary file and sends a signal to notify the parent process that the RDB persistence process is complete
    • Parent process receives notification to update related persisted information
advantages and disadvantages of RDB persistenceAdvantages
    • Ideal for backup, full-scale replication, and other scenarios
    • Redis load RBD Recovery data is faster than using AOF mode
Disadvantages
    • No way to achieve real-time/quasi-real-time persistence
    • Because the Rdb file is a compressed binary, there are multiple format RDB formats during the evolution of the Redis version, so there is an old version of Redis that is not fully compatible with the new RDB format

  

Original link:https://wenchao.ren/archives/165

Redis Persistence-rdb

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.