`
tcxiang
  • 浏览: 89524 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ES unassigned initializing问题处理(转)

 
阅读更多

Elasticsearch is one of my favorite piece of software. I’ve been using it since 0.11 and deployed every version since 0.17.6 in production. However, I must admit it’s sometimes a pain in the ass to manage. It can behave unexpectedly and either vomit gigabytes in your logs, or stay desperately silent.

One of those strange behaviour can happen after one or more data nodes are restarted. In a cluster running either lots of nodes or lots of shards, the post restart shard allocation can take forever and never end.

This post is about investigating and eventually fixing this behaviour. You don’t need to have a deep knowledge of Elasticsearch to understand it.

Red is dead

The first evidence something’s wrong comes from the usual cluster state query.

curl -XGET http://localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "myescluster",
  "status" : "red",
  "timed_out" : false,
  "number_of_nodes" : 20,
  "number_of_data_nodes" : 16,
  "active_primary_shards" : 2558,
  "active_shards" : 5628,
  "relocating_shards" : 0,
  "initializing_shards" : 4,
  "unassigned_shards" : 22
}  

This is all but good.

The status: red is a sign your cluster is missing some primary shards. It means some data are still completely missing. As a consequence, queries on these data will fail and indexing will take a tremendous amount of time. When all the primary shards are back, the cluster switches in yellow to warn you it’s still working but your data is present.

initializing_shards: 4 is what your cluster is currently doing: bringing back your data to life.

unassigned_shards: 22 is where your lost primary shards are. The more you have there, the more data you’re missing and the more conflict you’re likely to meet.

Baby come back, won’t you pleaaaase come back?

What happened there?

When a data node leaves the cluster and comes back, Elasticsearch will bring the data back and merge the records that may have been written during the time that node was away. Since there may be lots of new data, the process can take forever, even more when some shards fail at starting.

Let’s run another query to understand the cluster state a bit better.

curl -XGET http://localhost:9200/_cat/shards
t37       434 p STARTED 12221982  13.8gb 10.0.0.22   datanode02
t37       434 r STARTED 12221982  13.8gb 10.0.0.23   datanode03
t37       403 p INITIALIZING 21620252  28.3gb 10.0.0.22   datanode02
t37       404 p INITIALIZING 5720596    4.9gb 10.0.0.22   datanode02
t37       20  p UNASSIGNED
t37       20  r UNASSIGNED
t37       468 p INITIALIZING  8313898  12.3gb 10.0.0.22   datanode02
t37       470 p INITIALIZING  38868416 56.8gb 10.0.0.22   datanode02
t37       37  p UNASSIGNED
t37       37  r UNASSIGNED
t37       430 r STARTED 11806144  15.8gb 10.0.0.24   datanode04
t37       430 p STARTED 11806144  15.8gb 10.0.0.25   datanode05
t37       368 p STARTED 34530372    43gb 10.0.0.25   datanode05
t37       368 r STARTED 34530372    43gb 10.0.0.23   datanode03
...

This is indeed a sample of the real output, which is actually 5628 lines long. There’s a few interesting things here I want to show you.

Every line is under the same form.

The first field, t37, is the index name. This one is obviously called t37, and it has a huge number of primary shard to store the gazillon posts I’ve written over the years.

The second field is the shard number, followed by either p if the shard is a primary one, or r if it’s a replica.

The fourth field is the shard state. It’s either UNASSIGNED, INITIALIZING or STARTED. The first 2 states are the ones we’re insterested with. If I run the previous query | grep INITIALIZING and | grep UNASSIGNED, I’ll get 4 and 22 lines respectively.

If you need a fix…

First, let’s take care of the 22 unassigned shards since they’re the easiest to fix. What we’re going to do is force the shards allocation. Since we’re lazy, let’s do some scripting here.

for shard in $(curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk '{print $2}'); do
    curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
        "commands" : [ {
              "allocate" : {
                  "index" : "t37", 
                  "shard" : $shard, 
                  "node" : "datanode15", 
                  "allow_primary" : true
              }
            }
        ]
    }'
    sleep 5
done

What we’re doing here is forcing every unassigned shard allocation on datanode15. Depending on the shards size, you’ll probably have to assign them in various nodes. If you’re playing with very small shards, don’t worry, Elasticsearch will reallocate them for you once they’re up.

Let’s run the cluster health query again, will you?

curl -XGET http://localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "myescluster",
  "status" : "red",
  "timed_out" : false,
  "number_of_nodes" : 20,
  "number_of_data_nodes" : 16,
  "active_primary_shards" : 2568,
  "active_shards" : 5638,
  "relocating_shards" : 0,
  "initializing_shards" : 16,
  "unassigned_shards" : 0
}  

Great news, isn’t it? All our previously unassigned shards are now active or assigned. Unfortunately, things aren’t fixed yet.

I still haven’t found what I’m looking for

Let’s run that query once more a few minutes later.

curl -XGET http://localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "myescluster",
  "status" : "red",
  "timed_out" : false,
  "number_of_nodes" : 20,
  "number_of_data_nodes" : 16,
  "active_primary_shards" : 2580,
  "active_shards" : 5650,
  "relocating_shards" : 0,
  "initializing_shards" : 4,
  "unassigned_shards" : 0
}  

See? There are 4 shards still initializing. Guess what? I’m sure they’re the ones the first query already spotted. Let’s query the shard listing again.

curl -XGET http://localhost:9200/_cat/shards | grep INIT
t37       403 p INITIALIZING 21620252  28.3gb 10.0.0.22   datanode02
t37       404 p INITIALIZING 5720596    4.9gb 10.0.0.22   datanode02
t37       468 p INITIALIZING  8313898  12.3gb 10.0.0.22   datanode02
t37       470 p INITIALIZING  38868416 56.8gb 10.0.0.22   datanode02

Interesting isn’t it? Every stuck shard are on the same node. This is not really a surprise though.

If we try to run the reroute query, it will fail because the primary shard is not yet active.

[2015-01-25 11:45:14,569][DEBUG][action.admin.cluster.reroute] [masternode01] failed to perform [cluster_reroute (api)]
org.elasticsearch.ElasticsearchIllegalArgumentException: [allocate] allocation of [t37][403] on node [datanode02][uvM8ncAjTs2_HER9k6DMow][datanode02.t37.net][inet[/10.0.0.22:9300]]{master=false} is not allowed, reason: [YES(shard is not allocated to same node or host)][YES(node passes include/exclude/require filters)][NO(primary shard is not yet active)][YES(below shard recovery limit of [2])][YES(allocation disabling is ignored)][YES(allocation disabling is ignored)][YES(no allocation awareness enabled)][YES(total shard limit disabled: [-1] <= 0)][YES(no active primary shard yet)][YES(disk usages unavailable)][YES(shard not primary or relocation disabled)]
  at org.elasticsearch.cluster.routing.allocation.command.AllocateAllocationCommand.execute(AllocateAllocationCommand.java:221)
  at org.elasticsearch.cluster.routing.allocation.command.AllocationCommands.execute(AllocationCommands.java:119)
  at org.elasticsearch.cluster.routing.allocation.AllocationService.reroute(AllocationService.java:131)
  at org.elasticsearch.action.admin.cluster.reroute.TransportClusterRerouteAction$1.execute(TransportClusterRerouteAction.java:91)
  at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:328)
  at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:153)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:745)

Then, what can we do? Unfortunately not much except restarting the node. Hopefully there’s only one of them.

Tell me whyyyyyyyyy

You and me together, fighting for our cluster

If you’re asking, yes, I love Jimmy Sommerville, but that’s not the point.

There’s some literature about shards never initializing and cluster restart taking ages on the Web. From what I’ve understood, such a stuck state can be reached when some shards fail to start and nothing’s done about it. Unfortunately, I didn’t find anything in my logs related to the shards that were stuck, so I have no idea how it happened.

 

That’s all folks, this post about tracking and fixing your shard allocations issues is over. I hope you enjoyed reading it as much as I enjoyed spending my weekend trying to fix it. Next time, we’ll see how pink unicorns are your personal development worst ennemies. Stay tuned!

 

curl -XPOST 'localhost:9200/_cluster/reroute' -d '{"commands" : [ {"allocate" : {"index" : "weibo", "shard" : "1", "node" : "wz", "allow_primary" : true}}]}'

分享到:
评论

相关推荐

    unassigned.devices:用于unRAID的Unassigned Devices插件

    标题:“unassigned.devices:用于unRAID的Unassigned Devices插件” 这个插件是专门为unRAID操作系统设计的,旨在自动化管理和利用那些没有被unRAID阵列直接使用的硬件设备。unRAID是一款基于Linux的分布式存储...

    Elasticsearch性能优化汇总.docx

    ### Elasticsearch性能优化详解 #### 一、硬件选择与磁盘I/O优化 Elasticsearch的基础构建于Lucene之上,所有索引及文档数据均存储在本地磁盘中。磁盘性能直接影响Elasticsearch的性能表现,尤其是在高负载情况下...

    Elasticsearch集群健康值红色终极解决方案.docx

    ### Elasticsearch集群健康值红色终极解决方案 #### 一、集群状态解读与健康颜色含义 在Elasticsearch中,集群状态的颜色...通过上述步骤,可以有效地解决Elasticsearch集群健康值红色的问题,并确保系统的稳定运行。

    FLUENT 17.0启动不了问题解决方法

    ANSYS FLUENT 17.0 启动后,鼠标移动到按钮的地方一直转圈,tree 和 task page 不显示,启 动不成功,过一段时间会提示: Error:eval:unassigned variable Error Object:re-host 用 workbench 启动会提示错误——...

    ES HTTP操作

    Elasticsearch(简称ES)是一款基于Lucene的搜索服务器。它提供了一个分布式多租户能力的全文搜索引擎,使用RESTful Web接口。本文将详细介绍ES中常见的HTTP API操作,这些操作可以帮助开发者更好地理解和使用ES的...

    Fluent常见问题解决方法

    在使用Fluent进行流体动力学模拟时,经常会遇到各种问题,尤其是对于初学者和进阶用户来说。本文将探讨一些常见的问题及其解决方案。 首先,关于"wall-shadow"的概念。"wall-shadow"并非用户手动定义,而是Fluent...

    无线网络 信令事件解析

    当我们遇到“未分配的(未确定的)号码”(Unassigned (Unallocaled) Number)这个原因值时,意味着主叫方尝试呼叫的电话号码虽然格式正确,但是当前尚未分配给任何用户。这可能是由于号码还没有分配给新的用户,...

    fluent常见问题解答.pdf

    在处理对称问题时,正确设定边界条件可以减少计算域,提高效率。 在Gambit中,实体和虚体的使用可以帮助处理复杂模型,例如分割和组合不同的几何部分。温度分布的contour图可以帮助找到特定温度值的位置,这对于热...

    shell脚本批量删除es索引的方法

    在IT行业中,Elasticsearch(简称ES)是一个广泛使用的分布式搜索引擎,它提供了高效的数据存储、检索和分析功能。然而,随着时间的推移,系统中可能会积累大量的旧索引,这可能导致资源浪费,甚至影响到集群的性能...

    oracle dataguard 物理standby建立

    在Oracle数据库管理中,Data Guard是一项关键的高可用性和灾难恢复技术,它通过在主数据库(primary database)和一个或多个备用数据库(standby databases)之间复制数据,来确保数据的安全性和业务连续性。...

    地震su软件地应用

    * SEGYCLEAN:zero out unassigned portion of header。 * SEGYREAD:读SEG-Y磁带。 * SEGYHDRS:为segywrite构造SEG-Y文件的ascii和二进制头文件。 * SEGYWRITE:写SEG-Y磁带。 * SETBHED:设置一个SEGY二进制磁带...

    处理数据类型 [ Working with Datatypes ].pdf

    在Caché数据库开发中,处理数据类型是至关重要的,特别是在与JSON数据交互时。`%GetTypeOf()`方法是Caché提供的一种功能,用于获取动态实体(如动态对象属性或数组元素)的数据类型。这个方法能够帮助开发者识别并...

    unraid Community Applications 市场插件2022.11.10独立版本

    这通常涉及到将文件如"unassigned.devices"等拷贝到unraid系统的特定目录,然后通过控制面板执行离线安装操作。 **"unassigned.devices" 文件** "unassigned.devices" 文件很可能是一个配置或数据文件,用于在...

    ccna实验之帧中继 用的是繁荣模拟器

    Ethernet0/0 unassigned YES unset administratively down down Ethernet0/1 unassigned YES unset administratively down down Ethernet0/2 unassigned YES unset administratively down down Ethernet0/3 ...

    delphi操作中word提取doc内容和图片可转html

    WordApp := Unassigned; ``` 以上就是使用Delphi通过OLE操作Word提取内容和图片并转换为HTML的基本步骤。在实际项目中,你可能需要根据具体需求进行更复杂的逻辑处理,如错误处理、文件路径动态构建等。此外,由于...

    delphi7实现把xml格式导出excel格式

    在IT行业中,XML(eXtensible Markup Language)是一种被广泛用于存储和交换结构化数据的标准格式,而Excel则是Microsoft Office套件中的一个组件,主要用于处理电子表格。当我们需要将XML数据转换为Excel格式时,这...

    Delphi 将Excel表存入到html中的源码.rar

     ExApph := unassigned;  end  else  showmessage('请选择Excel表');  保存Excel文件的代码如下,完整源码请下载查看:  procedure TForm1.SpeedButton1Click(Sender: TObject);  begin  OpenDialog1.Filter...

    fluent 用户指导手册19.2

    fluent19.2用户知道手册,884页以及一些相应算例的压缩包

    激光辐射加热-fluent

    激光辐射加热技术是现代工程和科学研究中的一种重要手段,尤其在材料加工、热处理、生物医学等领域有着广泛的应用。在这些领域,利用计算机模拟工具如Fluent进行热力学分析是必不可少的。Fluent作为一款强大的流体...

Global site tag (gtag.js) - Google Analytics