zookeeper选举的zxid的疑问

zk的每一个事务都会有一个唯一的事务id,这个id是一个64位的整数。前32位是逻辑时钟号,后32位是某个逻辑时钟下的单调递增的id,我的疑问是如果在一个任期内(前32位不变),后面的32位用尽了那么整个集群会怎么办?是重新选leader?还是leader不变然后将前32位加1后32位从0开始自增?如果前32位都用尽了又该怎么办?

阅读 4.3k
1 个回答

int 溢出了你说会发生啥?从 0 开始了呗……

然后会触发 XidRolloverException 异常,重新选举。


P.S. 相关源码

public Proposal Leader#propose(Request request) throws XidRolloverException {
    /**
    * Address the rollover issue. All lower 32bits set indicate a new leader
    * election. Force a re-election instead. See ZOOKEEPER-1277
    */
    if ((request.zxid & 0xffffffffL) == 0xffffffffL) {
        String msg = "zxid lower 32 bits have rolled over, forcing re-election, and therefore new epoch start";
        shutdown(msg);
        throw new XidRolloverException(msg);
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进