mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed #227 , loadBinlogChecksum NPE
This commit is contained in:
@@ -37,7 +37,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
private Charset charset = Charset.forName("UTF-8");
|
private Charset charset = Charset.forName("UTF-8");
|
||||||
private BinlogFormat binlogFormat;
|
private BinlogFormat binlogFormat;
|
||||||
private BinlogImage binlogImage;
|
private BinlogImage binlogImage;
|
||||||
private int binlogChecksum;
|
private int binlogChecksum;
|
||||||
|
|
||||||
public MysqlConnection(){
|
public MysqlConnection(){
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||||
LogContext context = new LogContext();
|
LogContext context = new LogContext();
|
||||||
context.setLogPosition(new LogPosition(binlogfilename));
|
context.setLogPosition(new LogPosition(binlogfilename));
|
||||||
context.setFormatDescription(new FormatDescriptionLogEvent(4,binlogChecksum));
|
context.setFormatDescription(new FormatDescriptionLogEvent(4, binlogChecksum));
|
||||||
while (fetcher.fetch()) {
|
while (fetcher.fetch()) {
|
||||||
LogEvent event = null;
|
LogEvent event = null;
|
||||||
event = decoder.decode(fetcher, context);
|
event = decoder.decode(fetcher, context);
|
||||||
@@ -204,7 +204,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
// 如果不设置会出现错误: Slave can not handle replication events with the
|
// 如果不设置会出现错误: Slave can not handle replication events with the
|
||||||
// checksum that master is configured to log
|
// checksum that master is configured to log
|
||||||
// 但也不能乱设置,需要和mysql server的checksum配置一致,不然RotateLogEvent会出现乱码
|
// 但也不能乱设置,需要和mysql server的checksum配置一致,不然RotateLogEvent会出现乱码
|
||||||
// '@@global.binlog_checksum'需要去掉单引号,在mysql 5.6.29下导致master退出
|
// '@@global.binlog_checksum'需要去掉单引号,在mysql 5.6.29下导致master退出
|
||||||
update("set @master_binlog_checksum= @@global.binlog_checksum");
|
update("set @master_binlog_checksum= @@global.binlog_checksum");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (!StringUtils.contains(e.getMessage(), "Unknown system variable")) {
|
if (!StringUtils.contains(e.getMessage(), "Unknown system variable")) {
|
||||||
@@ -266,12 +266,14 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
throw new IllegalStateException("unexpected binlog image query result:" + rs.getFieldValues());
|
throw new IllegalStateException("unexpected binlog image query result:" + rs.getFieldValues());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取主库checksum信息
|
* 获取主库checksum信息
|
||||||
* https://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#option_mysqld_binlog-checksum
|
* https://dev.mysql.com/doc/refman/5.6/en/replication-options
|
||||||
|
* -binary-log.html#option_mysqld_binlog-checksum
|
||||||
*/
|
*/
|
||||||
private void loadBinlogChecksum(){
|
private void loadBinlogChecksum() {
|
||||||
ResultSetPacket rs = null;
|
ResultSetPacket rs = null;
|
||||||
try {
|
try {
|
||||||
rs = query("select @master_binlog_checksum");
|
rs = query("select @master_binlog_checksum");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -279,10 +281,10 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> columnValues = rs.getFieldValues();
|
List<String> columnValues = rs.getFieldValues();
|
||||||
if(columnValues.get(0).toUpperCase().equals("CRC32")){
|
if (columnValues != null && columnValues.size() >= 1 && columnValues.get(0).toUpperCase().equals("CRC32")) {
|
||||||
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_CRC32;
|
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_CRC32;
|
||||||
}else{
|
} else {
|
||||||
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
|
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user