iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 4
2
Elastic Stack on Cloud

喬叔帶你上手Elastic Stack系列 第 4

喬叔教 Elastic - 04 - Index 建立前你該知道的 (1/5) - ES Index 如何被建立

Index 建立前你該知道的 系列文章索引


前言

當我們建立好一個 Elastic Cloud 的 Deployment 之後,下一步就是要建立 Index,但是 Index 建立時的底層是如何運作的呢?

進入此章節的先備知識

  • 初步了解 Elasticsearch 的 Cluster 與 Shards。

此章節的重點學習

  • Elasticsearch 的 Index 是如何被建立,在 Cluster 中是如何運作。

Elasticsearch Index 的建立

假設有一組擁有 4 個 Nodes 的 Elasticsearch Cluster:

  • index: a, shard: 2, replica: 1 (有 a0, a1 兩個深色的 primary shard, 另各有一份白底的 replica shard)
  • index: b, shard: 3, replica: 1 (有 b0, b1, b2 三個深色的 primary shard, 另各有一份白底的 replica shard)

es-node

當我們要建立一個新的 Index c 時,Elasticsearch 會執行以下幾個檢查的步驟:

Shard 分配決策者 (Allocation Deciders)

  1. 計算每個 node 身上的 shard 數量,盡可能的以數量來平均分配,決定新的 primary shard 要放在哪個 node 身上。
  2. 檢查是否有些 filter 條件,例如當 node 有宣告 hot/warm architecture 的 attribute 時,會過濾掉不應該被存放的 nodes,例如新的資料只能被放在有宣告 hot attribute 的 node 身上。

image-20200915024738494

  1. 檢查磁碟空間是否充足,如果已達到 cluster.routing.allocation.disk.watermark.low 設定的水位,則不會將新的 shard 放在該 node 身上。

image-20200915023728618

  1. 檢查是否有設定 Throttling,例如 indices.recovery.concurrent_small_file_streamsindices.recovery.concurrent_file_streams 的設置是否達到,而是否要暫緩目前 create index 的動作。

Primary Shard 初始化

若 Shard Allocation Decider 一切順利,將會進行 Primary Shard 的初始化:

  1. 在 Cluster 狀態中,標示這個 Index 的 Primary Shard 會被分派到哪個 node 身上,並標示狀態為 Initializing
  2. 該 Index 存在的 node 收到動工的通知後,開始建立空白的 Lucene index,並且回報 Cluster master node 處理完成。
  3. Cluster master node 收到處理完成時,會將這個 shard 的狀態標示為 started,並且通知 cluster 中的大家這個狀態,而這個存在此 pirmary shard 的 node 也收到 master node 的通知時,就會將這個 shard 的狀態設定成 started,這時就能提供 indexing 的處理了。

Replica Initialization

當我們 Primary Shard 正常運作之後,Cluster 會檢查目前 replica 的設定是否滿足,若是有需要執行 replica 的複制則進行下列步驟:

  1. 決定 shard 應該放在哪一個 node 身上,通知這個 node 要做事,並且標示這個 shard 為 Initializing
  2. 收到通知的 node 為此 shard 建立空白的 Lucene index。
  3. 一律從 primary shard 複制資料到 replica shard,並且在完成之後通知 master node。
  4. Master node 將這個 shard 的狀態改為 started,並且通知 cluster 中的大家。
  5. 收到 master node 通知時,存放 replica shard 的 node,將 shard 的狀態開啟提供服務。

到此階段,這個 Index 算是完成了被建立的這個流程,也開始能正常的提供服務了,下一步就是將要 indexing 進 Elasticsearch 的文件準備好吧!

參考資料


查看最新 Elasticsearch 或是 Elastic Stack 教育訓練資訊: https://training.onedoggo.com
歡迎追蹤我的 FB 粉絲頁: 喬叔 - Elastic Stack 技術交流
不論是技術分享的文章、公開線上分享、或是實體課程資訊,都會在粉絲頁通知大家哦!

此系列文章已整理成書
喬叔帶你上手 Elastic Stack:Elasticsearch 的最佳實踐與最佳化技巧
書中包含許多的修正、補充,也依照 Elastic 新版本的異動做出不少修改。
有興趣的讀書歡迎支持! 天瓏書局連結
喬叔帶你上手 Elastic Stack:Elasticsearch 的最佳實踐與最佳化技巧


上一篇
喬叔教 Elastic - 03 - Elastic Cloud 如何建立 Deployment (2/2) - 配置的選擇
下一篇
喬叔教 Elastic - 05 - Index 建立前你該知道的 (2/5) - ES 的超前佈署 - Dynamic Mapping
系列文
喬叔帶你上手Elastic Stack31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言