ElstaticSearch基于version的并发控制

1.基于version的控制,只有当version的版本号一致时,才允许更新。

例如:
1.先建立一条数据:

PUT /test_index/test_type/7
  {
  "test_field":"test"
   }

2.开启两个kibana客户端:
第一个客户端先执行更新操作:

  PUT /test_index/test_type/7**?version=1**
      {
      "test_field":"test_client 1"
       }
第二个客户端也执行相应的操作:
   put test_index/test_type/7**?version=1**
  {
  "test_field":"test_client 2"
   }

发现报错了:

 {
  "error": {
    "root_cause": [
      {
        "type": "version_conflict_engine_exception",
        "reason": "[test_type][7]: version conflict, current version [2] is different than the one provided        [1]",
        "index_uuid": "ZZuYYEO3QPShE9Se_sEpfw",
        "shard": "3",
        "index": "test_index"
      }
    ],
    "type": "**version_conflict_engine_exception**",
    "reason": "**[test_type][7]: version conflict, current version [2] is different than the one provided [1]**",
    "index_uuid": "ZZuYYEO3QPShE9Se_sEpfw",
    "shard": "3",
    "index": "test_index"
  },
  "status": 409
}

第二个客户端更新时,开始不知道别人修改了数据,也用version=1修改

但是出现版本冲突的错误,所以这时需要重新查询版本号,在更新

put test_index/test_type/7**?version=2**
{
  "test_field":"test_client 2"
}

这时候就更新成功了。

2.使用version控制并发,也可以加上 version_type=external

例如这样:
当前的version=3
put test_index/test_type/7**?version=4&version_type=external**
{
“test_field”:”test_client 3”
}
与纯version控制并发操作不同的是,加上version_type=external之后
version的值要大于当前的版本号,才能执行成功。

以上就是ElstaticSearch对于并发的控制策略,上述就是我所有实践的例子,有什么问题,欢迎指正。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值