Zookeeper server processing Watcher implementation

Zookeeper server processing Watcher implementation

(1) The server receives the Watcher and stores it. After
receiving the client request, processing the request to determine whether it needs to register the Watcher, if necessary,
the node path of the data node and
ServerCnxn (ServerCnxn represents a connection between the client and the server, which
implements the process interface of Watcher ,
Which can be regarded as a Watcher object at this time) is stored in WatchTable and watch2Paths of WatcherManager.

(2) Watcher trigger
Take the server receiving a setData() transaction request to trigger the NodeDataChanged event as an example:
2.1 Encapsulate WatchedEvent
to encapsulate the notification status (SyncConnected), event type (NodeDataChanged)
and node path into a WatchedEvent object
2.2 Query Watcher
from WatchTable the node path lookup Watcher
2.3 not found; no instructions registered in the client node through the data Watcher
2.4 found; extracting and deleting from the Watcher in WatchTable and Watch2Paths
(Watcher can be seen here in disposable server, trigger It fails once)

(3) Call the process method to trigger Watcher.
The process here is mainly to send Watcher event notifications through the TCP connection corresponding to ServerCnxn

Guess you like

Origin blog.csdn.net/m0_51684972/article/details/111518311