Watcher mechanism for Solr source code reading and Analysis

Source: Internet
Author: User
Tags solr

The client ClientWatchManager manages the watchers and handle events generated by ClientXncn.
You can register a watcher object in the ClientWatchManager APIs such as exists, getChildren, and getData of zookeeper,
Create, setData, delete, and other APIs that cause changes to the zookeeper node will trigger the execution of watcher process.

The WatchManager of the server and the watcher Object Manager of the server;
When registering watcher, you will call FinalRequestProcessor. processRequest on the server end to register the server connection object ServerCnxn (which implements the watcher Interface) corresponding to the client to the DataTree.
In this way, when the watcher of the server is triggered, the process method of ServerCnxn is actually triggered. In the process Implementation of ServerCnxn, the notify message is sent to the client that registers the watcher object,
The client will call the process method of the watcher object registered with the corresponding path.
The server registers the watcher object.
FinalRequestProcessor. processRequest
Case OpCode. getData :{
...............................
Stat stat = New Stat ();
Byte B [] = zks. getzkdatabase (). getdata (getdatarequest. getpath (), stat,
Getdatarequest. getwatch ()? Cnxn: NULL); // cnxn is servercnxn
RSp = new getdataresponse (B, STAT );
Watcher trigger: trigerwatch (string path, eventype type) in watchmanager. When the Server accepts operations such as createnode/deletenode/setdata,
The zkdatabase operation will be performed to operate the data in the datatree. Of course, changes to the data in the datatree will trigger watch on the corresponding patch (node) (one operation may trigger multiple watches ),
TrigerWatch is called at these times. In this operation, the watch registered under the corresponding path is removed from watchManager, and watch. process () is called in sequence ().
This process () is used to send a nofication message to the client. The message contains a WatchEvent object, which encapsulates the event type/path,

In the waitingEvents queue sent to EventThread, The EventThread background thread pulls messages from the queue and executes the process logic in watcher.

If an exception occurs when ServerCnxn processes the request or the client is closed, ServerCnxn will call the close () method, one branch operation in this method is to delete the associated watch from the two watches lists in the DataTree.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.