• Elasticsearch之CURL命令的version控制


      普通关系型数据库使用的是(悲观并发控制(PCC))

        当我们在修改一个数据前先锁定这一行,然后确保只有读取到数据的这个线程可以修改这一行数据

      

      ES使用的是(乐观并发控制(OCC))  

        ES不会阻止某一数据的访问,然而,如果基础数据在我们读取和写入的间隔中发生了变化,更新就会失败,这时候就由程序来决定如何处理这个冲突。它可以重新读取新数据来进行更新,又或者将这一情况直接反馈给用户。

      ES如何实现版本控制(使用es内部版本号)

        1)首先得到想要修改的文档,获取版本version号

    curl -XGET http://master:9200/zhouls/user/2

    [hadoop@master elasticsearch-2.4.0]$ curl -XGET http://master:9200/zhouls/user/2
    {"_index":"zhouls","_type":"user","_id":"2","_version":1,"found":true,"_source":{"name" : "john"  , "age" : 28}}[hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 

        2)在执行更新操作的时候把版本号传过去

    curl -XPUT http://master:9200/zhouls/user/2?version=1  -d  '{"name" : "john1" , "age" : 29}'

     

    [hadoop@master elasticsearch-2.4.0]$ curl -XPUT http://master:9200/zhouls/user/2?version=1  -d  '{"name" : "john1" , "age" : 29}'
    {"_index":"zhouls","_type":"user","_id":"2","_version":2,"_shards":{"total":2,"successful":2,"failed":0},"created":false}[hadoop@master elasticsearch-2.4.0]$ 

     

     

    curl -XPOST http://master:9200/zhouls/user/2/_update?version=2  -d  '{"doc" :{"age" : 30}}'

     

    [hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=2  -d  '{"doc" :{"age" : 30}}'
    {"_index":"zhouls","_type":"user","_id":"2","_version":3,"_shards":{"total":2,"successful":2,"failed":0}}[hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 

     

     

       

       3)如果传递的版本号和待更新的文档的版本号不一致,则会更新失败。

      现在,待更新文档的版本号是3。我分别传1和穿4进入,都会报更新失败。如下

    [hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=2  -d  '{"doc" :{"age" : 30}}'
    {"_index":"zhouls","_type":"user","_id":"2","_version":3,"_shards":{"total":2,"successful":2,"failed":0}}[hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=1  -d  '{"doc" :{"age" : 30}}'
    {"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [1]","index":"zhouls","shard":"2"}],"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [1]","index":"zhouls","shard":"2"},"status":409}[hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=4  -d  '{"doc" :{"age" : 30}}'
    {"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [4]","index":"zhouls","shard":"2"}],"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [4]","index":"zhouls","shard":"2"},"status":409}[hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 

      更多,请见

    Elasticsearch笔记三之版本控制和插件

  • 相关阅读:
    [原]【实例化需求】1.FitNesse工具应用简介
    [原][问题解决]常见问题的5种解决办法(由Jenkins问题解决谈起)
    [原][自动化测试]Robot Framework Selenium基本使用
    [原]好玩的Linux,关于时间cal命令
    [原][问题解决]Romote Control 图形化界面显示问题解决办法
    【SBE】由需求管理谈起
    [Robot]关于robot的几个学习网站
    coolite中在UserControl中使用Coolite.AjaxMethods方法
    javascript实现页面加载进度条(转)
    coolite 在前台更新Window中控件的值
  • 原文地址:https://www.cnblogs.com/zlslch/p/7101947.html
Copyright © 2020-2023  润新知