日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

15.concurrent-control并发控制

發布時間:2024/2/28 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 15.concurrent-control并发控制 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

    • 1. 基于樂觀鎖的并發控制

1. 基于樂觀鎖的并發控制

Elasticsearch是分布式的。創建,更新或刪除文檔時,必須將文檔的新版本復制到群集中的其他節點。 Elasticsearch也是異步和并發的,這意味著這些復制請求是并行發送的,并且可能不按順序到達其目的地。 Elasticsearch需要一種方法來確保文檔的old version永遠不會覆蓋 a newer version。

為確保文檔的較舊版本不會覆蓋較新的版本,對文檔執行的每項操作均由主分片分配一個sequence number(序號),來協調更改。每次操作都會增加sequence number 序列號,因此可以確保較新的操作具有比較舊的操作更高的序列號。然后,Elasticsearch可以使用操作的序列號來確保分配給它的序列號較小的更改不會覆蓋較新的文檔版本。

For example, the following indexing command will create a document and assign it an initial sequence number and primary term:

舉例,如下的index操作create一個doc并賦予一個初始的sequence number和primary term

PUT products/_doc/1567 {"product" : "r2d2","details" : "A resourceful astromech droid" }{"_shards" : {"total" : 2,"failed" : 0,"successful" : 1},"_index" : "products","_type" : "_doc","_id" : "1567","_version" : 1,"_seq_no" : 362,"_primary_term" : 2,"result" : "created" }

Elasticsearch會跟蹤上次操作的sequence number序列號和primary term,。sequence number序列號和primary term會在GET API的響應中的_seq_no和_primary_term字段中返回:

GET products/_doc/1567returns:{"_index" : "products","_type" : "_doc","_id" : "1567","_version" : 1,"_seq_no" : 362,"_primary_term" : 2,"found": true,"_source" : {"product" : "r2d2","details" : "A resourceful astromech droid"} }

但是search api中默認不會返回,你可以通過一些設置來讓他返回。
Note: The Search API can return the _seq_no and _primary_term for each search hit by setting seq_no_primary_term parameter.

sequence number序列號和primary term唯一的標識了一次change。通過記下返回的序列號和主要術語,可以確保僅在從你的search 請求拿到對應的doc之后到你要對其做修改之前,沒有任何人對該文檔做過修改,在這種情況下你的修改才更改該文檔。這可以通過設置Index API或Delete API的if_seq_no和if_primary_term參數來完成。

For example, the following indexing call will make sure to add a tag to the document without losing any potential change to the description or an addition of another tag by another API:

PUT products/_doc/1567?if_seq_no=362&if_primary_term=2 {"product" : "r2d2","details" : "A resourceful astromech droid","tags": ["droid"] }

總結

以上是生活随笔為你收集整理的15.concurrent-control并发控制的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。