zookeeper 故障重连机制
一、连接多个服务器,用逗号隔开
- 如果在连接时候zk服务器宕机
- To create a client session the application code must provide a connection string containing a comma separated list of host:port pairs, each corresponding to a ZooKeeper server (e.g.
- "127.0.0.1:4545" or "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"). The ZooKeeper client library will pick an arbitrary server and try to connect to it. If this connection fails, or if the client
- becomes disconnected from the server for any reason, the client will automatically try the next server in the list, until a connection is (re-)established.
- 创建一个client session 应用代码必须提供一个连接字符串包含一个逗号分隔的主机:端口 列表,
- 每个对应到一个ZooKeeper server (e.g.
- "127.0.0.1:4545" or "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002").
- ZooKeeper 客户端库 会选择一个任意的server 和尝试连接到它。
- 如果这个连接失败,或者 如果客户端变的不能连接,客户端会自动 尝试下一个server 在列表里,知道一个连接重新创建。
- 如果已经连接之后服务器宕机
- SessionMovedException. There is an internal exception that is generally not seen by clients called the SessionMovedException. This exception occurs because a request was received on a connection
- for a session which has been reestablished on a different server. The normal cause of this error is a client that sends a request to a server, but the network packet gets delayed, so the client
- times out and connects to a new server. When the delayed packet arrives at the first server, the old server detects that the session has moved, and closes the client connection. Clients normally do
- not see this error since they do not read from those old connections. (Old connections are usually closed.) One situation in which this condition can be seen is when two clients try to reestablish
- the same connection using a saved session id and password. One of the clients will reestablish the connection and the second client will be disconnected (causing the pair to attempt to re-establish
- its connection/session indefinitely).
- SessionMovedException. 有一个内部的异常,那是通常不被客户端请求SessionMovedException 看到。
- 这个exception 因为 一个请求被接收在一个连接对于一个会话 精被重新建立到一个不同的zk server.
- 这个错误的通常情况是一个客户端发送一个请求到一个服务器,
- 但是网络包延时了,因此客户端超时 ,连接到一个新的服务器.当延迟的packet 到达第一个server,
- old server 检测倒 session 已经移动了,关闭客户端连接。
- 客户端通常不会看到这个错误 因为它们不会从老的连接读取(老的连接通常是被关闭的)
- 一种情况是这个状况可以被看到当 2个客户端尝试重建建立相同的连接使用一个保存的会话id和密码。
参考链接:http://blog.csdn.net/zhaoyangjian724/article/details/52218172