|
@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import com.alibaba.otter.canal.common.AbstractCanalLifeCycle;
|
|
|
import com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter;
|
|
|
+import com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet;
|
|
|
import com.alibaba.otter.canal.parse.exception.CanalParseException;
|
|
|
import com.alibaba.otter.canal.parse.exception.TableIdNotFoundException;
|
|
|
import com.alibaba.otter.canal.parse.inbound.BinlogParser;
|
|
@@ -40,6 +41,7 @@ import com.alibaba.otter.canal.protocol.position.EntryPosition;
|
|
|
import com.google.protobuf.ByteString;
|
|
|
import com.taobao.tddl.dbsync.binlog.LogEvent;
|
|
|
import com.taobao.tddl.dbsync.binlog.event.DeleteRowsLogEvent;
|
|
|
+import com.taobao.tddl.dbsync.binlog.event.GtidLogEvent;
|
|
|
import com.taobao.tddl.dbsync.binlog.event.IntvarLogEvent;
|
|
|
import com.taobao.tddl.dbsync.binlog.event.LogHeader;
|
|
|
import com.taobao.tddl.dbsync.binlog.event.QueryLogEvent;
|
|
@@ -56,7 +58,6 @@ import com.taobao.tddl.dbsync.binlog.event.UserVarLogEvent;
|
|
|
import com.taobao.tddl.dbsync.binlog.event.WriteRowsLogEvent;
|
|
|
import com.taobao.tddl.dbsync.binlog.event.XidLogEvent;
|
|
|
import com.taobao.tddl.dbsync.binlog.event.mariadb.AnnotateRowsEvent;
|
|
|
-import com.taobao.tddl.dbsync.binlog.event.GtidLogEvent;
|
|
|
|
|
|
/**
|
|
|
* 基于{@linkplain LogEvent}转化为Entry对象的处理
|
|
@@ -93,6 +94,17 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
|
|
private boolean filterRows = false;
|
|
|
private boolean useDruidDdlFilter = true;
|
|
|
|
|
|
+ // latest gtid
|
|
|
+ private GTIDSet gtidSet;
|
|
|
+
|
|
|
+ public LogEventConvert(GTIDSet gtidSet){
|
|
|
+ this.gtidSet = gtidSet;
|
|
|
+ }
|
|
|
+
|
|
|
+ public LogEventConvert(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Entry parse(LogEvent logEvent, boolean isSeek) throws CanalParseException {
|
|
|
if (logEvent == null || logEvent instanceof UnknownLogEvent) {
|
|
@@ -148,10 +160,15 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
|
|
|
|
|
private Entry parseGTIDLogEvent(GtidLogEvent logEvent) {
|
|
|
LogHeader logHeader = logEvent.getHeader();
|
|
|
- Header header = createHeader("", logHeader, "", "", EventType.GTID);
|
|
|
+ String value = logEvent.getSid().toString() + ":" + logEvent.getGno();
|
|
|
Pair.Builder builder = Pair.newBuilder();
|
|
|
builder.setKey("gtid");
|
|
|
- builder.setValue(String.format("%s:%d", logEvent.getSid(), logEvent.getGno()));
|
|
|
+ builder.setValue(value);
|
|
|
+ if (gtidSet != null) {
|
|
|
+ gtidSet.update(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ Header header = createHeader("", logHeader, "", "", EventType.GTID);
|
|
|
return createEntry(header, EntryType.GTIDLOG, builder.build().toByteString());
|
|
|
}
|
|
|
|
|
@@ -737,6 +754,11 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
|
|
headerBuilder.setTableName(tableName);
|
|
|
}
|
|
|
headerBuilder.setEventLength(logHeader.getEventLen());
|
|
|
+ // enable gtid position
|
|
|
+ if (gtidSet != null) {
|
|
|
+ String gtid = gtidSet.toString();
|
|
|
+ headerBuilder.setGtid(gtid);
|
|
|
+ }
|
|
|
return headerBuilder.build();
|
|
|
}
|
|
|
|
|
@@ -785,7 +807,7 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
|
|
return "LONGTEXT".equalsIgnoreCase(columnType) || "MEDIUMTEXT".equalsIgnoreCase(columnType)
|
|
|
|| "TEXT".equalsIgnoreCase(columnType) || "TINYTEXT".equalsIgnoreCase(columnType);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private boolean isAliSQLHeartBeat(String schema, String table) {
|
|
|
return "test".equalsIgnoreCase(schema) && "heartbeat".equalsIgnoreCase(table);
|
|
|
}
|
|
@@ -857,4 +879,8 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
|
|
this.filterRows = filterRows;
|
|
|
}
|
|
|
|
|
|
+ public void setGtidSet(GTIDSet gtidSet) {
|
|
|
+ this.gtidSet = gtidSet;
|
|
|
+ }
|
|
|
+
|
|
|
}
|