Zookeeper START Process __hadoop

Source: Internet
Author: User
Tags thread class zookeeper

Zookeeper boot process 1. How to start

Zkserver.sh "Linux" or Zkserver.cmd "Windows"

Take Zkserver.cmd for example (too much content in zkserver.sh):



Can be clearly seen: called the Quorumpeermain this class, the passing parameters for%zoocfg% "in the Zkenv.cmd definition, is zoo.cfg."

To the Quorumpeermain class, there is a main method that accepts a parameter "Profile path":



Of course, accept the parameter is not a matter, but can not cluster, can only operate in stand-alone mode. The Zookeeper cluster boot process "Figure 120, Runfromconfig," is opened only if you accept a parameter as the profile path and this profile is not set to stand-alone mode.

2. Start process source Code Analysis

Runfromconfig:


As can be seen, the program moved to the Quorumpeer, first set a series of zoo.cfg in the attribute value, and then Start,quorumpeer inherited the thread class, naturally transferred to Quorumpeer.run ().

The Run method was too long, streamlined, and left only the skeleton:

 @Override public void Run () {///JMX ... try {* * Main loop * * while (running) {switch (Getpeerstate ()) {case looking:/
                	... setcurrentvote (Makelestrategy (). Lookforleader ());
                .. break;
                        Case Observing:try {setobserver (Makeobserver (logfactory));
                    Observer.observeleader ();
                        catch (Exception e) {} finally {Observer.shutdown ();  
                        Setobserver (NULL);
                    Updateserverstate ();
                } break;
                        Case Following:try {setfollower (Makefollower (logfactory));
                    Follower.followleader (); } catch (Exception e) {} finally {Follower.shutdown ();
                       Setfollower (NULL);
                    Updateserverstate ();
                } break;
                        Case Leading:try {setleader (Makeleader (logfactory));
                        Leader.lead ();
                    Setleader (NULL);
                            The catch (Exception e) {} finally {if (leader!= null) {
                            Leader.shutdown ("forcing shutdown");
                        Setleader (NULL);
                    } updateserverstate ();
                } break; }} finally {///clear JMX}}

As you can see, as long as there is no stop or no exception thrown, this thread has been running, there is no follow-up more operations, all in this cycle.

So far, this node in the Zookeeper cluster, "Peer", is started.


From the Run () method, you can see clearly that the nodes in zookeeper can have four states:

Looking observing following leading

Where state is initialized to looking in the Getpeerstate () method, each node is looking when it is started.

Next, is to participate in the vote, select the Zookeeper cluster leader, see the next article: Zookeeper Fastleaderelection algorithm.
















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.