In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "zk server exception alarm and thread service shutdown mechanism", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "zk server exception alarm and thread service shutdown mechanism"!
Mainly view ZooKeeperServer
Monitoring and server relationship class diagram
Question: when an important thread shuts down or interrupts? When will this listener be called?
Interface ZooKeeperServerListener
Void notifyStopping (String threadName, int errorCode)
Implementation class ZooKeeperServerListenerImpl
@ Override
Public void notifyStopping (String threadName, int exitCode) {
LOG.info ("Thread {} exits, error code {}", threadName, exitCode)
ZkServer.setState (State.ERROR)
}
The alarm crisis thread ZooKeeperCriticalThread inherits ZooKeeperThread
The parent class method is reimplemented, the listening notification method is called, and the service state is changed.
@ Override protected void handleException (String threadName, Throwable e) {LOG.error ("Severe unrecoverable error, from thread: {}", threadName, e); listener.notifyStopping (threadName, ExitCode.UNEXPECTED_ERROR.getValue ()); ServerMetrics.getMetrics () .UNRECOVERABLE_ERROR_COUNT.add (1);}
The processor implements ZooKeeperServerShutdownHandler
Private final CountDownLatch shutdownLatch
Void handle (State state) {if (state = = State.ERROR | | state = = State.SHUTDOWN) {shutdownLatch.countDown ();}}
Subtract 1 from shutdownLatch
1 exception handling flow
If an exception is encountered during the operation of SessionTrackerImpl
Catch (InterruptedException e) {
HandleException (this.getName (), e)
}
2 call the method handleException of the inherited class
3. Call the .notifyStopping notification method of the listener class ZooKeeperServerListener in the 3 method
4 Notification API to implement ZooKeeperServerListenerImpl specific specification processing
Set the service status to zkServer.setState (State.ERROR)
5 call the zkServer.setState method, and internally call the ZooKeeperServerShutdownHandler processor method
6 call the handle method in the processor
Void handle (State state) {
If (state = = State.ERROR | | state = = State.SHUTDOWN) {
ShutdownLatch.countDown ()
}
}
6 counter shutdown ZooKeeperServerMain registered shutdown service processor
/ / Registers shutdown handler which will be used to know the
/ / server error or shutdown state changes.
Final CountDownLatch shutdownLatch = new CountDownLatch (1)
ZkServer.registerServerShutdownHandler (new ZooKeeperServerShutdownHandler (shutdownLatch))
...
ContainerManager.start ()
/ / Watch status of ZooKeeper server. It will do a graceful shutdown
/ / if the server is not running or hits an internal error.
ShutdownLatch.await ()
Thank you for reading, the above is the content of "zk server exception alarm and thread service shutdown mechanism". After the study of this article, I believe you have a deeper understanding of the zk server exception alarm and thread service shutdown mechanism, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.