诊断

  1. GET _cat/indices/threatevent
  2. GET _cat/shards/threatevent
  3. GET _cluster/allocation/explain
  4. GET /_cluster/allocation/explain
  5. {
  6. "index": "threatevent",
  7. "shard": 3,
  8. "primary": true
  9. }

https://blog.csdn.net/laoyang360/article/details/109699085

修复方案

REOPEN 分片

  1. [root@sh ~]# curl -s -XPOST localhost:9200/Twitter/_close?pretty
  2. {
  3. "acknowledged": true
  4. }
  5. [root@sh ~]# curl -s -XPOST localhost:9200/Twitter/_open?pretty
  6. {
  7. "acknowledged": true,
  8. "shards_acknowledged": true
  9. }

分配陈腐分片

如果 reopen 索引无法使分片上线, 则需要考虑使用 reroute API 分配 stale primary. 执行这个 API 之前, 我们需要得到一些信息:
索引名称和分片 ID 可以通过 explain API 直观看到;
节点名称可以通过 unassigned_info.details 得到.
根据这些信息, 我们就可以执行 reroute API 了

  1. [root@sh ~]# curl -s -H "Content-Type:application/json" -XPOST "localhost:9200/_cluster/reroute?pretty" -d '
  2. {
  3. "commands": [
  4. {
  5. "allocate_stale_primary": {
  6. "index": "{索引名称}",
  7. "shard": "{分片 ID}",
  8. "node": "{节点名称}",
  9. "accept_data_loss": true
  10. }
  11. }
  12. ]
  13. }

丢弃分片

如果分配陈腐的分片也无法使分片上线, 为了不影响索引读写请求, 就只能丢弃掉损坏的分片了, 这是最糟糕的情况(会造成数据丢失):

  1. [root@sh ~]# curl -s -H "Content-Type:application/json" -XPOST "localhost:9200/_cluster/reroute?pretty" -d '
  2. {
  3. "commands" : [
  4. {
  5. "allocate_empty_primary" : {
  6. "index" : "{索引名称}",
  7. "shard" : "{分片 ID}",
  8. "node" : "{节点名称}",
  9. "accept_data_loss": true
  10. }
  11. }
  12. ]
  13. }'

部分已知问题

TranslogCorruptedException

https://blog.csdn.net/jiao_fuyou/article/details/79997292

corrupt_index_exception

https://blog.csdn.net/mincong_h/article/details/118884460