public enum ServerState {
// 初始状态
LOOKING,
FOLLOWING,
LEADING,
// 不参与选举
OBSERVING
}
/**
* (Used for monitoring) shows the current phase of
* Zab protocol that peer is running.
*/
public enum ZabState {
//集群进入选举状态
ELECTION,
// 第一:leader收集follower的lastProcessedZxid,这个主要用来通过和leader的lastProcessedZxid对比来确认follower需要同步的数据范围
// 第二:选举出一个新的peerEpoch,主要用于防止旧的leader来进行提交操作(旧leader向follower发送命令的时候,follower发现zxid所在的peerEpoch比现在的小,则直接拒绝,防止出现不一致性)
DISCOVERY,
// 同步数据
SYNCHRONIZATION,
// 提供服务
BROADCAST
}
/**
* (Used for monitoring) When peer is in synchronization phase, this shows
* which synchronization mechanism is being used
*/
public enum SyncMode {
NONE,
// 直接差异化同步, Leader直接把数据发给learner
DIFF,
// Leader 服务器将本机上的全量内存数据都同步给 Learner
SNAP,
// Learner上回滚Leader上不存在的提交
TRUNC
}
/*
* A peer can either be participating, which implies that it is willing to
* both vote in instances of consensus and to elect or become a Leader, or
* it may be observing in which case it isn't.
*
* We need this distinction to decide which ServerState to move to when
* conditions change (e.g. which state to become after LOOKING).
*/
public enum LearnerType {
// FOLLOWING
PARTICIPANT,
// OBSERVING
OBSERVER
}
/*
* To enable observers to have no identifier, we need a generic identifier
* at least for QuorumCnxManager. We use the following constant to as the
* value of such a generic identifier.
*/
static final long OBSERVER_ID = Long.MAX_VALUE;