知识库--ZooKeeper + States and the Lifetime of a Session(62)
来源:互联网 发布:桌面图标美化软件 编辑:程序博客网 时间:2024/06/02 03:43
States and the Lifetime of a Session
The lifetime of a session corresponds to the period between its creation and its end, whether it is closed gracefully or expires because of a timeout. To talk about what happens in a session, we need to consider the possible states that a session can be in and the possible events that can change its state.
The main possible states of a session are mostly sef-explanntory:CONNECTING,CONNECTED,CLOSED, and NOT_CONNECTED. The state transitions depend on various events that happen between the client and the service.
A session starts at the NOT_CONNECTED state and transitions to CONNECTING with the initialization of the ZooKeeper client. Normally, the connection to a ZooKeeper server succeeds and the session transitions to CONNECTED. When the client loses its connection to the ZooKeeper server or doesn’t hear from the server, it transitions back to CONNECTING and tries to find another ZooKeeper server. If it is able to find another server or reconnect to the original server, it transitions back to CONNECTED once the server confirms that the session is still valid. Otherwise , it declares the session expired and transitions to CLOSED. The application can also explicity close the session.
If a client disconnects from a server due to timeout, the client remains in the CONNECTING state. If the disconnection happens because the client has been partitioned away from the ZooKeeper ensemble, it will remain in this state until either it closes the session explicity, or the partition heals and the client hears from a ZooKeeper server that the session has expired. We have this behavior because the ZooKeeper ensemble is the one responsible for declaring a session expired, not the client. Until the client hears that a ZooKeeper session has expired, the client cannot declare the session expired. The client may choose to close the session, however.
//timeout 参数是一个重要的参数,服务端用来宣布 客户端过期。 客户端用来据此发送 heartbeat message 并且 寻找不同的 服务端。
One important parameter you shuold set when creating a session is the session timeout, which is the amount of timee the ZooKeeper service allows a session before declaring it expired. If the service does not see messages associated to a given session during time t, it declares the session expired. On the client side, if it has heard noting from the server at 1/3 of t, it sends a heartbeat message to the server. At 2/3 of t, the ZooKeeper client starts looking for a different server, and it has another 1/3 of t to find one.
//应用程序传递 服务列表 给客户端 即zk list
In quorum mode, the application is supposed to pass a list of servers the client can connect to and choose from.
//游离的客户端如何选择 服务器
When trying to connect to a different server, it is important for the ZooKeeper state of this server to be at least as fresh as the last ZooKeeper state the client has observed. A client cannot connect to a server that has not seen an update that the client might have seen. ZooKeeper determines freshness by ordering updates in the service. Every change to the state of a ZooKeeper deployment is totally ordered with respect to all other executed updates. Consequently, if a client has observed an update in position i, it cannot connect to a server that has only seen i’< i. In the ZooKeeper implementation, the transaction identifiers that the system assigns to each update establish the order.
Following figure illustrates the use of transaction identifiers (zxids) for reconnecting. After the client disconnects from s1 because it times out, it tries s2, but s2 has lagged behind and does not reflect a change known to the client. However, s3 has seen the same changes as the client, so it is safe to connect.
- 知识库--ZooKeeper + States and the Lifetime of a Session(62)
- Maximize the Lifetime Value of a Social Game Player
- 知识库--ZooKeeper create Session (61)
- states of the thread
- 知识库--ZooKeeper + Watches and Notifications(59)
- The Lifetime of Variants Declared in Function
- 1.4 Dynamically change the look of an application by using view states,transitions and effects
- two ways to hold the states of a job in ironic
- 知识库--Session(47)
- Lessons From A Lifetime Of Being A Programmer
- A List itemRenderer using States and Transitions
- Take a lifetime to be a good (and happy) programmer
- The session of IE7 and IE8
- 知识库--Concurrency+Determining the Number of Threads(76)
- 知识库--ZooKeeper Basics(59)
- 知识库--ZooKeeper + Versions(59)
- 知识库--ZooKeeper+Architecture(59)
- 3 major fashion trend of the United States out of
- iOS 自定义UICollectionViewCell
- 字符串处理技巧系列1
- Git 常用命令大全最新
- 蓝桥杯校内选拔第六题
- 蓝桥杯校内选拔第七题
- 知识库--ZooKeeper + States and the Lifetime of a Session(62)
- 【Java每日一题】20161227
- 蓝桥杯校内选拔第八题
- Centos7在ifcfg文件中配置静态路由 Configuring Static Routes in ifcfg files
- 网络编程(46)—— windows内核对象的两种状态
- ios设置字体-黑体,加粗等 修改textField的placeholder的字体颜色、大小
- 蓝桥杯校内选拔第九题
- cscope快速教程
- Chrome常用快捷键整理