elasticsearch源码研究之启动
2015-07-13 16:02
183 查看
elasticsearch主要使用juice(一款据说比spring快100倍的对象注入框架,如需详细了解,可以谷歌以下),Guava,netty等等实现的开源框架,下面介绍下es的启动过程,
在启动的过程中,在类中InternalNode注入了很多的模块,同时在各个模块中绑定了各自对应的服务,例如:设置模块绑定了Settings等接口服务,节点模块NodeModule绑定NodeService等服务,下面是比较重要的几个模块:
1.DiscoveryModule:主要涉及到ZenDiscovery服务以及ElectMasterService等,ElectMasterService服务主要做的事情,通过ping操作发现(主)节点,以及节点的join和leave,通过共同的集群名称,共同形成一个集群,以及进行节点的reroute等操作。
2.ClusterModule:主要涉及InternalClusterService服务和各种元数据的相关服务等,其中InternalClusterService服务比较重要,集群状态改变提交更新任务都是在此进行转发异步执行,而且此处线程池用的还是但线程池,即核心线程只有一个,最大线程数也是一个,如下代码所示:
IndicesClusterStateService类的主要内容如下:
3.RestModule:里面又绑定了RestActionModule,此模板非常重要,里面绑定了各种action,例如:RestClusterHealthAction(api:/_cluster/health),其他的同理,见如下代码:
4.GatewayModule:绑定了GatewayService,执行了集群状态恢复的相关操作
5.TransportModule:绑定了TransportService,处理了各种请求的提交和发送,例如:创建索引的请求,将action名称以及相关信息发送出去等;另外一个非常重要的地方是启动netty客户端和服务端
在启动的过程中,在类中InternalNode注入了很多的模块,同时在各个模块中绑定了各自对应的服务,例如:设置模块绑定了Settings等接口服务,节点模块NodeModule绑定NodeService等服务,下面是比较重要的几个模块:
1.DiscoveryModule:主要涉及到ZenDiscovery服务以及ElectMasterService等,ElectMasterService服务主要做的事情,通过ping操作发现(主)节点,以及节点的join和leave,通过共同的集群名称,共同形成一个集群,以及进行节点的reroute等操作。
2.ClusterModule:主要涉及InternalClusterService服务和各种元数据的相关服务等,其中InternalClusterService服务比较重要,集群状态改变提交更新任务都是在此进行转发异步执行,而且此处线程池用的还是但线程池,即核心线程只有一个,最大线程数也是一个,如下代码所示:
this.updateTasksExecutor = EsExecutors.newSinglePrioritizing(daemonThreadFactory(settings, UPDATE_THREAD_NAME));
public static PrioritizedEsThreadPoolExecutor newSinglePrioritizing(ThreadFactory threadFactory) { return new PrioritizedEsThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, threadFactory); }其中InternalClusterService还注册了各种事件监听,用来发送集群改变事件,来恢复集群等操作,例如将此服务IndicesClusterStateService加入到监听事件中去,最终调用其clusterChanged方法,去进行分片操作
for (ClusterStateListener listener : preAppliedListeners) { try { listener.clusterChanged(clusterChangedEvent); } catch (Exception ex) { logger.warn("failed to notify ClusterStateListener", ex); } }
IndicesClusterStateService类的主要内容如下:
applyNewOrUpdatedShards(event);
applyInitializingShard(routingTable, nodes, indexMetaData, routingTable.index(shardRouting.index()).shard(shardRouting.id()), shardRouting);
3.RestModule:里面又绑定了RestActionModule,此模板非常重要,里面绑定了各种action,例如:RestClusterHealthAction(api:/_cluster/health),其他的同理,见如下代码:
bind(RestClusterHealthAction.class).asEagerSingleton();
controller.registerHandler(RestRequest.Method.GET, "/_cluster/health", this); controller.registerHandler(RestRequest.Method.GET, "/_cluster/health/{index}", this);
4.GatewayModule:绑定了GatewayService,执行了集群状态恢复的相关操作
performStateRecovery(asyncRecovery, enforceRecoverAfterTime, reason);
5.TransportModule:绑定了TransportService,处理了各种请求的提交和发送,例如:创建索引的请求,将action名称以及相关信息发送出去等;另外一个非常重要的地方是启动netty客户端和服务端
transport(NettyTransport).start();
@Override protected void doStart() throws ElasticsearchException { boolean success = false; try { clientBootstrap = createClientBootstrap();
相关文章推荐
- 远程升级学习
- OC面向对象的三大特征(封装 继承 多态)习题3 多态
- c++链表实例与链表基本知识
- JS判断客户端是否是iOS或者Android
- 教程-键盘扫描码
- 模板方法模式 Template
- Properties类文件的的操作
- 发现通用流感疫苗的新路径
- 【Java】动物收容所
- 经典算法总结之AdaBoost与随机森林
- Button添加图片和文字
- 左值,右值 及(++a)+=(a++)和(++a)=(++a)+(a++)计算
- jQuery插件第五十六:十七种翻页插件
- 通过maven构建一个java项目
- 实现ssh免密码登录
- linux mkdir命令
- java.net.InetAddress.getLocalHost(InetAddress.java:1473) java.net.Unknown
- 转-浅谈HTTP-GET 、 HTTP-POST 和SOAP
- WebSocket 帮助
- MonkeyTalk 传输协议