elasticsearch学习笔记(十五)——Elasticsearch partial update内置乐观锁并发控制

Elasticsearch partial update内置了乐观锁并发控制机制。一样是基于_version(新版本更新为if_seq_no和if_primary_term)进行乐观锁的并发控制。详细请看:https://segmentfault.com/a/11...
这里多提一点就是使用partial update有一个参数叫retry_on_conflict,也就是能够基于retry策略:segmentfault

咱们回顾一下以前说的乐观锁并发控制策略
在高并发更新数据时,它基于最新的数据和if_seq_no,if_primary_term进行修改,可能这个过程会须要反复执行好几回,才能成功,特别是在多线程并发更新同一条数据很频繁的状况下。
而partial update就是在此基础上添加了一个参数retry_on_conflict,能够设置最多重复的次数。
示例:多线程

POST /test_index/_update/3?retry_on_conflict=5
{
  "doc": {
    "test_field1": "update test1"
  }
}
GET /test_index/_doc/3
{
  "_index" : "test_index",
  "_type" : "_doc",
  "_id" : "3",
  "_version" : 3,
  "_seq_no" : 2,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "test_field1" : "update test1",
    "test_field2" : "update test2"
  }
}
相关文章
相关标签/搜索