简体   繁体   English

raft算法如何在节点成为leader并且有未提交的日志条目的情况下保持强读一致性

[英]How raft algorithm maintains strong read consistency in case of a node become leader and it have an uncommitted log entry

Consider five nodes(S1,S2,S3,S4,S5) getting key/value data.考虑五个节点(S1、S2、S3、S4、S5)获取键/值数据。 And the following steps happened并发生了以下步骤

  1. S3 becomes leader and client write a key equal 2 to cluster S3 成为领导者,客户端向集群写入等于 2 的密钥
  2. S3 append entry to S1,S2,S4,S5, then S1,S2,S4,S5 accept it and write entry to itself log(as shown in the picture 1) S3 append entry to S1,S2,S4,S5,然后S1,S2,S4,S5接受它并将entry写入自己的日志(如图1所示)
  3. S3 received majority response(from S1,S2,S4,S5), S3 commit entity that key equal 2, and send write succeed message to client, and then send commit message to S1,S2,S4,S5 S3 收到多数响应(来自 S1,S2,S4,S5),S3 提交 key 等于 2 的实体,并向客户端发送写入成功消息,然后向 S1,S2,S4,S5 发送提交消息
  4. S2,S4,S5 received commit message and commit entry success, but S1 crashed. S2,S4,S5 收到提交消息并提交条目成功,但 S1 崩溃。 just like in picture 2, S1 will have an uncommitted entry.就像在图 2 中一样,S1 将有一个未提交的条目。
  5. Now, S1 restart and become a leader with an uncommitted entry that key equal 2(as shown in the picture 3)现在,S1 重新启动并成为具有未提交条目且 key 等于 2 的领导者(如图 3 所示)

After above steps, client query an entry(key equal 2, just wrote succeed).经过上述步骤,客户端查询一个条目(key等于2,刚刚写成功)。 But now S1 is leader and key equal 2 entry is uncommitted.但是现在 S1 是领导者,并且 key equal 2 条目未提交。 So, client will can't find entry that itself wrote a moment ago.因此,客户将找不到自己刚才写的条目。 So, where I made a mistake?那么,我在哪里做错了? please help me请帮我图片1 (picture 1) (图片1) 图 2 (picture 2) (图二) 图 3 (picture 3) (图三)

I have found the solution at Diego Ongaro paper more detailed version In Search of an Understandable Consensus Algorithm(Extended Version) .我在 Diego Ongaro 论文中找到了解决方案更详细的版本In Search of an Understanding Consensus Algorithm(Extended Version) In section 8(Client interaction), I found the answer, Raft handles this by having each leader commit a blank no-op entry into the log at the start of its term.在第 8 节(客户端交互)中,我找到了答案, Raft 通过让每个领导者在其任期开始时向日志中提交一个空白的 no-op 条目来处理这个问题。 After this, In question S1 will commit log index equal 1 entry by commit a blank no-op entry.在此之后,问题 S1 将通过提交一个空白的无操作条目来提交日志索引等于 1 条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM