mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #4940 , support percona 8.0.33
This commit is contained in:
@@ -57,6 +57,7 @@ public class MysqlConnection implements ErosaConnection {
|
||||
private int binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
|
||||
// dump binlog bytes, 暂不包括meta与TSDB
|
||||
private AtomicLong receivedBinlogBytes;
|
||||
private boolean compatiablePercona = false;
|
||||
|
||||
public MysqlConnection(){
|
||||
}
|
||||
@@ -122,6 +123,7 @@ public class MysqlConnection implements ErosaConnection {
|
||||
public void seek(String binlogfilename, Long binlogPosition, String gtid, SinkFunction func) throws IOException {
|
||||
updateSettings();
|
||||
loadBinlogChecksum();
|
||||
loadVersionComment();
|
||||
sendBinlogDump(binlogfilename, binlogPosition);
|
||||
DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
|
||||
fetcher.start(connector.getChannel());
|
||||
@@ -146,6 +148,7 @@ public class MysqlConnection implements ErosaConnection {
|
||||
}
|
||||
context.setGtidSet(gtidSet);
|
||||
}
|
||||
context.setCompatiablePercona(compatiablePercona);
|
||||
context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
|
||||
while (fetcher.fetch()) {
|
||||
accumulateReceivedBytes(fetcher.limit());
|
||||
@@ -165,12 +168,14 @@ public class MysqlConnection implements ErosaConnection {
|
||||
public void dump(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException {
|
||||
updateSettings();
|
||||
loadBinlogChecksum();
|
||||
loadVersionComment();
|
||||
sendRegisterSlave();
|
||||
sendBinlogDump(binlogfilename, binlogPosition);
|
||||
DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
|
||||
fetcher.start(connector.getChannel());
|
||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||
LogContext context = new LogContext();
|
||||
context.setCompatiablePercona(compatiablePercona);
|
||||
context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
|
||||
while (fetcher.fetch()) {
|
||||
accumulateReceivedBytes(fetcher.limit());
|
||||
@@ -195,12 +200,14 @@ public class MysqlConnection implements ErosaConnection {
|
||||
public void dump(GTIDSet gtidSet, SinkFunction func) throws IOException {
|
||||
updateSettings();
|
||||
loadBinlogChecksum();
|
||||
loadVersionComment();
|
||||
sendBinlogDumpGTID(gtidSet);
|
||||
|
||||
try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
|
||||
fetcher.start(connector.getChannel());
|
||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||
LogContext context = new LogContext();
|
||||
context.setCompatiablePercona(compatiablePercona);
|
||||
context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
|
||||
// fix bug: #890 将gtid传输至context中,供decode使用
|
||||
context.setGtidSet(gtidSet);
|
||||
@@ -238,10 +245,12 @@ public class MysqlConnection implements ErosaConnection {
|
||||
public void dump(String binlogfilename, Long binlogPosition, MultiStageCoprocessor coprocessor) throws IOException {
|
||||
updateSettings();
|
||||
loadBinlogChecksum();
|
||||
loadVersionComment();
|
||||
sendRegisterSlave();
|
||||
sendBinlogDump(binlogfilename, binlogPosition);
|
||||
((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
|
||||
((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
|
||||
((MysqlMultiStageCoprocessor) coprocessor).setCompatiablePercona(compatiablePercona);
|
||||
try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
|
||||
fetcher.start(connector.getChannel());
|
||||
while (fetcher.fetch()) {
|
||||
@@ -264,9 +273,11 @@ public class MysqlConnection implements ErosaConnection {
|
||||
public void dump(GTIDSet gtidSet, MultiStageCoprocessor coprocessor) throws IOException {
|
||||
updateSettings();
|
||||
loadBinlogChecksum();
|
||||
loadVersionComment();
|
||||
sendBinlogDumpGTID(gtidSet);
|
||||
((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
|
||||
((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
|
||||
((MysqlMultiStageCoprocessor) coprocessor).setCompatiablePercona(compatiablePercona);
|
||||
try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
|
||||
fetcher.start(connector.getChannel());
|
||||
while (fetcher.fetch()) {
|
||||
@@ -558,6 +569,24 @@ public class MysqlConnection implements ErosaConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 识别下mysql的几种生态版本 (percona / mariadb / mysql)
|
||||
*/
|
||||
private void loadVersionComment() {
|
||||
ResultSetPacket rs = null;
|
||||
try {
|
||||
rs = query("select @@version_comment");
|
||||
List<String> columnValues = rs.getFieldValues();
|
||||
if (columnValues != null && columnValues.size() >= 1 && columnValues.get(0) != null){
|
||||
if(StringUtils.containsIgnoreCase(columnValues.get(0),"Percona")){
|
||||
compatiablePercona = true;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
compatiablePercona = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void accumulateReceivedBytes(long x) {
|
||||
if (receivedBinlogBytes != null) {
|
||||
receivedBinlogBytes.addAndGet(x);
|
||||
|
||||
@@ -130,6 +130,10 @@ public class MysqlMultiStageCoprocessor extends AbstractCanalLifeCycle implement
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompatiablePercona(boolean compatiablePercona) {
|
||||
logContext.setCompatiablePercona(compatiablePercona);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
// fix bug #968,对于pool与
|
||||
|
||||
Reference in New Issue
Block a user