mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fix bug #890
This commit is contained in:
@@ -8,6 +8,8 @@ import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet;
|
||||
import com.alibaba.otter.canal.parse.inbound.mysql.MysqlMultiStageCoprocessor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
@@ -235,12 +237,14 @@ public abstract class AbstractEventParser<EVENT> extends AbstractCanalLifeCycle
|
||||
if (parallel) {
|
||||
// build stage processor
|
||||
multiStageCoprocessor = buildMultiStageCoprocessor();
|
||||
multiStageCoprocessor.start();
|
||||
|
||||
if (isGTIDMode()) {
|
||||
// 判断所属instance是否启用GTID模式,是的话调用ErosaConnection中GTID对应方法dump数据
|
||||
erosaConnection.dump(MysqlGTIDSet.parse(startPosition.getGtid()), multiStageCoprocessor);
|
||||
GTIDSet gtidSet = MysqlGTIDSet.parse(startPosition.getGtid());
|
||||
((MysqlMultiStageCoprocessor) multiStageCoprocessor).setGtidSet(gtidSet);
|
||||
multiStageCoprocessor.start();
|
||||
erosaConnection.dump(gtidSet, multiStageCoprocessor);
|
||||
} else {
|
||||
multiStageCoprocessor.start();
|
||||
if (StringUtils.isEmpty(startPosition.getJournalName())
|
||||
&& startPosition.getTimestamp() != null) {
|
||||
erosaConnection.dump(startPosition.getTimestamp(), multiStageCoprocessor);
|
||||
|
||||
@@ -76,13 +76,6 @@ public abstract class AbstractMysqlEventParser extends AbstractEventParser {
|
||||
* @return
|
||||
*/
|
||||
protected boolean processTableMeta(EntryPosition position) {
|
||||
if (isGTIDMode()) {
|
||||
if (binlogParser instanceof LogEventConvert) {
|
||||
// 记录gtid
|
||||
((LogEventConvert) binlogParser).setGtidSet(MysqlGTIDSet.parse(position.getGtid()));
|
||||
}
|
||||
}
|
||||
|
||||
if (tableMetaTSDB != null) {
|
||||
if (position.getTimestamp() == null || position.getTimestamp() <= 0) {
|
||||
throw new CanalParseException("use gtid and TableMeta TSDB should be config timestamp > 0");
|
||||
|
||||
@@ -179,6 +179,8 @@ public class MysqlConnection implements ErosaConnection {
|
||||
fetcher.start(connector.getChannel());
|
||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||
LogContext context = new LogContext();
|
||||
// fix bug: #890 将gtid传输至context中,供decode使用
|
||||
context.setGtidSet(gtidSet);
|
||||
while (fetcher.fetch()) {
|
||||
accumulateReceivedBytes(fetcher.limit());
|
||||
LogEvent event = null;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import com.alibaba.otter.canal.common.AbstractCanalLifeCycle;
|
||||
import com.alibaba.otter.canal.common.utils.NamedThreadFactory;
|
||||
import com.alibaba.otter.canal.parse.driver.mysql.packets.GTIDSet;
|
||||
import com.alibaba.otter.canal.parse.exception.CanalParseException;
|
||||
import com.alibaba.otter.canal.parse.inbound.ErosaConnection;
|
||||
import com.alibaba.otter.canal.parse.inbound.EventTransactionBuffer;
|
||||
@@ -63,6 +64,7 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
private String destination;
|
||||
private volatile CanalParseException exception;
|
||||
private AtomicLong eventsPublishBlockingTime;
|
||||
private GTIDSet gtidSet;
|
||||
|
||||
public MysqlMultiStageCoprocessor(int ringBufferSize, int parserThreadCount, LogEventConvert logEventConvert,
|
||||
EventTransactionBuffer transactionBuffer, String destination){
|
||||
@@ -227,6 +229,9 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
public SimpleParserStage(){
|
||||
decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||
context = new LogContext();
|
||||
if (gtidSet != null) {
|
||||
context.setGtidSet(gtidSet);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEvent(MessageEvent event, long sequence, boolean endOfBatch) throws Exception {
|
||||
@@ -447,4 +452,7 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
this.eventsPublishBlockingTime = eventsPublishBlockingTime;
|
||||
}
|
||||
|
||||
public void setGtidSet(GTIDSet gtidSet) {
|
||||
this.gtidSet = gtidSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,13 +99,6 @@ 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(){
|
||||
|
||||
}
|
||||
@@ -172,10 +165,9 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
||||
|
||||
private Entry parseGTIDLogEvent(GtidLogEvent logEvent) {
|
||||
LogHeader logHeader = logEvent.getHeader();
|
||||
String value = logEvent.getSid().toString() + ":" + logEvent.getGno();
|
||||
Pair.Builder builder = Pair.newBuilder();
|
||||
builder.setKey("gtid");
|
||||
builder.setValue(value);
|
||||
builder.setValue(logEvent.getGtidStr());
|
||||
|
||||
if (logEvent.getLastCommitted() != null) {
|
||||
builder.setKey("lastCommitted");
|
||||
@@ -974,8 +966,4 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
||||
public void setFilterRows(boolean filterRows) {
|
||||
this.filterRows = filterRows;
|
||||
}
|
||||
|
||||
public void setGtidSet(GTIDSet gtidSet) {
|
||||
this.gtidSet = gtidSet;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user