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

Server宕机后,客户端的refreshLeader方法失败 #1004

Closed annie-jpg closed 1 year ago

annie-jpg commented 1 year ago

在Counter例子中,启用三台Server并加入集群,然后运行CounterCli写入正常。但是如果关闭其中一台Server,Client就会报如下错误:

2023-06-30 17:08:56 [main] ERROR AbstractClientService:156 - Fail to connect 127.0.0.1:8081, remoting exception: com.alipay.remoting.exception.RemotingException: Create connection failed. The address is 127.0.0.1:8081. 2023-06-30 17:08:57 [main] ERROR AbstractClientService:156 - Fail to connect 127.0.0.1:8082, remoting exception: com.alipay.remoting.rpc.exception.InvokeTimeoutException: Rpc invocation timeout[responseCommand TIMEOUT]! the address is 127.0.0.1:8082. Exception in thread "main" java.lang.IllegalStateException: Refresh leader failed at com.alipay.sofa.jraft.example.counter.CounterClient.main(CounterClient.java:56)

如果Leader挂掉,应该发起重新选举,并且向Client报告新的Leader,然后客户端将leader写入缓存吗。

但似乎剩余的两个Server都不会把票投给对方,直到第三个Server重启,Leader才会选举成功。这是为什么

chenzhanpeng commented 1 year ago

在Counter例子中,启用三台Server并加入集群,然后运行CounterCli写入正常。但是如果关闭其中一台Server,Client就会报如下错误:

2023-06-30 17:08:56 [main] ERROR AbstractClientService:156 - Fail to connect 127.0.0.1:8081, remoting exception: com.alipay.remoting.exception.RemotingException: Create connection failed. The address is 127.0.0.1:8081. 2023-06-30 17:08:57 [main] ERROR AbstractClientService:156 - Fail to connect 127.0.0.1:8082, remoting exception: com.alipay.remoting.rpc.exception.InvokeTimeoutException: Rpc invocation timeout[responseCommand TIMEOUT]! the address is 127.0.0.1:8082. Exception in thread "main" java.lang.IllegalStateException: Refresh leader failed at com.alipay.sofa.jraft.example.counter.CounterClient.main(CounterClient.java:56)

如果Leader挂掉,应该发起重新选举,并且向Client报告新的Leader,然后客户端将leader写入缓存吗。

但似乎剩余的两个Server都不会把票投给对方,直到第三个Server重启,Leader才会选举成功。这是为什么

  • SOFAJRaft version: latest
  • JVM version : 8
  • OS version: windows

我这是正常的,你可以加我交流一下,315262634 QQ

killme2008 commented 1 year ago

windows 系统上的行为不做任何保证,也没有测试验证过,sorry。