ElasticSearch 5.3原始碼學習 —— Cluster State 欄位詳解

jxy發表於2018-02-20

背景

  • ES採用事件模型進行狀態變更,其ClusterState為其唯一持久化的叢集狀態資訊。

欄位詳解

  • ES 5.3的ClusterState如下所示,主要分為
    • routingTable - 路由表
    • nodes - 節點資訊
    • metaData - 後設資料,也可以有custom擴充套件
    • blocks - 系統限制
    • customs - 自定義專案,如snapshots,可用外掛擴充套件
  • 下面就具體以例項說明下每個值的具體作用,在叢集中GET _cluster/state即可看見
{
  "cluster_name": "elasticsearch",
  "version": 158326,
  "state_uuid": "iYcpseRmQYmacnkkfZHsjg",
  "master_node": "WychrvtFSFiZpChp0ElnVw",
  "blocks": {
    "global": { // 全侷限制
      "1": {  // 限制id,所有block型別見附錄
        "description": "state not recovered / initialized",
        "retryable": true, //是否重試,如果為true則會監聽state變化,在發生變化時自動重試
        "disableStatePersistence": true, //為true將會清空之前持久化資料
        "levels": [ // 限制的專案,一共有讀,寫,後設資料讀,後設資料寫四種
          "read",
          "write",
          "metadata_read",
          "metadata_write"
        ]
      }
    },
    "indices": { //索引級別的限制
      "xxx": {
        "4": {
          "description": "index closed",
          "retryable": false,
          "levels": [
            "read",
            "write"
          ]
        }
      }
    }
  },
  "nodes": { //節點詳細資訊
    "9WPdZv8ESIS9_jWv26Dogw": {
      "name": "f1dba2f9-48c8-5896-97e2-983a520f1757",
      "ephemeral_id": "jbV855g3QQKj8_wpeWr3Jg",
      "transport_address": "1.2.3.4:9300",
      "attributes": {
        "box_type": "hot"
      }
    }
  },
  "metadata": { //後設資料
    "cluster_uuid": "jsWIOmkxQgCkmxN5_baWmg",
    "templates": {}, //模板
    "indices": {
      "test": {
        "state": "open",
        "settings": {},
        "mappings": {},
        "aliases": [],
        "primary_terms": { 
          "0": 13 //代表這個shard的primary切換的次數,用於區分新舊primary
        },
        "in_sync_allocations": {
          "0": [ // 擁有最新資料的allocation,如果primary丟失,就從這個列表裡選出個新的主.如果節點恢復,並且其id仍在這個列表中,則認為資料沒有缺少,不做恢復。當副本沒有返回ack時,primary會通知master將其從這個列表中移除,等其再返回全部ack後再加上。因此網路抖動可能造成master大量壓力
            "yxSi6kjZQC2I3LhwNbOdIQ", 
            "xNMX9KECSm6Au3Q4R-NoQA"
          ]
        }
      }
    },
    "ingest": {},//ingest的pipeline資料
    "index-graveyard": {
      "tombstones": [ //刪掉的索引的墓碑,預設500個,防止node回來時不知道索引已經刪掉了
        {
          "index": {
            "index_name": "append_only_sc_template_record.2017-11-25",
            "index_uuid": "woWP1c_iQs-M3HHUR1XOJQ"
          },
          "delete_date_in_millis": 1512921691703
        }
      ]
    }
  },
  "routing_table": { //每個shard的具體路由資訊
    "indices": {
      "test": {
        "shards": {
          "0": [
            {
              "state": "STARTED", //共有四種狀態,UNASSIGNED,INITIALIZING,STARTED,RELOCATING
              "primary": true,
              "node": "9WPdZv8ESIS9_jWv26Dogw",
              "relocating_node": null, //如果為relocating狀態,這個值表示relocating的目標機器
              "shard": 0,
              "index": "test",
              "allocation_id": {
                "id": "yxSi6kjZQC2I3LhwNbOdIQ" //當前allocation的uid,和in_sync_allocations對應
              }
            },
            {
              "state": "UNASSIGNED",
              "primary": false,
              "node": null,
              "relocating_node": null,
              "shard": 0,
              "index": "test",
              "recovery_source": { //恢復源,EMPTY_STORE,EXISTING_STORE,PEER,SNAPSHOT,LOCAL_SHARDS五種
                "type": "PEER"
              },
              "unassigned_info": {
                "reason": "CLUSTER_RECOVERED",
                "at": "2017-09-27T03:26:36.488Z",
                "delayed": false,
                "allocation_status": "no_attempt"
              }
            }
          ]
        }
      }
    }
  },
  "routing_nodes": { //這個就是把routing_table按照node重新整理了一下
    "unassigned": [
      {
        "state": "UNASSIGNED",
        "primary": false,
        "node": null,
        "relocating_node": null,
        "shard": 0,
        "index": "test",
        "recovery_source": {
          "type": "PEER"
        },
        "unassigned_info": {
          "reason": "CLUSTER_RECOVERED",
          "at": "2017-09-27T03:26:36.488Z",
          "delayed": false,
          "allocation_status": "no_attempt"
        }
      }
    ],
    "nodes": {
      "9WPdZv8ESIS9_jWv26Dogw": [
        {
          "state": "STARTED",
          "primary": true,
          "node": "9WPdZv8ESIS9_jWv26Dogw",
          "relocating_node": null,
          "shard": 0,
          "index": "test",
          "allocation_id": {
            "id": "yxSi6kjZQC2I3LhwNbOdIQ"
          }
        },
        {
          "state": "STARTED",
          "primary": false,
          "node": "9WPdZv8ESIS9_jWv26Dogw",
          "relocating_node": null,
          "shard": 0,
          "index": "test",
          "allocation_id": {
            "id": "xNMX9KECSm6Au3Q4R-NoQA"
          }
        }
      ]
    }
  }
}
複製程式碼

附錄

  • ClusterBlock 列表
Block Name id
STATE_NOT_RECOVERED_BLOCK 1
NO_MASTER_BLOCK_ALL 2
NO_MASTER_BLOCK_WRITES 2
INDEX_CLOSED_BLOCK 4
INDEX_READ_ONLY_BLOCK 5
CLUSTER_READ_ONLY_BLOCK 6
INDEX_READ_BLOCK 7
INDEX_WRITE_BLOCK 8
INDEX_METADATA_BLOCK 9
TRIBE_METADATA_BLOCK 10
TRIBE_WRITE_BLOCK 11

參考資料

相關文章