【zookeeper】错误处理机制
来源:互联网 发布:linux php5.6编译参数 编辑:程序博客网 时间:2024/05/01 14:03
为什么要了解Zookeeper的错误处理机制?
Life would be so much easier if failures never happened. Of course, without failures,much of the need for ZooKeeper would also go away. To effectively use ZooKeeper it is important to understand the kinds of failures that happen and how to handle them.
Zookeeper暴露两种错误(可恢复的和不可恢复的)
ZooKeeper exposes two classes of failures: recoverable andunrecoverable.
Recoverable failures are transient and should be considered relatively normal—things happen. Brief network hiccups and server failures can cause these kinds of failures. Developers should write their code so that their applications keep running in spite of these failures.
Unrecoverable failures are much more problematic. These kinds of failures cause the ZooKeeper handle to become inoperable. The easiest and most common way to deal with this kind of failure is to exit the application. Examples of causes of this class of failure are session timeouts, network outages for longer than the session timeout, and authentication failures.
可恢复故障是短暂的,也是比较正常的。短暂的网络故障和服务器故障可能会导致这类故障。开发人员应该写自己的代码,以便保证应用程序能够一直运行。
可恢复故障
A typical cause ofDisconnected events and ConnectionLossExceptions is a ZooKeeper server failure
Figure 5-5 illustrates the corner case that causes us to miss the creation event of a watched znode. In this example, the client is watching for the creation of /event. However, just as the /event is created by another client, the watching client loses its connection to ZooKeeper. During this time the other client deletes/event, so when the watching client reconnects to ZooKeeper and reregisters its watch, the ZooKeeper server no longer has the/event znode. Thus, when it processes the registered watches and sees the watch for/event, and sees that there is no node called/event, it simply reregisters the watch,causing the client to miss the creation event for /event. Because of this corner case, you should try to avoid watching for the creation event of a znode. If you do watch for a creation event it should be for a long-lived znode; otherwise, this corner case can bite you.
不可恢复故障
1. At t1,c1becomes unresponsive due to overload and stops communicating with ZooKeeper. It has queued up changes to the external resource but has not yet received the CPU cycles to send them.2. At t2, ZooKeeper declares c1’s session with ZooKeeper dead. At this time it also deletes all ephemeral nodes associated withc1’s sessions, including the ephemeral node that it created to become the master.
3. At t3,c2becomes the master.
4. At t4,c2changes the state of the external resource.
5. At t5,c1’s overload subsides and it sends its queued changes to the external resource.
6. At t6,c1is able to reconnect to ZooKeeper, finds out that its session has expired, and relinquishes mastership. Unfortunately, the damage has been done: at time t5, changes were made to the external resource, resulting in corruption.
Figure 5-7 shows how this technique solves the scenario of Figure 5-6. Whenc1becomes the leader at time t1, the creation zxid of the /leader znode is 3 (in reality, the zxid would be a much larger number). It supplies the creation zxid as the fencing token to connect with the database. Later, when c1becomes unresponsive due to overload, ZooKeeper declares c1as failed andc2becomes the new leader at timet2.c2uses 4 as its fencing token because the /leader znode it created has a creation zxid of 4. At time t3,c2starts making requests to the database using its fencing token. Now when c1’s request arrives at the database at timet4, it is rejected because its fencing token (3) is lower than the highestseen fencing token (4), thus avoiding corruption.
- 【zookeeper】错误处理机制
- asp错误处理机制
- 错误处理机制
- Kuix 错误处理机制
- .net错误处理机制
- .net错误处理机制
- .net错误处理机制
- .net错误处理机制
- QTP错误处理机制
- Windows 错误处理机制
- QTP错误处理机制
- net错误处理机制
- QTP错误处理机制
- QTP错误处理机制
- 错误处理机制
- js_错误处理机制
- VB错误处理机制
- Oracle错误处理机制
- windows命令行下用netsh实现端口转发(端口映射)
- Day2_数据类型与运算符
- 解决vs2013控制台程序一闪而过的问题
- C++终极复习篇(三)----类和对象
- Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT…
- 【zookeeper】错误处理机制
- Java基础中的基础01
- Java Calendar 类时间操作,代码很简单。 演示了获取时间,日期时间的累加和累减,以及比较。
- subplot函数用法(MATLAB)
- 【转】将图集切割成单个单个的图片
- 怎样新学一门技术
- JAVA学习摘记
- Curl 常用命令示例
- 根据前序遍历和后续遍历建立二叉树