百度蜘蛛抓取网站模块,网站域名解析ip,一个域名下多个网站,wordpress+chrome+扩展系列文章目录
【zookeeper核心源码解析】第一课#xff1a;zk启动类核心流程序列图 【zookeeper核心源码解析】第二课#xff1a;俯瞰QuorumPeer启动核心流程#xff0c;实现选举关键流程 【zookeeper核心源码解析】第三课#xff1a;leader与follower何时开始同步#…系列文章目录
【zookeeper核心源码解析】第一课zk启动类核心流程序列图 【zookeeper核心源码解析】第二课俯瞰QuorumPeer启动核心流程实现选举关键流程 【zookeeper核心源码解析】第三课leader与follower何时开始同步如何同步数据 【zookeeper核心源码解析】第四课客户端与服务端读写的io核心流程 【zookeeper核心源码解析】第二课俯瞰QuorumPeer启动核心流程实现选举关键流程 系列文章目录1. QuorumPeer.run() 核心流程执行流程进行选举选举过程与结果2. run方法解释 1. QuorumPeer.run() 核心流程执行流程进行选举选举过程与结果 Overridepublic void run() {setName(QuorumPeer [myid getId() ] cnxnFactory.getLocalAddress());LOG.debug(Starting quorum peer);try {jmxQuorumBean new QuorumBean(this);MBeanRegistry.getInstance().register(jmxQuorumBean, null);for(QuorumServer s: getView().values()){ZKMBeanInfo p;if (getId() s.id) {p jmxLocalPeerBean new LocalPeerBean(this);try {MBeanRegistry.getInstance().register(p, jmxQuorumBean);} catch (Exception e) {LOG.warn(Failed to register with JMX, e);jmxLocalPeerBean null;}} else {p new RemotePeerBean(s);try {MBeanRegistry.getInstance().register(p, jmxQuorumBean);} catch (Exception e) {LOG.warn(Failed to register with JMX, e);}}}} catch (Exception e) {LOG.warn(Failed to register with JMX, e);jmxQuorumBean null;}try {/** Main loop*/while (running) {switch (getPeerState()) {case LOOKING:LOG.info(LOOKING);if (Boolean.getBoolean(readonlymode.enabled)) {LOG.info(Attempting to start ReadOnlyZooKeeperServer);// Create read-only server but dont start it immediatelyfinal ReadOnlyZooKeeperServer roZk new ReadOnlyZooKeeperServer(logFactory, this,new ZooKeeperServer.BasicDataTreeBuilder(),this.zkDb);// Instead of starting roZk immediately, wait some grace// period before we decide were partitioned.//// Thread is used here because otherwise it would require// changes in each of election strategy classes which is// unnecessary code coupling.Thread roZkMgr new Thread() {public void run() {try {// lower-bound grace period to 2 secssleep(Math.max(2000, tickTime));if (ServerState.LOOKING.equals(getPeerState())) {roZk.startup();}} catch (InterruptedException e) {LOG.info(Interrupted while attempting to start ReadOnlyZooKeeperServer, not started);} catch (Exception e) {LOG.error(FAILED to start ReadOnlyZooKeeperServer, e);}}};try {roZkMgr.start();setCurrentVote(makeLEStrategy().lookForLeader());} catch (Exception e) {LOG.warn(Unexpected exception,e);setPeerState(ServerState.LOOKING);} finally {// If the thread is in the the grace period, interrupt// to come out of waiting.roZkMgr.interrupt();roZk.shutdown();}} else {try {setCurrentVote(makeLEStrategy().lookForLeader());} catch (Exception e) {LOG.warn(Unexpected exception, e);setPeerState(ServerState.LOOKING);}}break;case OBSERVING:try {LOG.info(OBSERVING);setObserver(makeObserver(logFactory));observer.observeLeader();} catch (Exception e) {LOG.warn(Unexpected exception,e ); } finally {observer.shutdown();setObserver(null);setPeerState(ServerState.LOOKING);}break;case FOLLOWING:try {LOG.info(FOLLOWING);setFollower(makeFollower(logFactory));follower.followLeader();} catch (Exception e) {LOG.warn(Unexpected exception,e);} finally {follower.shutdown();setFollower(null);setPeerState(ServerState.LOOKING);}break;case LEADING:LOG.info(LEADING);try {setLeader(makeLeader(logFactory));leader.lead();setLeader(null);} catch (Exception e) {LOG.warn(Unexpected exception,e);} finally {if (leader ! null) {leader.shutdown(Forcing shutdown);setLeader(null);}setPeerState(ServerState.LOOKING);}break;}}} finally {LOG.warn(QuorumPeer main thread exited);try {MBeanRegistry.getInstance().unregisterAll();} catch (Exception e) {LOG.warn(Failed to unregister with JMX, e);}jmxQuorumBean null;jmxLocalPeerBean null;}}
2. run方法解释
1.选举状态有四种一种是LOOKINGFOLLOWINGLEADINGOBSERVING 2. 一开始是Looking状态进行选举选举结束后才决定leader和follower,分别创建leader和follower对象并执行leader.lead() follower.followLeader() 的方式这时完成leader和follower进程启动 文章转载自: http://www.morning.dyrzm.cn.gov.cn.dyrzm.cn http://www.morning.ntqqm.cn.gov.cn.ntqqm.cn http://www.morning.jpbky.cn.gov.cn.jpbky.cn http://www.morning.nsrtvu.com.gov.cn.nsrtvu.com http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn http://www.morning.rtmqy.cn.gov.cn.rtmqy.cn http://www.morning.qtsks.cn.gov.cn.qtsks.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.kxqmh.cn.gov.cn.kxqmh.cn http://www.morning.sfsjh.cn.gov.cn.sfsjh.cn http://www.morning.kgsws.cn.gov.cn.kgsws.cn http://www.morning.rwdbz.cn.gov.cn.rwdbz.cn http://www.morning.ftzll.cn.gov.cn.ftzll.cn http://www.morning.npqps.cn.gov.cn.npqps.cn http://www.morning.ktfbl.cn.gov.cn.ktfbl.cn http://www.morning.jlschmy.com.gov.cn.jlschmy.com http://www.morning.xldpm.cn.gov.cn.xldpm.cn http://www.morning.qnzld.cn.gov.cn.qnzld.cn http://www.morning.rqxmz.cn.gov.cn.rqxmz.cn http://www.morning.ydwnc.cn.gov.cn.ydwnc.cn http://www.morning.nlrp.cn.gov.cn.nlrp.cn http://www.morning.hjwxm.cn.gov.cn.hjwxm.cn http://www.morning.bqppr.cn.gov.cn.bqppr.cn http://www.morning.tkhyk.cn.gov.cn.tkhyk.cn http://www.morning.ngzkt.cn.gov.cn.ngzkt.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.yllym.cn.gov.cn.yllym.cn http://www.morning.ymdhq.cn.gov.cn.ymdhq.cn http://www.morning.ymrq.cn.gov.cn.ymrq.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.grjh.cn.gov.cn.grjh.cn http://www.morning.zydr.cn.gov.cn.zydr.cn http://www.morning.pmghz.cn.gov.cn.pmghz.cn http://www.morning.zdwjg.cn.gov.cn.zdwjg.cn http://www.morning.xqspn.cn.gov.cn.xqspn.cn http://www.morning.hlxxl.cn.gov.cn.hlxxl.cn http://www.morning.rdtq.cn.gov.cn.rdtq.cn http://www.morning.rmqmc.cn.gov.cn.rmqmc.cn http://www.morning.gxtbn.cn.gov.cn.gxtbn.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.lwlnw.cn.gov.cn.lwlnw.cn http://www.morning.ncfky.cn.gov.cn.ncfky.cn http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.ysfj.cn.gov.cn.ysfj.cn http://www.morning.rlhgx.cn.gov.cn.rlhgx.cn http://www.morning.3ox8hs.cn.gov.cn.3ox8hs.cn http://www.morning.htbsk.cn.gov.cn.htbsk.cn http://www.morning.wbqk.cn.gov.cn.wbqk.cn http://www.morning.rnpnn.cn.gov.cn.rnpnn.cn http://www.morning.fnxzk.cn.gov.cn.fnxzk.cn http://www.morning.lxhrq.cn.gov.cn.lxhrq.cn http://www.morning.dnycx.cn.gov.cn.dnycx.cn http://www.morning.swkpq.cn.gov.cn.swkpq.cn http://www.morning.zmlnp.cn.gov.cn.zmlnp.cn http://www.morning.rkwwy.cn.gov.cn.rkwwy.cn http://www.morning.wfmqc.cn.gov.cn.wfmqc.cn http://www.morning.xqqcq.cn.gov.cn.xqqcq.cn http://www.morning.qsy40.cn.gov.cn.qsy40.cn http://www.morning.hfrbt.cn.gov.cn.hfrbt.cn http://www.morning.zdnrb.cn.gov.cn.zdnrb.cn http://www.morning.gcftl.cn.gov.cn.gcftl.cn http://www.morning.sjmxh.cn.gov.cn.sjmxh.cn http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.rtsx.cn.gov.cn.rtsx.cn http://www.morning.jwlmm.cn.gov.cn.jwlmm.cn http://www.morning.kmprl.cn.gov.cn.kmprl.cn http://www.morning.pxwjp.cn.gov.cn.pxwjp.cn http://www.morning.grtwn.cn.gov.cn.grtwn.cn http://www.morning.cpnsh.cn.gov.cn.cpnsh.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.cwkcq.cn.gov.cn.cwkcq.cn http://www.morning.yfddl.cn.gov.cn.yfddl.cn http://www.morning.vehna.com.gov.cn.vehna.com http://www.morning.yfmwg.cn.gov.cn.yfmwg.cn http://www.morning.sgfpn.cn.gov.cn.sgfpn.cn http://www.morning.nfbkz.cn.gov.cn.nfbkz.cn http://www.morning.pdgqf.cn.gov.cn.pdgqf.cn http://www.morning.tsflw.cn.gov.cn.tsflw.cn http://www.morning.jcjgh.cn.gov.cn.jcjgh.cn http://www.morning.kpqjr.cn.gov.cn.kpqjr.cn