alibaba / canal

阿里巴巴 MySQL binlog 增量订阅&消费组件
Apache License 2.0
28.36k stars 7.59k forks source link

Adapter 1.1.6 MYSQL增量同步ES NullPointerException异常 #4195

Closed yuyoyth closed 2 years ago

yuyoyth commented 2 years ago

environment

Issue Description

实现mysql 8的*库的xxx表增量同步至es7索引xxx

Steps to reproduce

adapter application.yml部分配置:

  srcDataSources:
    dbconfig1:
      url: jdbc:mysql://*.*.*.*:*/*?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
      username: *
      password: *
  canalAdapters:
  - instance: example # canal instance Name or mq topic name
    groups:
    - groupId: g1
      outerAdapters:
      - name: logger
      - name: es7
        hosts: http://*.*.*.*:* # 127.0.0.1:9200 for rest mode
        properties:
          mode: rest # or rest
          security.auth: *:* #  only used for rest mode
          cluster.name: *

增量同步表的配置文件es7/xxx.yml:

dataSourceKey: dbconfig1
destination: example
groupId: g1
esMapping:
  _index: xxx
  _id: id
  upsert: true
#  pk: id
  sql: "select id,alias,plus_code,kexin_plus_code,code,code_sqjw,is_settle,is_temp,is_build,is_house,has_monitoring,level,name,full_name,landmark,parent_id,parent_ids,start_date,stop_date,type,village_city_type,weight,clazz,last_update_coordinate_time,remarks,del_flag,sort,temp,old_id from xxx"
  commitBatch: 1500

修改xxx表一条数据

Expected behaviour

Affected indexes: xxx

Actual behaviour

日志出现NullPointerException异常

If there is an exception, please attach the exception trace:

2022-05-26 15:43:26.214 [pool-2-thread-1] INFO  c.a.o.canal.client.adapter.logger.LoggerAdapterExample - DML: {"data":[{"id":"vvvvvvvvvvvvvvvvvv","alias":"vvvvv3aa","center_latitude":null,"center_longitude":null,"plus_code":null,"range_points":null,"kexin_center_latitude":null,"kexin_center_longitude":null,"kexin_plus_code":null,"kexin_range_points":null,"code":null,"code_sqjw":null,"is_settle":null,"is_temp":null,"is_build":null,"is_house":null,"has_monitoring":0,"level":0,"name":"vvvv","full_name":"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv","landmark":"","parent_id":"0","parent_ids":"0,","start_date":null,"stop_date":null,"type":12,"village_city_type":null,"weight":null,"clazz":null,"last_update_coordinate_time":null,"create_by":"1","create_date":1653550251000,"update_by":"1","update_date":1653550256000,"remarks":null,"del_flag":"1","sort":null,"temp":null,"old_id":null}],"database":"*","destination":"example","es":1653551004000,"groupId":"g1","isDdl":false,"old":[{"alias":"vvvvv3a"}],"pkNames":["id"],"sql":"","table":"xxx","ts":1653551006057,"type":"UPDATE"}
2022-05-26 15:43:26.215 [pool-2-thread-1] ERROR c.a.o.canal.client.adapter.es.core.service.ESSyncService - sync error, es index: xxx, DML : Dml{destination='example', database='*', table='xxx', type='UPDATE', es=1653551004000, ts=1653551006057, sql='', data=[{id=vvvvvvvvvvvvvvvvvv, alias=vvvvv3aa, center_latitude=null, center_longitude=null, plus_code=null, range_points=null, kexin_center_latitude=null, kexin_center_longitude=null, kexin_plus_code=null, kexin_range_points=null, code=null, code_sqjw=null, is_settle=null, is_temp=null, is_build=null, is_house=null, has_monitoring=0, level=0, name=vvvv, full_name=vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv, landmark=, parent_id=0, parent_ids=0,, start_date=null, stop_date=null, type=12, village_city_type=null, weight=null, clazz=null, last_update_coordinate_time=null, create_by=1, create_date=2022-05-26 15:30:51.0, update_by=1, update_date=2022-05-26 15:30:56.0, remarks=null, del_flag=1, sort=null, temp=null, old_id=null}], old=[{alias=vvvvv3a}]}
2022-05-26 15:43:26.220 [pool-2-thread-1] ERROR c.a.otter.canal.adapter.launcher.loader.AdapterProcessor - java.lang.NullPointerException
java.lang.RuntimeException: java.lang.NullPointerException
        at com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService.sync(ESSyncService.java:112) ~[na:na]
        at com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService.sync(ESSyncService.java:60) ~[na:na]
        at com.alibaba.otter.canal.client.adapter.es.core.ESAdapter.sync(ESAdapter.java:104) ~[na:na]
        at com.alibaba.otter.canal.client.adapter.es.core.ESAdapter.sync(ESAdapter.java:83) ~[na:na]
        at com.alibaba.otter.canal.adapter.launcher.loader.AdapterProcessor.batchSync(AdapterProcessor.java:140) ~[client-adapter.launcher-1.1.6.jar:na]
        at com.alibaba.otter.canal.adapter.launcher.loader.AdapterProcessor.lambda$null$1(AdapterProcessor.java:98) ~[client-adapter.launcher-1.1.6.jar:na]
        at java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:891) ~[na:1.8.0_242]
        at com.alibaba.otter.canal.adapter.launcher.loader.AdapterProcessor.lambda$null$2(AdapterProcessor.java:95) ~[client-adapter.launcher-1.1.6.jar:na]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_242]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_242]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_242]
        at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_242]
Caused by: java.lang.NullPointerException: null
        at com.alibaba.otter.canal.client.adapter.es7x.support.ES7xTemplate.getESDataFromDmlData(ES7xTemplate.java:321) ~[na:na]
        at com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService.singleTableSimpleFiledUpdate(ESSyncService.java:814) ~[na:na]
        at com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService.update(ESSyncService.java:208) ~[na:na]
        at com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService.sync(ESSyncService.java:97) ~[na:na]
        ... 11 common frames omitted
2022-05-26 15:43:26.220 [Thread-4] ERROR c.a.otter.canal.adapter.launcher.loader.AdapterProcessor - Outer adapter sync failed!  Error sync and rollback, execute times: 1
yuyoyth commented 2 years ago

补充:adapter 1.1.5版本没有出现此异常

danny383121 commented 2 years ago

我也遇见这个问题,怎么解,兄弟

yuyoyth commented 2 years ago

我也遇见这个问题,怎么解,兄弟

我直接换回了1.1.5版本

yuyoyth commented 2 years ago

我也遇见这个问题,怎么解,兄弟

找到问题了,是adapter配置的ES7的SQL语句,每个表必须有别名,哪怕单表也是,可能1.1.6改逻辑了

danny383121 commented 2 years ago

是这样吗?select 表别名.字段名 from 表 as 别名;select 字段名 from 表 as 别名 这二个都行吗?还是只能一个?

yuyoyth commented 2 years ago

是这样吗?select 表别名.字段名 from 表 as 别名;select 字段名 from 表 as 别名 这二个都行吗?还是只能一个?

只能前者

ascarl2010 commented 1 year ago

兄弟,看看我的问题是不是和你一样

ascarl2010 commented 1 year ago

4789

ascarl2010 commented 1 year ago

厉害,真的是!!!!!是adapter配置的ES7的SQL语句,每个表必须有别名,哪怕单表也是!!!不然修改就报错

从1.1.6开始的!!!!!!