elasticsearch 5.2.2 学习笔记之源码阅读12-分片服务之分片_副本_路由

31 篇文章 0 订阅
24 篇文章 0 订阅

elasticsearch 5.2.2 学习笔记之源码阅读12-分片服务之分片_副本_路由

概述

分片服务之分片_副本_路由

  • 分片(Shard)
    • 分片ID(ShardId,记录分片所属索引和索引中的分片id)
    • 分片路由(ShardRouting,根据集群最新状态,记录此分片的路由信息)
    • 分片索引信息(IndexShardState,记录分片是处于什么状态,是CREATED/POST_RECOVERY/RECOVERING/STARTED/RELOCATED/CLOSED)
    • 恢复状态(RecoveryState)
  • 副本
  • 路由(RoutingTable,记录集群中所有索引的路由信息)
    • 索引路由表(IndexRoutingTable,记录单个索引的所有分片信息)
    • 索引分片路由(IndexShardRoutingTable,记录一个分片的所有信息,例如主分片/副本分片)
    • 分片路由(ShardRouting,根据集群最新状态,记录此分片的路由信息)
    • 路由节点(RoutingNode,记录node上的分片信息)

核心接口与类

  • 使用AbstractComponent和AbstractLifecycleComponent管理核心组件的配置与生命周期
    • AbstractComponent
      • AbstractLifecycleComponent
        • RoutingService(监听集群状态,维护路由表更新服务类)
      • AllocationService(管理集群中节点的分片分配服务类)
      • BaseGatewayShardAllocator(分片分配器基类)
        • PrimaryShardAllocator(主分片分配器)
        • ReplicaShardAllocator(副本分片分配器)
      • AllocationDecider(分配决定器基类,决定给定的分片路由能否分配到相应的节点/保留在相应节点)
        • DiskThresholdDecider(根据磁盘空间来进行判断,是否进行分配,默认磁盘使用率高于低水位线85%新分片不分配到此节点,高于高水位线90%分片不保留在此节点)
        • FilterAllocationDecider(根据设定的index.routing.allocation策略进行分片节点的选择)
    • LifecycleComponent
  • RoutingAllocation(路由分配)
  • ShardsAllocator
    • BalancedShardsAllocator
  • Decision(分片分配的操作标记类)

以 创建索引时的分片操作 为例讲解加载过程

  • 索引创建参看 https://blog.csdn.net/undergrowth/article/details/82885628
    • 在创建索引的时候,先通过RoutingTable.Builder#addAsNew创建索引路由IndexRoutingTable更新RoutingTable和ClusterState
      • IndexRoutingTable.Builder#initializeAsNew/Builder#initializeEmpty根据索引的分片数目indexMetaData.getNumberOfShards()分片数目遍历创建ShardId,再创建ShardId的时候,根据索引副本数目indexMetaData.getNumberOfReplicas()创建分片的主分片和副本分片,但是这些分片都还没有路由节点
    • 然后通过allocationService.reroute根据ClusterState开启分片操作
      • 先通过最新的集群状态的RoutingTable创建RoutingNodes,保存最新的unassignedShards/assignedShards/nodesToShards信息
      • 将未分配分片shuffle,routingNodes.unassigned().shuffle()防止产生毒药后果,同时创建路由分配器RoutingAllocation
      • 然后重新路由reroute(allocation)
        • 先通过gatewayAllocator.allocateUnassigned,GatewayAllocator#allocateUnassigned/GatewayAllocator#innerAllocatedUnassigned
          利用primaryShardAllocator和replicaShardAllocator进行未分片的分配(这里区别于下面在于,网关的分片是其他目标节点上也有此分片的副本分片才可以分配)
        • 然后再shardsAllocator.allocate/BalancedShardsAllocator#allocate创建Balancer进行集群分片的分配和平衡
          • balancer.allocateUnassigned()
          • balancer.moveShards()
          • balancer.balance()
      • 最后发布集群状态,相应服务接收状态进行更改
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值