1. cluser概述

One of the main roles of the master is to decide which shards to allocate to which nodes, and when to move shards between nodes in order to rebalance the cluster.

2. ClusterModule模块的作用

Configures classes and services that affect the entire cluster

3.重点类介绍:

3.1 配置类Decider

  各种Decider关系如下

以EnableAllocationDecider.java为例:

    public static final Setting<Allocation> CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING =new Setting<>("cluster.routing.allocation.enable", Allocation.ALL.toString(), Allocation::parse,Property.Dynamic, Property.NodeScope);public static final Setting<Allocation> INDEX_ROUTING_ALLOCATION_ENABLE_SETTING =new Setting<>("index.routing.allocation.enable", Allocation.ALL.toString(), Allocation::parse,Property.Dynamic, Property.IndexScope);public static final Setting<Rebalance> CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING =new Setting<>("cluster.routing.rebalance.enable", Rebalance.ALL.toString(), Rebalance::parse,Property.Dynamic, Property.NodeScope);public static final Setting<Rebalance> INDEX_ROUTING_REBALANCE_ENABLE_SETTING =new Setting<>("index.routing.rebalance.enable", Rebalance.ALL.toString(), Rebalance::parse,Property.Dynamic, Property.IndexScope);private volatile Rebalance enableRebalance;private volatile Allocation enableAllocation;

Decider的使用

