In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the role of ZooKeeperServer in zk? aiming at this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Inner class
ChangeRecord handles the information between PrepRP and FinalRP
Static class ChangeRecord {ChangeRecord (long zxid, String path, StatPersisted stat, int childCount, List acl) {this.zxid = zxid; this.path = path; this.stat = stat; this.childCount = childCount; this.acl = acl;} long zxid; String path; StatPersisted stat; / * Make sure to create a new object when changing * / int childCount; List acl / * Make sure to create a new object when changing * / ChangeRecord duplicate (long zxid) {StatPersisted stat = new StatPersisted (); if (this.stat! = null) {DataTree.copyStatPersisted (this.stat, stat);} return new ChangeRecord (zxid, path, stat, childCount, acl = = null? New ArrayList (): new ArrayList (acl);}} protected enum State {INITIAL, RUNNING, SHUTDOWN, ERROR} initialization function public ZooKeeperServer (FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, int clientPortListenBacklog, ZKDatabase zkDb, String initialConfig) {serverStats = new ServerStats (this); this.txnLogFactory = txnLogFactory; this.txnLogFactory.setServerStats (this.serverStats); this.zkDb = zkDb; this.tickTime = tickTime; setMinSessionTimeout (minSessionTimeout); setMaxSessionTimeout (maxSessionTimeout) This.listenBacklog = clientPortListenBacklog; listener = new ZooKeeperServerListenerImpl (this); readResponseCache = new ResponseCache (); connThrottle = new BlueThrottle (); this.initialConfig = initialConfig; this.requestPathMetricsCollector = new RequestPathMetricsCollector (); this.initLargeRequestThrottlingSettings () LOG.info ("Created server with tickTime" + tickTime + "minSessionTimeout" + getMinSessionTimeout () + "maxSessionTimeout" + getMaxSessionTimeout () + "clientPortListenBacklog" + getClientPortListenBacklog () + "datadir" + txnLogFactory.getDataDir () + "snapdir" + txnLogFactory.getSnapDir ();}
Construct a data management Log FileTxnSnapLog through parameters
Public ZooKeeperServer (File snapDir, File logDir, int tickTime) throws IOException {this (new FileTxnSnapLog (snapDir, logDir), tickTime, ");}
Load data in clusters and stand-alone machines
Cluster call sequence
Leader#lead
ZooKeeperServer#loadData
Stand-alone call sequence
ServerCnxFactory#startUp
ZooKeeperServer#startdata
ZooKeeperServer#loadData
StartData method of stand-alone version
Public void startdata () throws IOException, InterruptedException {/ / check to see if zkDb is not null if (zkDb = = null) {zkDb = new ZKDatabase (this.txnLogFactory); / / instantiate zkdatabase} if (! zkDb.isInitialized ()) {loadData () / / reinitialize}} / / load data public void loadData () throws IOException, InterruptedException {/ * * When a new leader starts executing Leader#lead, it * invokes this method without initialization. The database, however, has been * initialized before running leader election so that * the server could pick its zxid for its initial vote. * It does it by invoking QuorumPeer#getLastLoggedZxid. * Consequently, we don't need to initialize it once more * and avoid the penalty of loading it a second time. Not * reloading it is particularly important for applications * that host a large database. * The following if block checks whether the database has * been initialized or not. Note that this method is * invoked by at least one other method: * ZooKeeperServer#startdata * / / load information if (zkDb.isInitialized ()) {setZxid (zkDb.getDataTreeLastProcessedZxid ());} else {setZxid (zkDb.loadDataBase ());} / / Clean up dead sessions / / get timeout deadSessions List deadSessions = new ArrayList () For (Long session: zkDb.getSessions ()) {if (zkDb.getSessionWithTimeOuts (). Get (session) = = null) {deadSessions.add (session);}} / / Kill session for (long session: deadSessions) {/ / TODO: Is lastProcessedZxid really the best thing to use? KillSession (session, zkDb.getDataTreeLastProcessedZxid ());} / / Make a clean snapshot create snapshot takeSnapshot ();} delete session protected void killSession (long sessionId, long zxid) {zkDb.killSession (sessionId, zxid); if (LOG.isTraceEnabled ()) {ZooTrace.logTraceMessage (LOG, ZooTrace.SESSION_TRACE_MASK, "ZooKeeperServer-killSession: 0x" + Long.toHexString (sessionId)) } if (sessionTracker! = null) {sessionTracker.removeSession (sessionId);}} public synchronized void startup () {if (sessionTracker = = null) {createSessionTracker ();} / / chain of responsibility processing startSessionTracker (); / / set request processor setupRequestProcessors (); startRequestThrottler (); / / register jmx registerJMX (); startJvmPauseMonitor (); registerMetrics () / / set status setState (State.RUNNING); requestPathMetricsCollector.start (); localSessionEnabled = sessionTracker.isLocalSessionsEnabled (); notifyAll ();} this is the answer to the question about what the role of ZooKeeperServer in zk is. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.