1
wqlin 2018-06-04 15:34:20 +08:00
嗯,如果在 term 2 的时候没有 propose 新的日志,那么 server 2 就不能 commit 101-105 这几条日志,所以就可能出现活锁的问题。Raft 作者在论文提到新的 leader 上任后可以提交一个空的日志,帮助 commit,但是一时没找到在哪里...
|
3
wqlin 2018-06-04 16:36:42 +08:00
@streamo #2 找到了,在 raft thesis 中 6.4 Processing read-only queries more efficiently 中提到了:
> If the leader has not yet marked an entry from its current term committed, it waits until it has done so. The Leader Completeness Property guarantees that a leader has all committed entries, but at the start of its term, it may not know which those are. To find out, it needs to commit an entry from its term. Raft handles this by having each leader commit a blank no-op entry into the log at the start of its term. As soon as this no-op entry is committed, the leader ’ s commit index will be at least as large as any other servers ’ during its term. > |
4
streamo OP @wqlin 看了下这个似乎是对只读操作的优化,所以按作者的意思如果不需要这个只读优化的话让这个活锁不断循环也没什么大碍?
|
5
wqlin 2018-06-04 21:00:18 +08:00 1
@streamo #4 不记得是不是只有这里涉及了 blank no-op,但是思想是相同的,就是新的 leader 上任后可以自己 propose 一个 command 帮助 commit,SO 的这个问题 https://stackoverflow.com/questions/37210615/raft-term-condition-to-commit-an-entry 有提到:
> What this means in practice is when a leader is elected, it typically commits a no-op entry to force a commit in its current term. The leader doesn't increase its commitIndex until the no-op entry is stored on a majority of servers. > 而且找到一个 Raft 实现,详见: https://github.com/yahoo/gondola,专门分出了一个 blank command: > Note blank commands (command 3) are written into the log after a leader election. This is due to a Raft requirement that entries are not considered committed unless the last committed entry is of the current term. Applications need to ignore these blank commands. > 活锁是否重要取决于应用程序,如果能保证 client 会不同的 propose,那么不处理也没事。但是通常情况下都无法保证,所以一般使用 blank command 帮助 commit |