`

zookeeper-3.5--1.summary

 
阅读更多

  here will talk about the skeleton model of zookeeper,so the details of implemention are recommanded to dig into sources.

 

I startup 

 1.1 client side

 1.2 server side

  

  ------

 

I startup 

 1.1 client side

  as u can see,through the client shell entry,the zkCli.sh states that the  class 'ZooKeeperMain' is the real client command side interacted with server,and the class 'ZooKeeper' is an ensucapsuated client tools which is more closed to server .

  here is a simple client side handling model



   so u will know that there are two components in ZooKeeper instance:

   1.SendThread--used to interact wth server,include send packet to and receive result response from server.in general the ClientCnxnSocketNIO is the implemented class of cnxn.so this is a 'flow controller class'

   2.EventThread--delivers events from the queue which has been put in element in the reponse of SendThread to user register watcher.

  so here are some questions to ask normally:

  q1:if i do some heavy tasks in Watcher#process() ,will it affect   the server?

  no,as this process is stayed in client side,so if u want to issue some CRUD ops about zk or ther io heavy ops ,please go ahead.

  q2:if more than one clients registered  watchers at the same znode(path) ,which one will will be notified first,certain order?

   the notification order is not guaranteed,as the server will send back a notification to all clients whcih have registerd the znode concurrently ,so the order will be caslled as 'randomly'.see 1.2 server side(also,FinalReqeustProcessor#process() & NIOServerCnxn#processWatch())

  q3:issue a 'delete' op on zookeeper client,which one will come first,this  result response or event triggers registered before?

  same as q2,as all reponses will be sent concurrently,so no order is guaranteed.

 

 1.2 server side

  from the zkServer.sh we know that the 'QuorumPeerMain' is the entry of server side. 

  1.2.1 standalone mode


  note:the WorkerThread will not exist if the # of workers is undefined or set to 0.and the NIOServerCnxn is resonsible for communicating with clients to read data from or write data to.

  client A--a client that issue certain CRUD ops.

  clients B--certain clients registered wathchers on that znode,so they will be nodified when client A ops are complete.
  and the request processor chains are below(only for standalone mode):

 

  for example,client B commit a 'getData' op on a znode with a watcher,then server will keep in mind this cnxn;then when client A post a 'delete' op on the same znode,the server will know who has registered this znode,so after the znode has been removed in server,than a 'notification' will be sent to client B immediately.

  but one thing i want to know is:for a 'read' op,the client will get 2 times(two selected keys) to complete the reading;but   only one selected-key for server to do that,why?(preliminarily suggest that this is a nio mechanism,right?) give me a clue if you have any thinkings,please

 

  something to keep in mind:

  A.the client will adjust sessionTimeout against the server's bounds

    in ZooKeeper(x,x),we will pass a sessionTimeout param,and generate two sessionTimeout values against it:

connectTimeout = sessionTimeout / num-zk-servers-client-want-to-connect
readTimeout = sessionTimeout * 2  / 3

    but after the first connect to server,the server will fix it by apply bouds:

minSessionTimeout < sessionTimeout-in-cient < maxSessionTimeout

 and the maxSessionTimeout bound will be applied after the min.

minSessionTimeout  = 2*tick;maxSessionTimeout = 20 * tick

of course the sub values 'connectTimeout' and 'readTimeout' will be recomputed also.

  

  B.there is a sesssion expiry thread called 'SessionTrackerImpl' to expire those

  this thread will use a bucket to remove batch expired threads by using fixed sessionTimeout described in A above,so the real expiry time is not absoulte exact,but it's not important.so the param 'sessionTimeout' sent from client is used only by server for checking expiry period,but no anywhere fro client.

   if u want to introduce a timeout concept in client,u can check in 高并发下NIO socket消息超时机制的探讨 or use a new nio framework,e.g mina

 

  1.2.2 ensemble mode     

         zookeeper-3.5--2 ensemble work flow

 

 

ref:

zookeeper-3.5--study flow 

  • 大小: 109.4 KB
  • 大小: 83.2 KB
  • 大小: 15.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics