sofastack / sofa-jraft

A production-grade java implementation of RAFT consensus algorithm.
https://www.sofastack.tech/projects/sofa-jraft/
Apache License 2.0
3.59k stars 1.15k forks source link

After a node stops, after deleting the data file, restart the reason for repeatedly printing the following logs. Is there any solution? #315

Closed huzhihong closed 5 years ago

huzhihong commented 5 years ago

image

huzhihong commented 5 years ago

onSnapshotLoad这个方法在启动的时候会被调用多次,我代码其中有一个逻辑是判断当前状态机有没有数据,已经有数据就不需要从快照恢复,onSnapshotLoad直接返回false,最后导致了结点状态一致不正确。现在我想问onSnapshotLoad被调用多次的情况下,是以快照数据为准,还是以当前状态机的数据为准?

fengjiachun commented 5 years ago

正确的做法是以快照为准,重启时不需要为你自己的状态机额外保存任何状态,如果你的状态机数据做了持久化到磁盘,请启动前删除,依靠 onSnapshotLoad + replay raft log 来恢复,这样数据一致性

另外 onSnapshotLoad 如果返回 false,会将状态机设置为 error 状态并停止状态机

killme2008 commented 5 years ago

@fengjiachun 建议这一点写入到我们的文档

fengjiachun commented 5 years ago

@fengjiachun 建议这一点写入到我们的文档

恩,我来更新一下文档

huzhihong commented 5 years ago

嗯嗯 明白了 谢谢

fengjiachun commented 5 years ago

不用客气,没有更多问题的话就关闭这个 issue 了

fengjiachun commented 5 years ago

https://github.com/sofastack/sofastack.tech/pull/291

更新了文档中 snapshot 部分