dothetrick / binlogportal

mysql binlog同步工具
129 stars 57 forks source link

大佬运行报错 这是啥问题呢 #6

Open miaomiaojianglove opened 2 years ago

miaomiaojianglove commented 2 years ago

2021-11-10 14:18:04.262 WARN 25352 --- [iyuncs.com:3306] c.g.shyiko.mysql.binlog.BinaryLogClient : com.insistingon.binlogportal.event.MultiEventHandlerListener@4a7c22b1 choked on Event{header=EventHeaderV4{timestamp=1636524980000, eventType=UPDATE_ROWS, serverId=19404926, headerLength=19, dataLength=4385, nextPosition=280448513, flags=0}, data=UpdateRowsEventData{tableId=327, includedColumnsBeforeUpdate={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}, includedColumns={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}, rows=[ {before=[2411, [B@491e63ae, -1.00, 0.00, 299.00, 4.00, 0.00, 13, 4, 0, 0, 100, 5, 0, 2, 4, 6, 0, [B@198954f2, [B@644f887d, [B@262dacf6, [B@1c94b88e, [B@4fe9412a, [B@577d34ca, [B@1c7c68cf, 1613460000, 1629539443000, 1629539443000], after=[2411, [B@2515f306, -1.00, 0.00, 299.00, 4.00, 0.00, 13, 4, 0, 0, 100, 5, 5, 2, 4, 6, 0, [B@2070069f, [B@1e15ad3f, [B@61d08422, [B@6bd7d6dd, [B@4bb361c6, [B@787c41da, [B@1de83b63, 1613460000, 1629539443000, 1629539443000]} ]}}

java.lang.NullPointerException: null at com.insistingon.binlogportal.event.MultiEventHandlerListener.lambda$null$0(MultiEventHandlerListener.java:113) ~[binlogportal-1.0.11.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.MultiEventHandlerListener.lambda$onEvent$1(MultiEventHandlerListener.java:111) ~[binlogportal-1.0.11.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.MultiEventHandlerListener.onEvent(MultiEventHandlerListener.java:110) ~[binlogportal-1.0.11.jar:na] at com.github.shyiko.mysql.binlog.BinaryLogClient.notifyEventListeners(BinaryLogClient.java:1158) [mysql-binlog-connector-java-0.21.0.jar:0.21.0] at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:1005) [mysql-binlog-connector-java-0.21.0.jar:0.21.0] at com.github.shyiko.mysql.binlog.BinaryLogClient.connectWithTimeout(BinaryLogClient.java:517) [mysql-binlog-connector-java-0.21.0.jar:0.21.0] at com.github.shyiko.mysql.binlog.BinaryLogClient.access$1100(BinaryLogClient.java:90) [mysql-binlog-connector-java-0.21.0.jar:0.21.0] at com.github.shyiko.mysql.binlog.BinaryLogClient$7.run(BinaryLogClient.java:881) [mysql-binlog-connector-java-0.21.0.jar:0.21.0] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_291]

peng909300035 commented 2 years ago

我也遇到了同样的问题

dothetrick commented 2 years ago

mysql版本和使用的jar包版本发下

peng909300035 commented 2 years ago

mysql版本 5.7.21 使用的binlogportal 1.0.12

miaomiaojianglove commented 2 years ago

mysql是5.7 驱动

mysql mysql-connector-java 8.0.26

项目是直接当前您这个项目直接克隆的

miaomiaojianglove commented 2 years ago

binlogportal 1.0.11 版本我下载您的源码运行也是同样错误

dothetrick commented 2 years ago

确认下事件监听处理类,是否已经注册到了spring的ioc中。 image

dothetrick commented 2 years ago

源码里面的日志路径是这个,看下当前运行的机器是否没有文件权限。

logging:
  file:
    path: /var/log/binlogportal
miaomiaojianglove commented 2 years ago

这个logEventHandler指的是啥呢 有例子嘛 这个我当时以为是固定死的一个您封装的处理类 @Slf4j @Component public class BinlogSync implements CommandLineRunner { @Autowired BinlogPortalStarter binlogPortalStarter;

public void run(String... args){
    try {
        binlogPortalStarter.start();
    } catch (BinlogPortalException e) {
        log.error(e.getMessage(), e);
    }
}

}

dothetrick commented 2 years ago

可以参考下源码里面,com.insistingon.binlogportal.binlogportalspringbootstartertest.eventhandler.LogEventHandler这个类。这是个demo.

eventhandler是接收到binlog信息后,实际要做的处理,是需要根据自己的需求实现的。

dothetrick commented 2 years ago

源码中可以直接运行springboot项目,com.insistingon.binlogportal.binlogportalspringbootstartertest.BinlogportalSpringBootStarterTestApplication

这个是已经配置好的springboot项目

peng909300035 commented 2 years ago

就是运行这个也会报错
image

miaomiaojianglove commented 2 years ago

同楼上也是一样会报错

miaomiaojianglove commented 2 years ago

断点调试是数组内一共有两个元素 第一个是null的 第二个是url

peng909300035 commented 2 years ago

image 这个路径会有影响么 因为是在windows机器上试的 不过尝试了把路径改成 D:\binlogportal 还是报错

dothetrick commented 2 years ago

看下你们用的mysql的binlog记录格式,是row类型么?

peng909300035 commented 2 years ago

是的 我用main方法的那种写法 可以正常运行 想和springboot结合用 一修改mysql的数据 就会报上面的错误

dothetrick commented 2 years ago

main方法的方式,需要再启动前加一行,

syncConfig.setEventHandlerList(Collections.singletonList(eventEntity -> System.out.println(eventEntity.getJsonFormatData())));

加上运行下,看能打印出变更内容么

miaomiaojianglove commented 2 years ago

我的binlog 是row类型

peng909300035 commented 2 years ago

可以 增删改查 都可以

peng909300035 commented 2 years ago

增删改 都可以

peng909300035 commented 2 years ago

只是和springboot结合使用 就出现了问题

miaomiaojianglove commented 2 years ago

只是和springboot结合使用 就出现了问题

老哥你的main方法运行方式能贴下代码嘛 我看的有点云里雾里的

dothetrick commented 2 years ago

只是和springboot结合使用 就出现了问题

老哥你的main方法运行方式能贴下代码嘛 我看的有点云里雾里的

main方法我修改过了,更新下源码运行看看

miaomiaojianglove commented 2 years ago

报错信息 image

dothetrick commented 2 years ago

报错信息 image

这里应该加上这一行, image

dothetrick commented 2 years ago

只是和springboot结合使用 就出现了问题

我刚试了几次,没重现这个问题。麻烦把表结构,springboot.xml的配置发下,

还有在mysql中执行下,SHOW VARIABLES like "%binlog%"; 这个命令,返回的信息也贴下看看

miaomiaojianglove commented 2 years ago

我重新拉下源码试试看 我上面的截图是SpringBoot的方式运行错误 不是main的

miaomiaojianglove commented 2 years ago

您的SpringBoot方式能够运行吗 大佬

dothetrick commented 2 years ago

您的SpringBoot方式能够运行吗 大佬

我的可以的,刚试过。你上面那个报错就是eventhandler没有在spring里创建成功,所以列表里没有处理类。

demo里面创建成功后运行会打出变更日志。 image

miaomiaojianglove commented 2 years ago

请问大佬您是改什么东西了嘛 我重新拉了一份源码 直接运行成功了

miaomiaojianglove commented 2 years ago

我好像明白了 的项目内没有加那个监听器的bean LogEventHandler 我加上运行以后报错 2021-11-12 12:29:38.725 ERROR 12324 --- [ Thread-20] c.i.binlogportal.BinlogPortalStarter : binaryLogClient connect error!com.github.shyiko.mysql.binlog.BinaryLogClient@2057f0dc 这个啥啥情况呀大佬

miaomiaojianglove commented 2 years ago

回刚刚那个错误 是偶尔启动时候会报错 我删除redis内的binlog记录重新启动就没问题了 启动以后报错 2021-11-12 12:32:40.876 WARN 12328 --- [ Thread-19] c.g.shyiko.mysql.binlog.BinaryLogClient : com.insistingon.binlogportal.event.MultiEventHandlerListener@7ba0b7b6 choked on Event{header=EventHeaderV4{timestamp=1636691560000, eventType=WRITE_ROWS, serverId=19404926, headerLength=19, dataLength=48, nextPosition=281890913, flags=0}, data=WriteRowsEventData{tableId=73, includedColumns={0, 1, 2, 3, 4}, rows=[ [1597, 130570, 8424, 0, 1636720360000] ]}}

java.lang.IndexOutOfBoundsException: Index: 5, Size: 5 at java.util.ArrayList.rangeCheck(ArrayList.java:659) ~[na:1.8.0_291] at java.util.ArrayList.get(ArrayList.java:435) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.EventEntity.getJsonFormatData(EventEntity.java:111) ~[binlogportal-1.0.11.jar:na] at com.tianju.smdk.common.LogEventHandler.process(LogEventHandler.java:13) ~[classes/:na] at com.insistingon.binlogportal.event.MultiEventHandlerListener.lambda$null$0(MultiEventHandlerListener.java:113) ~[binlogportal-1.0.11.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.MultiEventHandlerListener.lambda$onEvent$1(MultiEventHandlerListener.java:111) ~[binlogportal-1.0.11.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.MultiEventHandlerListener.onEvent(MultiEventHandlerListener.java:110) ~[binlogportal-1.0.11.jar:na] at com.github.shyiko.mysql.binlog.BinaryLogClient.notifyEventListeners(BinaryLogClient.java:1055) [mysql-binlog-connector-java-0.16.1.jar:0.16.1] at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:913) [mysql-binlog-connector-java-0.16.1.jar:0.16.1] at com.github.shyiko.mysql.binlog.BinaryLogClient.connect(BinaryLogClient.java:559) [mysql-binlog-connector-java-0.16.1.jar:0.16.1] at com.insistingon.binlogportal.BinlogPortalStarter.lambda$null$1(BinlogPortalStarter.java:65) [binlogportal-1.0.11.jar:na] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_291]

2021-11-12 12:32:41.079 WARN 12328 --- [ Thread-19] c.g.shyiko.mysql.binlog.BinaryLogClient : com.insistingon.binlogportal.event.MultiEventHandlerListener@7ba0b7b6 choked on Event{header=EventHeaderV4{timestamp=1636691560000, eventType=UPDATE_ROWS, serverId=19404926, headerLength=19, dataLength=1089, nextPosition=281892312, flags=0}, data=UpdateRowsEventData{tableId=66, includedColumnsBeforeUpdate={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, includedColumns={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, rows=[ {before=[8424, 0, 303, [B@3ac34fd2, [B@e4fa93c, null, 0, -95, 1206, 0, 0, 0, null, 0.00000, 0.00000, 0, 0, 1636710264000, 1629665705000], after=[8424, 0, 303, [B@71e932c7, [B@583d7f7c, null, 1, -95, 1206, 0, 0, 0, null, 0.00000, 0.00000, 0, 0, 1636710264000, 1629665705000]} ]}}

java.lang.IndexOutOfBoundsException: Index: 19, Size: 19 at java.util.ArrayList.rangeCheck(ArrayList.java:659) ~[na:1.8.0_291] at java.util.ArrayList.get(ArrayList.java:435) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.EventEntity.getJsonFormatData(EventEntity.java:107) ~[binlogportal-1.0.11.jar:na] at com.tianju.smdk.common.LogEventHandler.process(LogEventHandler.java:13) ~[classes/:na] at com.insistingon.binlogportal.event.MultiEventHandlerListener.lambda$null$0(MultiEventHandlerListener.java:113) ~[binlogportal-1.0.11.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.MultiEventHandlerListener.lambda$onEvent$1(MultiEventHandlerListener.java:111) ~[binlogportal-1.0.11.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_291] at com.insistingon.binlogportal.event.MultiEventHandlerListener.onEvent(MultiEventHandlerListener.java:110) ~[binlogportal-1.0.11.jar:na] at com.github.shyiko.mysql.binlog.BinaryLogClient.notifyEventListeners(BinaryLogClient.java:1055) [mysql-binlog-connector-java-0.16.1.jar:0.16.1] at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:913) [mysql-binlog-connector-java-0.16.1.jar:0.16.1] at com.github.shyiko.mysql.binlog.BinaryLogClient.connect(BinaryLogClient.java:559) [mysql-binlog-connector-java-0.16.1.jar:0.16.1] at com.insistingon.binlogportal.BinlogPortalStarter.lambda$null$1(BinlogPortalStarter.java:65) [binlogportal-1.0.11.jar:na] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_291]

miaomiaojianglove commented 2 years ago

报错的代码是 before = this.getChangeBefore().get(i) != null ? this.getChangeBefore().get(i).toString() : ""; 这一行

miaomiaojianglove commented 2 years ago

以上错误是我引用jar包在自己的SpringBoot项目内报的错误 我使用您的源码运行没有问题

miaomiaojianglove commented 2 years ago

我找到原因了 是因为我版本的问题 我将jar升级到最新版本问题得到了解决 现在就还剩下一个问题 启动时候偶尔会出现 2021-11-12 12:29:38.725 ERROR 12324 --- [ Thread-20] c.i.binlogportal.BinlogPortalStarter : binaryLogClient connect error!com.github.shyiko.mysql.binlog.BinaryLogClient@2057f0dc 清除redis内的binlog日志再次启动可以得到解决 但是要多次尝试才行

miaomiaojianglove commented 2 years ago

报错信息代码 binaryLogClientList.forEach((binaryLogClient) -> { (new Thread(() -> { try { binaryLogClient.setHeartbeatInterval(10000L); binaryLogClient.connect(); } catch (IOException var3) { this.log.error("binaryLogClient connect error!" + binaryLogClient.toString()); }

        })).start();
    });

求大佬解答

miaomiaojianglove commented 2 years ago

连接超时貌似 好像是超时时间设置的太短了如果能设置长点就好了

peng909300035 commented 2 years ago

你的是怎么跑起来的? 我又重新拉了还是报同样的错误

peng909300035 commented 2 years ago

image image image

miaomiaojianglove commented 2 years ago

你的是怎么跑起来的? 我又重新拉了还是报同样的错误

老哥你把这个类加进去然后直接启动试试看 我反正是没问题 现在就剩一个连接超时问题了

@Component @Slf4j public class LogEventHandler implements IEventHandler { public void process(EventEntity eventEntity) throws BinlogPortalException { log.info(eventEntity.getJsonFormatData()); } } 直接粘贴到你的SpringBoot扫描包下的任意目录 然后重启即可

miaomiaojianglove commented 2 years ago

大佬的源码我试了下没问题了 你重新克隆一份试试看

miaomiaojianglove commented 2 years ago

您的SpringBoot方式能够运行吗 大佬

我的可以的,刚试过。你上面那个报错就是eventhandler没有在spring里创建成功,所以列表里没有处理类。

demo里面创建成功后运行会打出变更日志。 image

恳请大佬看下我的问题 谢谢您

peng909300035 commented 2 years ago

大佬的源码我试了下没问题了 你重新克隆一份试试看

我重新克隆了下 还是同样的问题 你让粘贴的 项目里面已经有了 image

miaomiaojianglove commented 2 years ago

大佬的源码我试了下没问题了 你重新克隆一份试试看

我重新克隆了下 还是同样的问题 你让粘贴的 项目里面已经有了 image

那我就不太清楚了 但是按理说不应该 你的那个错误就是监听器没有找到导致的 您试试maven clean 或者你看看是不是项目的缓存 当然有没有可能说是项目没有扫描到你的这个监听器

peng909300035 commented 2 years ago

image

peng909300035 commented 2 years ago

image 我更新了一条数据 这里应该进update的 但是EventType 竟然不是update 所以 增删改 都没匹配到 所以返回null了

peng909300035 commented 2 years ago

image 这几个都没进

miaomiaojianglove commented 2 years ago

image 这几个都没进

我觉得可能是你binlog日志格式设置的有问题

dothetrick commented 2 years ago

连接超时貌似 好像是超时时间设置的太短了如果能设置长点就好了

启动前加上这行,可以设置连接超时时间,

void start() {
        try {
            //设置连接超时时间,key是application.xml中配置的
            binlogPortalStarter.getClientByDbKey("d1").setConnectTimeout(1000L);
            binlogPortalStarter.start();
        } catch (BinlogPortalException e) {
            log.error(e.getMessage(), e);
        }
    }
dothetrick commented 2 years ago

@peng909300035 mysql里用这个命令,SHOW VARIABLES like "%binlog%";,返回的信息贴下。

类似下面这样的: image