ES學習筆記2-理論進階篇1

分佈式文檔存儲

routing a document to a shard

shard = hash(routing) % number_of_primary_shards
routing value default is document's _id

how primary and replica shards interact


我們可以發送請求到集羣中的任何節點。每個節點完全有能力任何請求服務。每個節點都知道集羣中的每個文檔的位置,所以可以直接請求轉發到所需的節點。在下面的例子中,我們將我們所有的請求發送到節點1,我們將稱之爲請求節點。

When sending requests, it is good practice to round-robin through all the nodes in the cluster, in order to spread the load.

creating, indexing, and deleting a document

上邊所有的操作都是寫操作,所以必須要再主分片上進行成功之後再同步到複製分片


1.請求發送到master節點。更新文檔存在的shard爲P0。

2。master節點知道P0存在於NODE3所以將請求轉發給node3.

3。node3更新文檔後,複製更新後的文檔到NODE2,與NODE1的複製分片。當複製成功之後,返回請求成功

請求參數設置

replication sync|async 同步或異步複製,默認同步

consistency(數據一致性) 主分片需要一些複製分片來保證數據一致性(不是所有複製分片,因爲有些複製分片所存在的節點網絡不通) 選項爲 one(只有主分片)|all(所有分片)|quorum(指定複製分片個數)

一個主分片的默認一致性複製分片個數爲int( (primary + number_of_replicas) / 2 ) + 1 

timeout 如果沒有滿足複製分片的個數,請求將等待 默認1分鐘 1分鐘之後請求超時  100 is 100 milliseconds, and 30s is 30 seconds.



A new index has 1 replica by default, which means that two active shard copies shouldbe required in order to satisfy the need for a quorum. However, these default settings would prevent us from doing anything useful with a single-node cluster. To avoid this problem, the requirement for a quorum is enforced only when number_of_replicas is greater than 1.

重新取回文檔

For read requests, the requesting node will choose a different shard copy on every request in order to balance the load; it round-robins through all shard copies.

partial update a document


1.請求發送到master節點。master節點通過計算hash值發現此文檔屬於shard0 

2.將請求轉發到Node3

3.從P0主分片中取出文檔,更新文檔

4.複製更新後的文檔到複製分片。

多文檔模式。

因爲ES知道每個文檔所存在的節點與分片,請求將會以分片的形式分組(每一組請求都屬於同一個主分片),最後將分組後的請求一併轉發到node上


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章