1.DiscoveryModule概述

/*** A module for loading classes for node discovery.*/

2.discovery

The discovery module is responsible for discovering nodes within a cluster, as well as electing a master node.Note, Elasticsearch is a peer to peer based system, nodes communicate with one another directly if operations are delegated / broadcast. All the main APIs (index, delete, search) do not communicate with the master node. The responsibility of the master node is to maintain the global cluster state, and act if nodes join or leave the cluster by reassigning shards. Each time a cluster state is changed, the state is made known to the other nodes in the cluster (the manner depends on the actual discovery implementation).

调用情况Node.java

            final DiscoveryModule discoveryModule = new DiscoveryModule(this.settings, threadPool, transportService, namedWriteableRegistry,networkService, clusterService.getMasterService(), clusterService.getClusterApplierService(),clusterService.getClusterSettings(), pluginsService.filterPlugins(DiscoveryPlugin.class),clusterModule.getAllocationService(), environment.configFile());this.nodeService = new NodeService(settings, threadPool, monitorService, discoveryModule.getDiscovery(),transportService, indicesService, pluginsService, circuitBreakerService, scriptModule.getScriptService(),httpServerTransport, ingestService, clusterService, settingsModule.getSettingsFilter(), responseCollectorService,searchTransportService);

Discovery接口

/*** A pluggable module allowing to implement discovery of other nodes, publishing of the cluster* state to all nodes, electing a master of the cluster that raises cluster state change* events.*/

实现类有两个:

2.1 SingleNodeDiscovery

构造方法

    public SingleNodeDiscovery(final Settings settings, final TransportService transportService,final MasterService masterService, final ClusterApplier clusterApplier) {super(Objects.requireNonNull(settings));this.transportService = Objects.requireNonNull(transportService);masterService.setClusterStateSupplier(() -> clusterState);this.clusterApplier = clusterApplier;}

