一、基于version进行乐观锁并发控制

1)、查看一条document

GET /test_version/test_version_type/
{
"_index" : "test_version",
"_type" : "test_version_type",
"_id" : "",
"_version" : ,
"found" : true,
"_source" : {
"test_field" : "test test"
}
}

2)、模拟多并发下,利用version进行更新

同时带上数据的版本号,确保说,es中的数据的版本号,跟客户端中的数据的版本号是相同的,才能修改

PUT /test_version/test_version_type/?version=
{
"test_field": "test client 1"
} {
"_index" : "test_version",
"_type" : "test_version_type",
"_id" : "",
"_version" : ,
"result" : "updated",
"_shards" : {
"total" : ,
"successful" : ,
"failed" :
},
"_seq_no" : ,
"_primary_term" :
}
PUT /test_version/test_version_type/?version=
{
"test_field": "test client 2"
} {
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[test_version_type][1]: version conflict, current version [2] is different than the one provided [1]",
"index_uuid": "VT8uFhvTS_qawAksysahtQ",
"shard": "",
"index": "test_version"
}
],
"type": "version_conflict_engine_exception",
"reason": "[test_version_type][1]: version conflict, current version [2] is different than the one provided [1]",
"index_uuid": "VT8uFhvTS_qawAksysahtQ",
"shard": "",
"index": "test_version"
},
"status":
}

二、基于external version进行乐观锁并发控制

es提供了一个feature,就是说,你可以不用它提供的内部_version版本号来进行并发控制,可以基于你自己维护的一个版本号来进行并发控制。

1)、查看一条document

GET /test_version/test_version_type/
{
"_index" : "test_version",
"_type" : "test_version_type",
"_id" : "",
"_version" : ,
"found" : true,
"_source" : {
"test_field" : "test"
}
}

2)、语法与区别

?version=1
?version=1&version_type=external

version_type=external,唯一的区别在于,_version,只有当你提供的version与es中的_version一模一样的时候,才可以进行修改,只要不一样,就报错;当version_type=external的时候,只有当你提供的version比es中的_version大的时候,才能完成修改

3)、模拟多并发下,利用version进行更新

PUT /test_version/test_version_type/?version=&version_type=external
{
"test_field": "test client 1"
} {
"_index" : "test_version",
"_type" : "test_version_type",
"_id" : "",
"_version" : ,
"result" : "updated",
"_shards" : {
"total" : ,
"successful" : ,
"failed" :
},
"_seq_no" : ,
"_primary_term" :
}
PUT /test_version/test_version_type/?version=&version_type=external
{
"test_field": "test client 2"
} {
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[test_version_type][3]: version conflict, current version [2] is higher or equal to the one provided [2]",
"index_uuid": "VT8uFhvTS_qawAksysahtQ",
"shard": "",
"index": "test_version"
}
],
"type": "version_conflict_engine_exception",
"reason": "[test_version_type][3]: version conflict, current version [2] is higher or equal to the one provided [2]",
"index_uuid": "VT8uFhvTS_qawAksysahtQ",
"shard": "",
"index": "test_version"
},
"status":
}

