Replicated state Machine and Wal

Source: Internet
Author: User

When reading a raft paper, consider two questions:

    1. Why use replicated state machine? No other way?
    2. Why do I have to write a log before applying it to replicated state machine and apply it directly to the replicated state machine brush disk?
1 Replicated State machine

In the raft protocol, there is a replicated state machine in each server, and as long as each server receives the same input command, the final result of replicated state machine is the same, The final consensus was reached. Then we can consider if there are other ways of not using replicated state machine. In fact, there are two ways to replicate:

To make the process highly available, we can back up the process, and there are two main ways to implement a master-slave backup of the process

    1. State Transfer: The primary server transmits the full state content to the backup server
    2. Replicated state machine: The server that needs to be backed up is treated as a deterministic state machine-the master is started in the same state, the same input is imported in the same order, and eventually they enter the same state, giving the same output

The second kind is what we just said about replicated state machine. Assuming that the first, we need to replicate the entire data in the server to each other server, the performance cost is obviously not feasible, so in the case of multi-copy replication, replicated state machine is used, The only need to apply incremental commands to the state machine is to achieve the final consensus.

2 WAL

Wal,write-ahead Logging. The central idea of Wal is that changes to the data file must occur after the changes have been recorded to the log, that is, the log is written down and then the data is written. If you follow this procedure, you do not need to brush the data block back to disk every time you commit a transaction, because you can use the log to recover the data in case of a crash.

So what's good about that? Why not just drop the plate?

    1. the main benefit of using Wal is to significantly reduce the number of write disks, because the log file is submitted with only the log files flushed to disk, not all the data files modified by the transaction , and the log files are sequential, so the cost of the synchronization log is much smaller than the cost of synchronizing the data blocks. Here we answer the question just now, the key point is performance.
    2. Using logs also supports operations such as rollback

Therefore, in raft, leader logs the log to follower, which means that the operation has been persisted and replicated to most of the time, indicating that the message is not lost in the entire system (personal understanding)

3 references
    1. Https://www.postgresql.org/docs/9.2/static/wal-intro.html
    2. https://zhuanlan.zhihu.com/p/33816607
    3. Http://book.51cto.com/art/201201/313209.htm

Replicated state Machine and Wal

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.