提问:布和纸怕什么?

bulk同时写入和更新问题【version conflict和document missing】

Elasticsearch | 作者 caoweixiong | 发布于2020年07月06日 | 阅读数:4385

【环境信息】:
es版本:6.2.5
canal:1.1.4
Kafka:2.11-1.0.0
 
【业务描述】:
 使用canal把mysql中订单表的数据同步到es。canal把订单表数据写入kafka的一个主题中,利用Kafka分区来确保按顺序处理所有更新同一ES文档的消息。一条订单记录有3次操作(1次Insert、2次Update),使用Bulk按顺序批量写入到ES中时,
【偶尔】会报以下2种错误:
DocumentMissingException[[order][D202007021531220000001]: document missing]
【或】
version conflict, current version [3] is different than the one provided [2]]

【原因分析】:
我初步分析的原因是:Insert后,还没有转换成Segment,马上Update,找不到这条记录。

哪位能给点思路或解决方法。我怎样才能解决这个问题?我需要遵循某种“同步”或“锁定”概念吗? 谢谢。
 
 
【补充】:
1、使用canal-adapter来消费kafka中的数据往es插入;
2、kafka中的主题使用的是单分区;
3、是用id操作ES的curd的,es中的_id存在的【订单号】;
 
1.png 2.png
已邀请:

caoweixiong

赞同来自: yilongchuan

因为是使用canal-adapter往es写入数据,通过查看其源码,已找到问题原因,是我canal-adapter没配置好导致的,现已解决,谢谢各位的意见。
 
具体原因:
因为有多个表,映射了多个主题,配置的时候没有指定key,这样初始化出来的es相关的实例都是同一个,使用就出问题了。
 
修改后的配置如下:
  canalAdapters:
- instance: db1-merchant-receipt-mpop-basic-stpprdinf # canal instance Name or mq topic name
groups:
- groupId: db1stpprdinf
outerAdapters:
- name: es
[b]key: db1stpprdinfKey[/b]
hosts: 172.xxx.xxx.2:4026
properties:
cluster.name: log-cluster
- instance: db1-merchant-receipt-mpop-basic-stppayinf # canal instance Name or mq topic name
groups:
- groupId: db1stppayinf
outerAdapters:
- name: es
[b]key: db1stppayinfKey
[/b] hosts: 172.xxx.xxx.2:4026
properties:
cluster.name: log-cluster
- instance: db2-merchant-receipt-mpop-basic-stpprdinf # canal instance Name or mq topic name
groups:
- groupId: db2stpprdinf
outerAdapters:
- name: es
[b]key: db2stpprdinfKey[/b]
hosts: 172.xxx.xxx.2:4026
properties:
cluster.name: log-cluster
- instance: db2-merchant-receipt-mpop-basic-stppayinf # canal instance Name or mq topic name
groups:
- groupId: db2stppayinf
outerAdapters:
- name: es
[b]key: db2stppayinfKey
[/b] hosts: 172.xxx.xxx.2:4026
properties:
cluster.name: log-cluster

tacsklet - 公司有用到es

赞同来自:

version conflict, current version [3] is different than the one provided [2]]
这个意思是当前version是3,但是你传过来的version是2,确定传输顺序是和原始顺序一样的吗,写数据是同步的还是异步的,有没有重试机制。

FFFrp

赞同来自:

有事务么

machuan11

赞同来自:

你理解的这个错误原因不对, 这是你更新的时候,拿到要更新的doc的版本在你更新之前又被更新过了。

pony_maggie - 公众号:犀牛饲养员的技术笔记

赞同来自:

看问题描述应该是更新顺序乱了导致的,建议贴出部分代码看看,只看你的描述没法确定顺序一定是对的

要回复问题请先登录注册