ElasticSearch(九)基于version进行乐观锁并发控制的更多相关文章

  1. 21.实验基于_version进行乐观锁并发控制

    21.实验基于_version进行乐观锁并发控制 主要知识点: 实验基于_version进行乐观锁并发控制 1.实验实战演练基于_version进行乐观锁并发控制 (1)先构造一条数据出来 PUT / ...

  2. 关于Hibernate基于version的乐观锁

    刚刚接触SSH框架,虽然可能这个框架已经比较过时了,但是个人认为,SSH作为一个成熟的框架,作为框架的入门还是可以的. 马马虎虎学完了Hibernate的基础,总结一点心得之类的. 学习Hiberna ...

  3. 基于external version进行乐观锁并发控制

    ?version=1?version=1&version_type=external它们的唯一区别在于,_version,只有当你提供的version与es中的_version一模一样的时候, ...

  4. Elasticsearch学习笔记(八)Elasticsearch的乐观锁并发控制

    一.基于_version的乐观锁并发控制                 语法:PUT /test_index/test_type/id?version=xxx             更新时带上数据 ...

  5. 25.partial update内置乐观锁并发控制

    主要知识点     (1)partial update内置乐观锁并发控制 (2)retry_on_conflict post /index/type/id/_update?retry_on_confl ...

  6. 并发-AtomicInteger源码分析—基于CAS的乐观锁实现

    AtomicInteger源码分析—基于CAS的乐观锁实现 参考: http://www.importnew.com/22078.html https://www.cnblogs.com/mantu/ ...

  7. 6:Partial Update 内部原理 和 乐观锁并发控制

    Partial Update 内部执行过程: 首先,ES文档是不可变的,它们只能被修改,不能被替换.Update Api 也不例外. Update API 简单使用与之前描述相同的 检索-修改-重建索 ...

  8. AtomicInteger源码分析——基于CAS的乐观锁实现

    AtomicInteger源码分析——基于CAS的乐观锁实现 1. 悲观锁与乐观锁 我们都知道,cpu是时分复用的,也就是把cpu的时间片,分配给不同的thread/process轮流执行,时间片与时 ...

  9. 基于redis的乐观锁实践

    redis真是一个分布式应用场景下的好东西,对于我们的应用设计,功劳大大的! 今天要研究的是基于redis的事务机制以及watch指令(CAS)实现乐观锁的过程. 所谓乐观锁,就是利用版本号比较机制, ...

随机推荐

  1. bq25896 charging status CHRG_STAT register 0xB

    condition 1 :                    adapter 全部電流往 system去,                    battery current 也往 system ...

  2. getID3类的学习使用

    getID3类的学习使用 网上描述: getID3()这个PHP脚本能够从MP3或其它媒体文件中提取有用的信息如:ID3标签,bitrate,播放时间等. (格式包括:Ogg,WMA,WMV,ASF, ...

  3. ajax 分页(jquery分页插件pagination) 小例2

    封装成:myPagination.js// ajax分页 function sendAjax(flag, dataParam, url, callback) {//封装的ajax: var shus ...

  4. c#FileStream文件读写

    //C#文件流写文件,默认追加FileMode.Append             string msg = "okffffffffffffffff";            b ...

  5. 富文本ZSSRichTextEditor之趟坑集锦

    富文本ZSSRichTextEditor是iOS原生与网页交互的集大成者,各种交互.自然问题也是多多,这篇文文章陆续更新遇到的奇葩问题. 1.问题1:从头条这种文章里头复制粘贴的文章,里边有图片,我们 ...

  6. 字蛛(font-spider)-单独压缩字体(解决页面少有的特殊字体的字体包引用)

    特别想独立的把这个问题写成一篇内容,分享给大家. 反正我是这个字体压缩使用的受益者,不是打广告. 很久以前,设计师总是爱用一些奇奇怪怪的字体放在页面上,而作为前端我们很容易的就能直接使用TA们用到的字 ...

  7. Manajro17配置

    :Manjaro近来点击率一直排行第一,比较适合笔记本使用,这次从下载刻录开始讲述: 1: 下载刻录 因为一些环境特殊原因,官网下载还是比较慢的,普通用户还是从清华镜像源下载比较快,当然你也可以选择官 ...

  8. mac 安装opencv-python

    Mac下安装opencv-python 项目中使用的是opencv 2的版本,因此下面说一下opencv2的一些安装流程. 安装方法 1:如果没有homebrew的话,需要先安装 安装命令: ruby ...

  9. Maven教程:tutorialspoint-maven

    来自turorialspoint的Maven教程(英文),官网:http://www.tutorialspoint.com/maven/index.htm 这个教程在国内已经被翻译成中文,官网:htt ...

  10. [IOS笔记] - 动画animation

    //移动 - (IBAction)translation:(id)sender { CABasicAnimation *traslation = [CABasicAnimation animation ...