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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

聊聊elasticsearch的RoutingService

發布時間:2025/7/14 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 聊聊elasticsearch的RoutingService 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

本文主要研究一下elasticsearch的RoutingService

RoutingService

elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java

public class RoutingService extends AbstractLifecycleComponent {private static final Logger logger = LogManager.getLogger(RoutingService.class);private static final String CLUSTER_UPDATE_TASK_SOURCE = "cluster_reroute";private final ClusterService clusterService;private final AllocationService allocationService;private AtomicBoolean rerouting = new AtomicBoolean();@Injectpublic RoutingService(ClusterService clusterService, AllocationService allocationService) {this.clusterService = clusterService;this.allocationService = allocationService;}@Overrideprotected void doStart() {}@Overrideprotected void doStop() {}@Overrideprotected void doClose() {}/*** Initiates a reroute.*/public final void reroute(String reason) {try {if (lifecycle.stopped()) {return;}if (rerouting.compareAndSet(false, true) == false) {logger.trace("already has pending reroute, ignoring {}", reason);return;}logger.trace("rerouting {}", reason);clusterService.submitStateUpdateTask(CLUSTER_UPDATE_TASK_SOURCE + "(" + reason + ")",new ClusterStateUpdateTask(Priority.HIGH) {@Overridepublic ClusterState execute(ClusterState currentState) {rerouting.set(false);return allocationService.reroute(currentState, reason);}@Overridepublic void onNoLongerMaster(String source) {rerouting.set(false);// no biggie}@Overridepublic void onFailure(String source, Exception e) {rerouting.set(false);ClusterState state = clusterService.state();if (logger.isTraceEnabled()) {logger.error(() -> new ParameterizedMessage("unexpected failure during [{}], current state:\n{}",source, state), e);} else {logger.error(() -> new ParameterizedMessage("unexpected failure during [{}], current state version [{}]",source, state.version()), e);}}});} catch (Exception e) {rerouting.set(false);ClusterState state = clusterService.state();logger.warn(() -> new ParameterizedMessage("failed to reroute routing table, current state:\n{}", state), e);}} }
  • RoutingService的構造器要求輸入clusterService及allocationService;其reroute方法主要是向clusterService提交ClusterStateUpdateTask,其execute方法是委托給allocationService.reroute

AllocationService.reroute

elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java

public class AllocationService {//....../*** Reroutes the routing table based on the live nodes.* <p>* If the same instance of ClusterState is returned, then no change has been made.*/public ClusterState reroute(ClusterState clusterState, String reason) {return reroute(clusterState, reason, false);}/*** Reroutes the routing table based on the live nodes.* <p>* If the same instance of ClusterState is returned, then no change has been made.*/protected ClusterState reroute(ClusterState clusterState, String reason, boolean debug) {ClusterState fixedClusterState = adaptAutoExpandReplicas(clusterState);RoutingNodes routingNodes = getMutableRoutingNodes(fixedClusterState);// shuffle the unassigned nodes, just so we won't have things like poison failed shardsroutingNodes.unassigned().shuffle();RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, fixedClusterState,clusterInfoService.getClusterInfo(), currentNanoTime());allocation.debugDecision(debug);reroute(allocation);if (fixedClusterState == clusterState && allocation.routingNodesChanged() == false) {return clusterState;}return buildResultAndLogHealthChange(clusterState, allocation, reason);}private void reroute(RoutingAllocation allocation) {assert hasDeadNodes(allocation) == false : "dead nodes should be explicitly cleaned up. See disassociateDeadNodes";assert AutoExpandReplicas.getAutoExpandReplicaChanges(allocation.metaData(), allocation.nodes()).isEmpty() :"auto-expand replicas out of sync with number of nodes in the cluster";// now allocate all the unassigned to available nodesif (allocation.routingNodes().unassigned().size() > 0) {removeDelayMarkers(allocation);gatewayAllocator.allocateUnassigned(allocation);}shardsAllocator.allocate(allocation);assert RoutingNodes.assertShardStats(allocation.routingNodes());}//...... }
  • AllocationService的reroute方法主要是構建RoutingAllocation,然后在進行gatewayAllocator.allocateUnassigned及shardsAllocator.allocate(allocation)

BalancedShardsAllocator.allocate

elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java

public class BalancedShardsAllocator implements ShardsAllocator {//......public void allocate(RoutingAllocation allocation) {if (allocation.routingNodes().size() == 0) {/* with no nodes this is pointless */return;}final Balancer balancer = new Balancer(logger, allocation, weightFunction, threshold);balancer.allocateUnassigned();balancer.moveShards();balancer.balance();}//...... }
  • BalancedShardsAllocator的allocate方法,則創建Balancer,然后執行Balancer的allocateUnassigned()、moveShards()、balance()方法

小結

  • RoutingService的構造器要求輸入clusterService及allocationService;其reroute方法主要是向clusterService提交ClusterStateUpdateTask,其execute方法是委托給allocationService.reroute
  • AllocationService的reroute方法主要是構建RoutingAllocation,然后在進行gatewayAllocator.allocateUnassigned及shardsAllocator.allocate(allocation)
  • BalancedShardsAllocator的allocate方法,則創建Balancer,然后執行Balancer的allocateUnassigned()、moveShards()、balance()方法

doc

  • RoutingService

轉載于:https://my.oschina.net/go4it/blog/3049600

總結

以上是生活随笔為你收集整理的聊聊elasticsearch的RoutingService的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 超碰888| 国产最新视频在线 | 青青草原综合久久大伊人精品 | 女人舌吻男人茎视频 | 久久精品23 | 日韩丰满少妇 | 一区一区三区产品乱码 | 日本老肥婆bbbwbbbwzr | 免费成人黄色网址 | 色姑娘久 | 96久久久 | 欧美三级三级三级爽爽爽 | 亚洲乱码国产乱码精品精软件 | 日本久久一区二区 | 香蕉视频在线观看黄 | 黄片毛片 | 欧美性爱精品在线 | 欧洲色综合 | 99re在线视频观看 | 亚洲综合精品国产 | 成人无码久久久久毛片 | 亚洲欧美激情另类 | 国产一区二区久久久 | 欧美一级艳片视频免费观看 | 久久中文免费视频 | www.超碰97.com| 91性| 午夜一级大片 | 成人黄色av网站 | 国产一级爽片 | 91美女在线 | 波多野吉衣视频在线观看 | 99爱在线观看 | 蜜桃成人在线视频 | 日韩av手机在线观看 | 无码日韩精品视频 | 老熟妇高潮一区二区高清视频 | 天天激情站| 久久中文字幕一区二区 | tube日本69第一次 | 久久人人爽人人爽人人片亚洲 | 人人搞人人爱 | 精品黄色 | 奇米影视盒 | 日韩精品中文字幕在线播放 | 六月丁香综合网 | 自拍偷拍视频网 | 一级做a爰片久久毛片 | 人人色视频 | 美女啪啪av| 91在线观看免费高清完整版在线观看 | 视色网站 | 人妖性生活视频 | 国产精品无码人妻一区二区在线 | 久久国产精品久久久久 | 99久久精品免费看国产免费软件 | 国产精品美女久久久久av超清 | av日日夜夜 | 日韩午夜免费视频 | 一曲二曲三曲在线观看中文字幕动漫 | 免费在线观看www | 国产成人精品无码片区在线 | 成人一区二区电影 | www狠狠干 | 菲律宾黄色片 | 台湾佬美性中文娱乐 | 97超碰碰 | 成人国产一区二区三区精品麻豆 | 老司机精品视频在线 | 免费视频日韩 | www.天天射 | 五月天狠狠操 | 四虎精品永久在线 | 久久久久久久久久久久久久av | 99久久一区二区 | 91精品国产高潮对白 | 淫语视频 | 手机在线小视频 | 色欲av永久无码精品无码蜜桃 | 岛国伊人 | 丰满多毛的大隂户视频 | 国产喷水福利在线视频 | 日大逼 | 亚洲男人天堂2024 | av手机在线免费观看 | 91久久超碰| 欧美激情视频在线播放 | 亚洲精品综合精品自拍 | 精品国产乱码久久久久久108 | 污黄视频在线观看 | 善良的女朋友在线观看 | 欧美群交射精内射颜射潮喷 | ww欧美| 96国产在线 | www,jizz,com | 性欧美又大又长又硬 | 高柳家在线观看 | 红桃视频一区 | 超碰v|