一、問題描述
這次遇到的問題比較特殊,嘗試過以下幾種手段都沒有恢復:
-
_cluster/reroute手動分片shard
- 由于是從shard無法分片,所以當時試過將所以的副本改成0,然后再設置成1,想通過重新生成副本來解決,結(jié)果也失敗
接下來是排查問題的過程:
indexname 3 r UNASSIGNED indexname 4 r UNASSIGNED indexname 1 r UNASSIGNED
之前在運維過程中也遇到過UNASSIGNED這種從shard無法分配的問題,通過"allocate_replica"命令手動分配可以解決,這類問題一般都是因為node節(jié)點重啟或者失聯(lián)導致的shard分片異常
2、通過“GET _cluster/allocation/explain”錯誤信息如下:
"index": "indexname", "shard": 3, "primary": false, "current_state": "unassigned", "unassigned_info": { "reason": "ALLOCATION_FAILED", "at": "2023-11-02T18:43:14.758Z", "failed_allocation_attempts": 300, "details": "failed shard on node [4MMOUt8-SMatWGCzX1asAQ]: failed to create shard, failure IOException[failed to obtain in-memory shard lock]; nested: ShardLockObtainFailedException[[indexname][3]: obtaining shard lock timed out after 5000ms]; ", "last_allocation_status": "no_attempt" }, "can_allocate": "no", "allocate_explanation": "cannot allocate because allocation is not permitted to any of the nodes",
大多數(shù)情況下shard的allocate相關(guān)的問題都可以通過“GET _cluster/allocation/explain”命令獲取到有用的關(guān)鍵信息,從返回的內(nèi)容來分析是索引的第3個shard導致的,在node節(jié)點[4MMOUt8-SMatWGCzX1asAQ]被鎖定。
二、處理過程
前置工作
- 業(yè)務將索引的讀寫請求切走
- 創(chuàng)建一個測試索引驗證shard是否都正常
- 備份索引數(shù)據(jù)
方案1:重啟索引
--刷新索引 POST indexname/_flush --關(guān)閉索引 POST indexname/_close ---打開索引 POST indexname/_open
在本次處理過程中,使用了方案1重啟索引就已經(jīng)把問題解決了,但是方案一還是的業(yè)務配合將讀寫請求切走,否則索引close會導致應用的請求報錯
方案2:重啟節(jié)點node節(jié)點
[4MMOUt8-SMatWGCzX1asAQ]
PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "none" } } PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } }
方案2重啟鎖定shard的節(jié)點理論上來說也是可以解決這個問題,但是因為方案一已經(jīng)解決了問題就沒機會做測試
方案3.重建索引
- 先還原備份到一個臨時索引,驗證數(shù)據(jù)沒問題
- 刪除當前索引,還原創(chuàng)建新索引
三、思考總結(jié)
其實整個問題處理過程中還有一些其它的細節(jié)在文中沒有提到,集群在默認開啟自動shard均衡過程中由于shard多次嘗試分配無法成功,達到默認的5次重試之后就會報錯,這個時候其實可以嘗試將集群的自動分片關(guān)閉"cluster.routing.allocation.enable": "none",然后執(zhí)行"POST /_cluster/reroute?retry_failed=true"來重置計數(shù),最后通過手動分片shard的方式來做遷移也有可能能解決問題。只不過在每次遇到問題的時候需要結(jié)合當時的最佳場景去做判斷,尋找影響范圍最小的方案;?
備注: ??? 作者:pursuer.chen ??? 博客:http://www.cnblogs.com/chenmh 本站點所有隨筆都是原創(chuàng),歡迎大家轉(zhuǎn)載;但轉(zhuǎn)載時必須注明文章來源,且在文章開頭明顯處給明鏈接。文章來源:http://www.zghlxwxcb.cn/news/detail-745939.html 《歡迎交流討論》文章來源地址http://www.zghlxwxcb.cn/news/detail-745939.html |
到了這里,關(guān)于記錄ElasticSearch分片被鎖定導致無法分配處理過程的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!