背景
了解raft
组成
raft由三个模块组成:
- Leader election: a new leader must be chosen when an existing leader fails
- Log replication: the leader must accept log entries from clients and replicate them across the cluster, forcing the other logs to agree with its own
- Safety: the key safety property for Raft is the State Machine Safety Property in Figure 3: if any server has applied a particular log entry to its state machine,then no other server may apply a different command for the same log index. Section 5.4 describes howRaft ensures this property; the solution involves an additional restriction on the election mechanism described in Section 5.2.
raft 里面apply 和commit 区别
在 Raft 算法中,"apply" 和 "commit" 是两个相关但不同的概念,它们与日志(log)的提交有关。
Commit(提交): 在 Raft 中,当一个领导者将一条日志(log entry)成功地复制到大多数节点的日志中时,该日志条目被认为是“已提交”(committed)。这意味着这个日志条目现在是可用于应用到状态机的。日志的提交是 Raft 中实现一致性的关键机制之一。
Apply(应用): 一旦一个日志条目被提交,领导者就可以将该日志条目中包含的命令应用于其本地状态机。这个过程被称为“应用”(apply)。通过应用日志中的命令,状态机可以执行相应的操作,从而在整个分布式系统中保持一致性。
简而言之,提交(commit)是指 Raft 中日志的复制达到足够的节点,而应用(apply)是指领导者将已提交的日志中的命令应用于本地状态机,以确保在整个系统中的一致性。这两个步骤是 Raft 算法中保证状态一致性的关键部分