|
@@ -14,6 +14,7 @@ import com.alibaba.otter.canal.parse.driver.mysql.MysqlQueryExecutor;
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.MysqlUpdateExecutor;
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket;
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.packets.client.BinlogDumpCommandPacket;
|
|
|
+import com.alibaba.otter.canal.parse.driver.mysql.packets.client.SemiAckCommandPacket;
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.packets.server.ResultSetPacket;
|
|
|
import com.alibaba.otter.canal.parse.driver.mysql.utils.PacketManager;
|
|
|
import com.alibaba.otter.canal.parse.exception.CanalParseException;
|
|
@@ -24,6 +25,7 @@ import com.alibaba.otter.canal.parse.support.AuthenticationInfo;
|
|
|
import com.taobao.tddl.dbsync.binlog.LogContext;
|
|
|
import com.taobao.tddl.dbsync.binlog.LogDecoder;
|
|
|
import com.taobao.tddl.dbsync.binlog.LogEvent;
|
|
|
+import com.taobao.tddl.dbsync.binlog.event.RotateLogEvent;
|
|
|
|
|
|
public class MysqlConnection implements ErosaConnection {
|
|
|
|
|
@@ -35,6 +37,8 @@ public class MysqlConnection implements ErosaConnection {
|
|
|
private BinlogFormat binlogFormat;
|
|
|
private BinlogImage binlogImage;
|
|
|
|
|
|
+ private String binlogfilename;
|
|
|
+
|
|
|
// tsdb releated
|
|
|
private AuthenticationInfo authInfo;
|
|
|
protected int connTimeout = 5 * 1000; // 5秒
|
|
@@ -141,9 +145,18 @@ public class MysqlConnection implements ErosaConnection {
|
|
|
if (event == null) {
|
|
|
throw new CanalParseException("parse failed");
|
|
|
}
|
|
|
+
|
|
|
+ //binlog日志文件发生变化
|
|
|
+ if(event.getHeader().getType()==LogEvent.ROTATE_EVENT){
|
|
|
+ binlogfilename=((RotateLogEvent)event).getFilename();
|
|
|
+ }
|
|
|
|
|
|
if (!func.sink(event)) {
|
|
|
break;
|
|
|
+ }else{
|
|
|
+ if(event.getSemival()==1){
|
|
|
+ sendSemiAck(binlogfilename, binlogPosition);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -167,6 +180,21 @@ public class MysqlConnection implements ErosaConnection {
|
|
|
PacketManager.writePkg(connector.getChannel(), binlogDumpHeader.toBytes(), cmdBody);
|
|
|
connector.setDumping(true);
|
|
|
}
|
|
|
+
|
|
|
+ private void sendSemiAck(String binlogfilename, Long binlogPosition) throws IOException {
|
|
|
+ SemiAckCommandPacket semiAckCmd = new SemiAckCommandPacket();
|
|
|
+ semiAckCmd.binlogFileName = binlogfilename;
|
|
|
+ semiAckCmd.binlogPosition = binlogPosition;
|
|
|
+
|
|
|
+ byte[] cmdBody = semiAckCmd.toBytes();
|
|
|
+
|
|
|
+ logger.info("SEMI ACK with position:{}", semiAckCmd);
|
|
|
+ HeaderPacket semiAckHeader = new HeaderPacket();
|
|
|
+ semiAckHeader.setPacketBodyLength(cmdBody.length);
|
|
|
+ semiAckHeader.setPacketSequenceNumber((byte) 0x00);
|
|
|
+ PacketManager.writePkg(connector.getChannel(), semiAckHeader.toBytes(), cmdBody);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
public MysqlConnection fork() {
|
|
|
MysqlConnection connection = new MysqlConnection();
|