23 open-replicator 解析binlog失败 available: 4, event type: 19

xiaoxiao2021-02-28  94

问题出现

使用 open-replicator 来解析 binLog 的时候出现了这个问题, 这个包 似乎是14年之后 就没有杂更新了

open-replicator 的版本是现在的最新的版本1.0.7, 详情请见 参考的ref

15:55:33.435 [binlog-parser-1] ERROR c.g.c.o.b.impl.AbstractBinlogParser - failed to parse binlog java.lang.RuntimeException: assertion failed, available: 4, event type: 19 at com.google.code.or.binlog.impl.FileBasedBinlogParser.doParse(FileBasedBinlogParser.java:141) ~[open-replicator-1.0.7.jar:na] at com.google.code.or.binlog.impl.AbstractBinlogParser$Task.run(AbstractBinlogParser.java:244) ~[open-replicator-1.0.7.jar:na] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79] 然后 跟到代码里面去瞅了瞅,  FileBasedBinlogParser.doParse 108 - 149, 是挂在了下面的 " if(is.available() != 0) {" while(isRunning() && is.available() > 0) { try { // final BinlogEventV4HeaderImpl header = new BinlogEventV4HeaderImpl(); header.setTimestamp(is.readLong(4) * 1000L); header.setEventType(is.readInt(1)); header.setServerId(is.readLong(4)); header.setEventLength(is.readInt(4)); header.setNextPosition(is.readLong(4)); header.setFlags(is.readInt(2)); header.setBinlogFileName(this.binlogFileName); header.setTimestampOfReceipt(System.currentTimeMillis()); is.setReadLimit((int)(header.getEventLength() - header.getHeaderLength())); // Ensure the event boundary if(isVerbose() && LOGGER.isInfoEnabled()) { LOGGER.info("read an event, header: {}", header); } // if(this.stopPosition > 0 && header.getPosition() > this.stopPosition) { break; } // Parse the event body if(this.eventFilter != null && !this.eventFilter.accepts(header, context)) { this.defaultParser.parse(is, header, context); } else { BinlogEventParser parser = getEventParser(header.getEventType()); if(parser == null) parser = this.defaultParser; parser.parse(is, header, context); } // Ensure the packet boundary if(is.available() != 0) { throw new RuntimeException("assertion failed, available: " + is.available() + ", event type: " + header.getEventType()); } } catch(Exception e) { IOUtils.closeQuietly(is); throw e; } finally { is.setReadLimit(0); } } 首先是一个 FormatDescriptionEventParser, binlog 的版本号之类的东西 然后 之后的时候, 是一个 QueryEventParser 然后 之后是一个 TableMapEventParser, 然后 就是在这一步的 "parser.parse(is, header, context);" 之后, 

is.available() 得到的是 日志中的4, 

XInputStream.available 185 - 189

if(this.readLimit > 0) { return this.readLimit - this.readCount; } else { return this.tail - this.head + this.is.available(); } 就是这里 this.readLimit - this.readCount; 然后 想了一下 可不可能是 mysql binLog 和当前使用的 open-replicator 的版本不匹配呢,  然后 当前使用的是 1.0.7, 然后 我把其版本改成了 1.0.6, 之后 就没有报这个问题了, shit 原来是由于 1.0.6 拿到异常之后没有 打出来, 因此 我没有看到这个问题, 呵呵呵 还以为自己又机智了一会呢,,

问题临时解决

下午的时候, 对于 open-replicator 总共更新了几个地方 : TableMapEventParser, XidEventParser, WriteRowsEventParser, UpdateRowsEventParser, DeleteRowsEventParser, 基本上就是消耗 binlog 中的多出来的四个字节, 这四个字节有什么作用我也不知道, 官方文档上也没找到, 搜索也没有搜索到, 已经满足了我现在的需求[可能 还有一些地方还有需要处理的地方] 结合下午的研习, 晚上的时候, 瞅了瞅官方文档, 整理了一下 两个不同的地方,  有两个不同的地方, 一就是, TableMapEvent body 增加了四个字节, CU Event 增加了四个字节, D 最后增加了四个字节 第二 就是 WRITE_ROWS_EVENT 的 ExtraInfo 部分,,  前者是 binlog中有的, 然后 open-replicator 中没有, mysql官方文档也没有,  然后 后者是 binlog 中有的, 然后 open-replicator 中有, mysql 官方文档中没有,,  我去 xxx, 可能是我没找到吧 ??? 记录一下 

======================= add at 2017.08.10 ======================= 

哦, 说一说后面的事情吧, 后来没过多久我就想到, 可能虽然 原开发人员没有维护open-replicator了, 但是 还有别的朋友 fork open-replpicator, 然后 继续维护的吧, 然后 就来瞅了瞅, 果然不少, 然后 找了一个维护相对来说比较稳定的朋友[zendesk]的 open-replicator, clone 下来, 然后 打包什么的, 感谢原作者 以及这位朋友

参考连接

下面的一系列链接, 才是吊炸天的存在

whitesock/open-replicator https://github.com/whitesock/open-replicator https://github.com/zendesk/open-replicator/ 20.5 Event Classes and Types https://dev.mysql.com/doc/internals/en/event-classes-and-types.html 20.7 Event Structure https://dev.mysql.com/doc/internals/en/event-structure.html 20.8 Binary Log Versions [START_EVENT] https://dev.mysql.com/doc/internals/en/binary-log-versions.html 20.9 Event Data for Specific Event Types https://dev.mysql.com/doc/internals/en/event-data-for-specific-event-types.html 4.6.7 mysqlbinlog — Utility for Processing Binary Log Files https://dev.mysql.com/doc/refman/5.7/en/mysqlbinlog.html 4.6.7.1 mysqlbinlog Hex Dump Format https://dev.mysql.com/doc/refman/5.7/en/mysqlbinlog-hexdump.html 4.6.7.2 mysqlbinlog Row Event Display

https://dev.mysql.com/doc/refman/5.7/en/mysqlbinlog-row-events.html

转载请注明原文地址: https://www.6miu.com/read-45265.html

最新回复(0)