java-training-camp
java-training-camp copied to clipboard
第二期 作业一:使用 SOFAJRAFT 实现状态机
内容
- (必须)补充官方 exmaple ElectionBootstrap 增加 Follower 节点日志信息,参考 Leader 事件实现
- (可选)补充官方 exmaple counter 增加 CounterOperation 的操作符,比如 DECREMENT,实现 decrementAndGet 方法,类似于 Atomic 类
https://github.com/liqi19950722/Work/tree/master/work-2-01
https://github.com/Kurok1/java-training-camp/commit/9489d114d254402e1a304b68823e27e9dbe67feb
第一题: https://github.com/z-ak-z/sofa-jraft-learning/commit/d048b6c33b6edb1775c00b7fe3c155356c1be4e0 看日志,2个节点启动后,就选主成功了。
[ElectionBootstrap] Leader's ip is: 127.0.0.1, port: 8083
[ElectionBootstrap] Leader start on term: 7
[ElectionBootstrap] listAlivePeers: [127.0.0.1:8082, 127.0.0.1:8083]
[ElectionBootstrap] listLearners: []
[ElectionBootstrap] listAliveLearners: []
[ElectionBootstrap] followerPeers: [127.0.0.1:8082]


第二题:
https://github.com/z-ak-z/sofa-jraft-learning/commit/4ad5ecbeaf639ae12d0014da4add4ef5ca4d1989#diff-8999f7a701872fb40e5d2446a0c99495633ead4a8dcbb0b6dcbd145dedad8f86
题外话:IncrementAndGetRequest传入负数的delta,达到的效果就是decrementAndGet
https://github.com/xiaozhimingjava/sofa-jraft/tree/work201