日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

elasticSearch6源码分析(3)cluster模块

發(fā)布時間:2025/4/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 elasticSearch6源码分析(3)cluster模块 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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關(guān)系如下

?

以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

實現(xiàn)類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 服務(wù)類

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

分別調(diào)用

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);}

?

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/10102927.html

總結(jié)

以上是生活随笔為你收集整理的elasticSearch6源码分析(3)cluster模块的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。