启动方法

   @Overrideprotected synchronized void doStart() {// set initial stateDiscoveryNode localNode = transportService.getLocalNode();clusterState = createInitialState(localNode);clusterApplier.setInitialState(clusterState);}

2.2 ZenDiscovery

构造方法

 public ZenDiscovery(Settings settings, ThreadPool threadPool, TransportService transportService,NamedWriteableRegistry namedWriteableRegistry, MasterService masterService, ClusterApplier clusterApplier,ClusterSettings clusterSettings, UnicastHostsProvider hostsProvider, AllocationService allocationService,Collection<BiConsumer<DiscoveryNode, ClusterState>> onJoinValidators) {super(settings);this.onJoinValidators = addBuiltInJoinValidators(onJoinValidators);this.masterService = masterService;this.clusterApplier = clusterApplier;this.transportService = transportService;this.discoverySettings = new DiscoverySettings(settings, clusterSettings);this.zenPing = newZenPing(settings, threadPool, transportService, hostsProvider);this.electMaster = new ElectMasterService(settings);this.pingTimeout = PING_TIMEOUT_SETTING.get(settings);this.joinTimeout = JOIN_TIMEOUT_SETTING.get(settings);this.joinRetryAttempts = JOIN_RETRY_ATTEMPTS_SETTING.get(settings);this.joinRetryDelay = JOIN_RETRY_DELAY_SETTING.get(settings);this.maxPingsFromAnotherMaster = MAX_PINGS_FROM_ANOTHER_MASTER_SETTING.get(settings);this.sendLeaveRequest = SEND_LEAVE_REQUEST_SETTING.get(settings);this.threadPool = threadPool;ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);this.committedState = new AtomicReference<>();this.masterElectionIgnoreNonMasters = MASTER_ELECTION_IGNORE_NON_MASTER_PINGS_SETTING.get(settings);this.masterElectionWaitForJoinsTimeout = MASTER_ELECTION_WAIT_FOR_JOINS_TIMEOUT_SETTING.get(settings);logger.debug("using ping_timeout [{}], join.timeout [{}], master_election.ignore_non_master [{}]",this.pingTimeout, joinTimeout, masterElectionIgnoreNonMasters);clusterSettings.addSettingsUpdateConsumer(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING,this::handleMinimumMasterNodesChanged, (value) -> {final ClusterState clusterState = this.clusterState();int masterNodes = clusterState.nodes().getMasterNodes().size();// the purpose of this validation is to make sure that the master doesn't step down// due to a change in master nodes, which also means that there is no way to revert// an accidental change. Since we validate using the current cluster state (and// not the one from which the settings come from) we have to be careful and only// validate if the local node is already a master. Doing so all the time causes// subtle issues. For example, a node that joins a cluster has no nodes in its// current cluster state. When it receives a cluster state from the master with// a dynamic minimum master nodes setting int it, we must make sure we don't reject// it.if (clusterState.nodes().isLocalNodeElectedMaster() && value > masterNodes) {throw new IllegalArgumentException("cannot set "+ ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " to more than the current" +" master nodes count [" + masterNodes + "]");}});this.masterFD = new MasterFaultDetection(settings, threadPool, transportService, this::clusterState, masterService, clusterName);this.masterFD.addListener(new MasterNodeFailureListener());this.nodesFD = new NodesFaultDetection(settings, threadPool, transportService, this::clusterState, clusterName);this.nodesFD.addListener(new NodeFaultDetectionListener());this.pendingStatesQueue = new PendingClusterStatesQueue(logger, MAX_PENDING_CLUSTER_STATES_SETTING.get(settings));this.publishClusterState =new PublishClusterStateAction(settings,transportService,namedWriteableRegistry,this,discoverySettings);this.membership = new MembershipAction(settings, transportService, new MembershipListener(), onJoinValidators);this.joinThreadControl = new JoinThreadControl();this.nodeJoinController = new NodeJoinController(masterService, allocationService, electMaster, settings);this.nodeRemovalExecutor = new NodeRemovalClusterStateTaskExecutor(allocationService, electMaster, this::submitRejoin, logger);masterService.setClusterStateSupplier(this::clusterState);transportService.registerRequestHandler(DISCOVERY_REJOIN_ACTION_NAME, RejoinClusterRequest::new, ThreadPool.Names.SAME, new RejoinClusterRequestHandler());}

启动方法

    @Overrideprotected void doStart() {DiscoveryNode localNode = transportService.getLocalNode();assert localNode != null;synchronized (stateMutex) {// set initial stateassert committedState.get() == null;assert localNode != null;ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));ClusterState initialState = builder.blocks(ClusterBlocks.builder().addGlobalBlock(STATE_NOT_RECOVERED_BLOCK).addGlobalBlock(discoverySettings.getNoMasterBlock())).nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())).build();committedState.set(initialState);clusterApplier.setInitialState(initialState);nodesFD.setLocalNode(localNode);joinThreadControl.start();}zenPing.start();}

转载于:https://www.cnblogs.com/davidwang456/p/10169058.html

elasticSearch6源码分析(12)DiscoveryModule相关推荐

  1. Hadoop源码分析(12)

    Hadoop源码分析(12) 1. journalnode客户端   在文档(11)中分析了初始化editlog的方法.在初始化之前其会根据集 群的配置状态选择不同的方式来进行初始化.在HA状态下,其 ...

  2. red5源码分析---12

    red5源码分析-服务器处理视频数据 接着<red5源码分析-11>,本章假设客户端发来的是视频数据,下面就分析服务器如何处理这些数据的. 根据前面几章的分析,基于mina框架,数据到达服 ...

  3. tcp/ip 协议栈Linux内核源码分析12 udp套接字发送流程一

    内核版本:3.4.39 因为过往的开发工作中既包括内核网络层模块的开发,又包括应用层程序的开发,所以对于网络数据的通信有那么一些了解.但是对于网络通信过程中,内核和应用层之间接口是如何运作的不是很清楚 ...

  4. elasticSearch6源码分析(10)SettingsModule

    1.SettingsModule概述 /*** A module that binds the provided settings to the {@link Settings} interface. ...

  5. elasticSearch6源码分析(2)模块化管理

    elasticsearch里面的组件基本都是用Guice的Injector进行注入与获取实例方式进行模块化管理. 在node的构造方法中 /*** Constructs a node** @param ...

  6. elasticSearch6源码分析(1)启动过程

    1.找到bin目录,下面有elasticSearch的sh文件,查看执行过程 exec \"$JAVA" \$ES_JAVA_OPTS \-Des.path.home=" ...

  7. elasticSearch6源码分析(6)http和transport模块

    1.http模块概述 The http module allows to expose Elasticsearch APIs over HTTP.The http mechanism is compl ...

  8. elasticSearch6源码分析(9)ActionModule

    1.ActionModule概述 /*** Builds and binds the generic action map, all {@link TransportAction}s, and {@l ...

  9. elasticSearch6源码分析(8)RepositoriesModule模块

    1.RepositoriesModule概述 Sets up classes for Snapshot/Restore 1.1 snapshot概述 A snapshot is a backup ta ...

最新文章

  1. R绘制水平箱图(horizontal boxplot)
  2. httpmodule权限应用
  3. ubuntu锁定mysql到任务栏_ubuntu16.04与mysql的运维注意事项
  4. 信息学奥赛一本通(C++)在线评测系统——基础(一)C++语言——1079:计算分数加减表达式的值
  5. java 对第三方的异常_Java第三方API调用打开文件方法时抛出异常
  6. java中什么是守护线程_什么是Java的守护线程?
  7. .NET 请求、事件 处理流程
  8. 改造一下jeecg中的部门树
  9. 你的消息队列如何保证消息不丢失,且只被消费一次,这篇就教会你
  10. 20个有用的 PHP + jQuery 组件和教程
  11. 林德物料搬运公司成功案例:基于功能需求开发的软件模型质量保障
  12. 怎样做风险评估?风险评估有哪些具体实施流程?
  13. 计算机量子化学计算实验报告物化实验,量子化学计算方试验.doc
  14. 我们这里最近很流行用彩色的丝带编成手环
  15. 安卓gpio操作示例
  16. wchar to char转换
  17. C语言:窗口控制台颜色改变(不断换色)
  18. mocha 测试 mysql_GitHub - nodejs-xx/lei: 整合Express mysql ioredis ejs 的一开发框架,使用mocha对api进行测试...
  19. 不同开发语言之Python、Java、Golang对比
  20. 【数据结构_选择题】(D21 0519)

热门文章

  1. 最严谨的计算机语言p,用于PLC的华P语言编译器设计及实现.pdf
  2. linux平台 使用dlopen接口调用HelloWorld动态库简单实例
  3. jmeter linux安装,Linux下安装Jmeter
  4. python圆的半径计算圆的周长列表_python计算圆周长、面积、球体体积并画出圆
  5. socket同步和异步通信区别_程序员必知必会,同步通信与异步通信,你了解多少...
  6. 自动滚放的html,HTML5实现视频播放器随页面滚动固定页面右下角效果详解
  7. 字符串匹配算法Java_如何简单理解字符串匹配算法?
  8. 华为安卓转鸿蒙,坦白说,华为不用鸿蒙替换安卓,而用HMS替代GMS,是当前最好方案 - 区块网...
  9. android 判断按钮是否已经有onclicklinstener,通过点击事件监听setOnClickListener彻底理解回调...
  10. bicq php,BICQ v2.0.0