ClusterModule.java
 public static Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings,List<ClusterPlugin> clusterPlugins) {// collect deciders by class so that we can detect duplicatesMap<Class, AllocationDecider> deciders = new LinkedHashMap<>();addAllocationDecider(deciders, new MaxRetryAllocationDecider(settings));addAllocationDecider(deciders, new ResizeAllocationDecider(settings));addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider(settings));addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider(settings));addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings));addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings));addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings));addAllocationDecider(deciders, new NodeVersionAllocationDecider(settings));addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider(settings));addAllocationDecider(deciders, new RestoreInProgressAllocationDecider(settings));addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings));addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings));addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings));addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings));addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings));addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings));clusterPlugins.stream().flatMap(p -> p.createAllocationDeciders(settings, clusterSettings).stream()).forEach(d -> addAllocationDecider(deciders, d));return deciders.values();}

3.2 配置类Allocator

实现类ShardsAllocator

使用

    private static ShardsAllocator createShardsAllocator(Settings settings, ClusterSettings clusterSettings,List<ClusterPlugin> clusterPlugins) {Map<String, Supplier<ShardsAllocator>> allocators = new HashMap<>();allocators.put(BALANCED_ALLOCATOR, () -> new BalancedShardsAllocator(settings, clusterSettings));for (ClusterPlugin plugin : clusterPlugins) {plugin.getShardsAllocators(settings, clusterSettings).forEach((k, v) -> {if (allocators.put(k, v) != null) {throw new IllegalArgumentException("ShardsAllocator [" + k + "] already defined");}});}String allocatorName = SHARDS_ALLOCATOR_TYPE_SETTING.get(settings);Supplier<ShardsAllocator> allocatorSupplier = allocators.get(allocatorName);if (allocatorSupplier == null) {throw new IllegalArgumentException("Unknown ShardsAllocator [" + allocatorName + "]");}return Objects.requireNonNull(allocatorSupplier.get(),"ShardsAllocator factory for [" + allocatorName + "] returned null");}

3.3 服务类

ClusterService.java
    @Overrideprotected synchronized void doStart() {clusterApplierService.start();masterService.start();}

分别调用

2.3.1clusterApplierService

    @Overrideprotected synchronized void doStart() {Objects.requireNonNull(nodeConnectionsService, "please set the node connection service before starting");Objects.requireNonNull(state.get(), "please set initial state before starting");addListener(localNodeMasterListeners);threadPoolExecutor = EsExecutors.newSinglePrioritizing(nodeName + "/" + CLUSTER_UPDATE_THREAD_NAME,daemonThreadFactory(settings, CLUSTER_UPDATE_THREAD_NAME),threadPool.getThreadContext(),threadPool.scheduler());}

3.3.2 masterService

    @Overrideprotected synchronized void doStart() {Objects.requireNonNull(clusterStatePublisher, "please set a cluster state publisher before starting");Objects.requireNonNull(clusterStateSupplier, "please set a cluster state supplier before starting");threadPoolExecutor = EsExecutors.newSinglePrioritizing(nodeName + "/" + MASTER_UPDATE_THREAD_NAME,daemonThreadFactory(settings, MASTER_UPDATE_THREAD_NAME),threadPool.getThreadContext(),threadPool.scheduler());taskBatcher = new Batcher(logger, threadPoolExecutor);}

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

elasticSearch6源码分析(3)cluster模块相关推荐

  1. elasticSearch6源码分析(5)gateway模块

    1.gateway概述 The local gateway module stores the cluster state and shard data across full cluster res ...

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

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

  3. elasticSearch6源码分析(4)indices模块

    1.indices概述 The indices module controls index-related settings that are globally managed for all ind ...

  4. dubbo源码分析系列——dubbo-cluster模块源码分析

    2019独角兽企业重金招聘Python工程师标准>>> 模块功能介绍 该模块的使用介绍请参考dubbo官方用户手册如下章节内容. 集群容错 负载均衡 路由规则 配置规则 注册中心参考 ...

  5. elasticsearch源码分析之search模块(server端)

    elasticsearch源码分析之search模块(server端) 继续接着上一篇的来说啊,当client端将search的请求发送到某一个node之后,剩下的事情就是server端来处理了,具体 ...

  6. elasticsearch源码分析之search模块(client端)

    elasticsearch源码分析之search模块(client端) 注意,我这里所说的都是通过rest api来做的搜索,所以对于接收到请求的节点,我姑且将之称之为client端,其主要的功能我们 ...

  7. FreeCAD源码分析:FreeCADGui模块

    FreeCAD源码分析:FreeCADGui模块 济南友泉软件有限公司 FreeCADGui项目实现了界面操作.模型显示与交互等相关功能,项目构建生成FreeCAD(_d).dll动态链接库. Fre ...

  8. 【转】Spark源码分析之-scheduler模块

    原文地址:http://jerryshao.me/architecture/2013/04/21/Spark%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B9%8B- ...

  9. Python3.5源码分析-内建模块builtins初始化

    Python3源码分析 本文环境python3.5.2. 参考书籍<<Python源码剖析>> python官网 Python3模块初始化与加载 Python的模块分为内建的模 ...

最新文章

  1. 怎么用python画简单的图-用python进行简单的画图操作
  2. android java设置颜色_java – 设置背景颜色:Android
  3. Git 合并分支选项 --squash 合并提交历史
  4. React 父组件和子组件中的方法相互调用
  5. 【Computer Organization笔记12】流水线技术概述
  6. c++笔试题整理(二)
  7. IBM小型机维护手册
  8. TFTP服务器的使用
  9. echarts地图迁徙图
  10. Agisoft Metashape照片转3D模型打印拿宇树狗做个实验
  11. 小米笔记本bios版本大全_如何设置u盘启动?bios设置u盘启动教程+U盘启动快捷键大全...
  12. layui省市区联动选择的实现
  13. Pidgin for windows 与MSN、ICQ、QQ、YAHOO、GoogleTalk、AIM/AOL等网络聊天工具互联互通的新型聊天软件
  14. win server2016远程桌面连接问题
  15. 简书CEO 林立:简书钻改,让付出有所得
  16. UFS发生命令超时处理流程
  17. c语言寻找勾股数,Numpy 寻找勾股数
  18. 多元回归分析(分类与运用)
  19. 总有你挂不完的环保吊牌GRS/RCS/SCS/OBP/OCS/GOTS/……
  20. iTOL:快速绘制超高颜值的进化树!

热门文章

  1. win10如何修改文件拓展名?
  2. 计算机键盘是编码键盘还是非编码键盘,矩阵按键原理图_矩阵按键扫描实例
  3. bootstrap 提交表单给后台_基于Bootstrap的响应式后台管理模板Ace
  4. 安卓代码拉下来编译后怎么运行_支付宝秒开是因为用了方舟编译器?官方回应...
  5. 两个Java项目之间的通信_两个容器之间的Docker通信与Java
  6. php5.5.9 新特性,php,_PHP 5.5.9版本中COOKIE的奇怪现象,php - phpStudy
  7. android java服务,Android进阶学习必会:Java Binder中的系统服务
  8. 记录一下pandas的分组统计功能,agg
  9. MySQL中的enum和set类型
  10. 下列数据类型中python不支持的是_ 下列选项中 ,Python 不支持的数据类型有 ( ) 。_学小易找答案...