sofastack / sofa-jraft

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

Raft node startup problem #304

Closed hanzhihua closed 4 years ago

hanzhihua commented 4 years ago

Your question

你好,我节点重启的时候,偶尔会出现下面的异常,我一般都是删除raft日志,然后在启动 异常: 2019-10-22 12:32:09.673 ERROR notaleader [JRaft-LogManager-Disruptor-0]-c.a.s.jraft.util.LogExceptionHandler.handleEventException - Handle LogManagerImpl disruptor event error, event is com.alipay.sofa.jraft.storage.impl.LogManagerImpl$StableClosureEvent@4fb00987 com.alipay.sofa.jraft.error.LogEntryCorruptedException: Log entry data not found at index=399854 at com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage.onTruncateSuffix(RocksDBSegmentLogStorage.java:487) at com.alipay.sofa.jraft.storage.impl.RocksDBLogStorage.truncateSuffix(RocksDBLogStorage.java:543) at com.alipay.sofa.jraft.storage.impl.LogManagerImpl$StableClosureEventHandler.onEvent(LogManagerImpl.java:536) at com.alipay.sofa.jraft.storage.impl.LogManagerImpl$StableClosureEventHandler.onEvent(LogManagerImpl.java:494) at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:137) at java.lang.Thread.run(Thread.java:748)

想咨询一下,出现这个错误,主要的原因是什么吗?

谢谢

Environment

linux 4.9.0-7-amd64 #1 SMP Debian 4.9.110-3+deb9u1 (2018-08-03) x86_64 GNU/Linux 最新版本的jraft jdk1.8

sofastack-bot[bot] commented 4 years ago

Hi @hanzhihua, we detect non-English characters in the issue. This comment is an auto translation by @sofastack-robot to help other users to understand this issue.

We encourage you to describe your issue in English which is more friendly to other users.

Your question Hello, when my node restarts, the following exception will occur occasionally. I usually delete the raft log and then start the exception: 2019-10-22 12:32:09.673 ERROR notaleader [JRaft-LogManager -Disruptor-0]-casjraft.util.LogExceptionHandler.handleEventException - Handle LogManagerImpl disruptor event error, event is com.alipay.sofa.jraft.storage.impl.LogManagerImpl$StableClosureEvent@4fb00987 com.alipay.sofa.jraft.error.LogEntryCorruptedException Log entry data not found at index=399854 at com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage.onTruncateSuffix(RocksDBSegmentLogStorage.java:487) at com.alipay.sofa.jraft.storage.impl.RocksDBLogStorage.truncateSuffix( RocksDBLogStorage.java: 543) at com.alipay.sofa.jraft.storage.impl.LogManagerImpl$StableClosureEventHandler.onEvent(LogManagerImpl.java:536) at com.alipay.sofa.jraft.storage.impl.LogManagerImpl$StableClosureEventHandler.onEvent( LogManagerImpl.java:494) at com.lmax.disruptor.BatchEventProcessor.run(BatchEventPro Cstor.java:137) at java.lang.Thread.run(Thread.java:748) I would like to consult, what is the main reason for this error? Thank you ### Environment linux 4.9.0-7-amd64 #1 SMP Debian 4.9.110-3 deb9u1 (2018-08-03) x86_64 GNU/Linux The latest version of jraft jdk1.8

fengjiachun commented 4 years ago

你把日志删除了获取不到了就是这个错误啦。。。 应该可能分两种情况

  1. 你在重启之前就删除了日志,在你重启之前出现了这个错误
  2. 你只删了日志,没删除整个目录(meta还留着),那就更不行了,属于欺骗 jraft 的行为 :(
hanzhihua commented 4 years ago

如果出现这个问题,raft相关的数据,我都会删除,包括元信息

我主要想知道这个问题出现的愿意是什么呢?谢谢

hanzhihua commented 4 years ago

会不会因为 我把落盘的Sync设置是false,造成的

目前,我在应用启动的时候,会先做一下sync,触发系统的落盘,应用设置成sync=false, 这个有问题吗?

fengjiachun commented 4 years ago

原因上面已经说了呀

fengjiachun commented 4 years ago

rheakv 的 sync 可以设置为 false 没问题, jraft 的 sync 设置为false 的话机器掉电会出现丢数据,理论上重启不会丢

hanzhihua commented 4 years ago

fengjiachun你好,我没有删除日志呀,应用是正常工作,不过,我们做了很多异常流的测试,会出现不停的主备切换,但日志是没有删除 请问一下,还有什么情况出现这个错误呢?我看代码主要是LogManager.unsafeTruncateSuffix出错

fengjiachun commented 4 years ago

你好,我节点重启的时候,偶尔会出现下面的异常,我一般都是删除raft日志,然后在启动

你这里不是说你删除日志么

hanzhihua commented 4 years ago

不好意思,表述不正确,我的意思,如果出现这个错误一般出现在应用启动的时候,我一般的解决方案是删除raft所有信息,然后在重启应用来解决这个问题

我现在想知道,为什么会出现这个错误,是哪里我 做错了

:)

fengjiachun commented 4 years ago

这回看明白了

你修改了默认配置项,使用了 RocksDBSegmentLogStorage 作为 log storage 对吧?当前稳定版本并不包含 RocksDBSegmentLogStorage

如果没删除日志,这个错误不应该出现,请问你知道如何重现吗?

fengjiachun commented 4 years ago

另外 sync 要设置为 true,日志需要同步刷盘

hanzhihua commented 4 years ago

请问一下,使用RocksDBSegmentLogStorage 作为 log storage会有什么问题吗?

目前我们磁盘io有点问题,如果测试成sync=false,我启动的时候回主动调用一次sync,这样做有问题吗?

fengjiachun commented 4 years ago

请问一下,使用RocksDBSegmentLogStorage 作为 log storage会有什么问题吗?

RocksDBSegmentLogStorage 在内部通过了 chaos 测试和 jepsen 测试,我们没发现问题,不过最新发布版本没有包含

目前我们磁盘io有点问题,如果测试成sync=false,我启动的时候回主动调用一次sync,这样做有问题吗?

启动时 sync 没用

hanzhihua commented 4 years ago

启动时 sync 没用,不太理解,日志数据不是都已经写到pagecache中,只要os不重启,都可以正确的落盘 我这样理解不对吗?

fengjiachun commented 4 years ago

fd.sync ,日志这么多 segment 文件, 你的 fd 哪里来的? 你是怎么样调用的 sync ?

hanzhihua commented 4 years ago

我理解linux sync命令是把所有未写的系统缓冲区写到磁盘中

fengjiachun commented 4 years ago

https://linux.die.net/man/2/fsync

fengjiachun commented 4 years ago

要指定 fd 的, 你的 fd 是哪里来的?