社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Elasticsearch

Elasticsearch节点关闭

Ombres • 6 年前 • 291 次点击  

节点关闭的时机

当Elasticsearch启动时,在Bootstrap.setup()过程中有这么一段,这里注册了节点关闭执行的钩子。

if (addShutdownHook) {
            Runtime.getRuntime().addShutdownHook(new Thread() {
                @Override
                public void run() {
                    try {
                        IOUtils.close(node, spawner);
                        LoggerContext context = (LoggerContext) LogManager.getContext(false);
                        Configurator.shutdown(context);
                    } catch (IOException ex) {
                        throw new ElasticsearchException("failed to stop node", ex);
                    }
                }
            });
        }

当收到 SIGTERMSIGINT信号时就会执行节点关闭流程

节点关闭进行的操作

Node.class实现了Closeable接口,当IOUtil.close(node, spawner)调用时就会调用node.close()
node.close()中,会对guice中管理的Service进行关闭。
Elasticsearch的Service都会实现startstop方法,方便在节点启动和关闭时进行调用。startstop方法实际会调用各个Service自己实现的doStart()doStop()接口来进行启动或者关闭。

由于各个Service之间可能存在依赖关系,因此在关闭的时候也应该按照顺序进行关闭,这些服务关闭的顺序与启动的时候相反

        injector.getInstance(ResourceWatcherService.class).stop();
        injector.getInstance(HttpServerTransport.class).stop();

        injector.getInstance(SnapshotsService.class).stop();
        injector.getInstance(SnapshotShardsService.class).stop();
        // stop any changes happening as a result of cluster state changes
        injector.getInstance(IndicesClusterStateService.class).stop();
        // close discovery early to not react to pings anymore.
        // This can confuse other nodes and delay things - mostly if we're the master and we're running tests.
        injector.getInstance(Discovery.class).stop();
        // we close indices first, so operations won't be allowed on it
        injector.getInstance(RoutingService.class).stop();
        injector.getInstance(ClusterService.class).stop();
        injector.getInstance(NodeConnectionsService.class).stop();
        nodeService.getMonitorService().stop();
        injector.getInstance(GatewayService.class).stop();
        injector.getInstance(SearchService.class).stop();
        injector.getInstance(TransportService.class).stop();

        pluginLifecycleComponents.forEach(LifecycleComponent::stop);
        // we should stop this last since it waits for resources to get released
        // if we had scroll searchers etc or recovery going on we wait for to finish.
        injector.getInstance(IndicesService.class).stop();
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/34968
 
291 次点击