Characteristics
1. A majority of the - election, survival, operation
2. Data Consistency - Atomic Broadcast
3 atomic - atom broadcast
4. sequential - Queue
The real-time - can change dynamically monitor node
6. Reliability - crash recovery
Features
1. Zookeeper is itself a tree structure - Znode tree
2 is root node /
3. Each child node is called a node znode
4. All of the root node path must have as a starting
5. Each node must store data, this data is typically a description of the configuration information or the node
6. under each node can mount a persistent child node
7. znode tree itself and maintain in disk memory
8. znode maintain in memory tree purpose: to quickly find
9. znode maintain object tree on disk: crash recovery
10. znode tree is stored in a location determined by the disk dataDir property. dataDir default is in the / tmp
transaction exists concept 11. Zookeeper. Zookeeper will each write operation (create, delete, rmr, set ) assigned a global incremental number is called the transaction id - Zxid
Second, the election mechanism
1. Process
1. 第一个阶段:数据恢复阶段。每一个节点(服务器)会找寻当前节点中的最大事务id
2. 第二个阶段:选举阶段。刚开始的时候,Zookeeper集群中的每一个节点都会推荐自己当leader,同时每一个节点会把自己节点的选举信息发送给其他的节点,经过比较之后,最后胜出的节点就成为leader,其他的节点就成为follower。
选举的细节
细节
1. 选举信息:
a. 当前节点的最大事务id - 一般而言是mZxid或者是pZxid
b. 当前节点的选举编号 - myid
c. 逻辑时钟值 - 保证选举在同一轮次上
2. 比较原则:
a. 先比较两个节点的最大事务id,谁大谁赢
b. 如果事务id一致,那么比较myid,谁大谁赢
3. 当一个节点胜过一半及以上的节点的时候,那么这个节点就会成为leader - 选举的过半性
4. 当一个集群中已经选举出来了leader,那么后续添加的节点的事务id以及myid无论多大,这个节点都只能成为follower
5. 节点状态:
a. looking/voting - 选举状态
b. follower - 追随者
c. leader - 领导者
d. observer - 观察者
6. 在集群中,如果出现了多个leader,这种情况称之为脑裂
7. 在Zookeeper集群中,只有半数以上的节点存活的时候才会进行选举才会对外服务 - 存活的过半
8. Zookeeper的节点个数一般是奇数个