fixed mysql rotate checksum

This commit is contained in:
agapple
2018-11-20 18:29:01 +08:00
parent b6f1e0d13c
commit a7be9c75f9
3 changed files with 14 additions and 53 deletions

View File

@@ -503,7 +503,6 @@ public class MysqlConnection implements ErosaConnection {
* </pre> * </pre>
*/ */
private void loadBinlogChecksum() { private void loadBinlogChecksum() {
if (checkMariaDB()) {
ResultSetPacket rs = null; ResultSetPacket rs = null;
try { try {
rs = query("select @@global.binlog_checksum"); rs = query("select @@global.binlog_checksum");
@@ -518,26 +517,6 @@ public class MysqlConnection implements ErosaConnection {
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF; binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
} }
} }
}
/**
* 获取是否为mariadb
*/
private boolean checkMariaDB() {
ResultSetPacket rs = null;
try {
rs = query("SELECT @@version");
} catch (IOException e) {
throw new CanalParseException(e);
}
List<String> columnValues = rs.getFieldValues();
if (columnValues != null && columnValues.size() >= 1) {
return StringUtils.containsIgnoreCase(columnValues.get(0), "MariaDB");
}
return false;
}
private void accumulateReceivedBytes(long x) { private void accumulateReceivedBytes(long x) {
if (receivedBinlogBytes != null) { if (receivedBinlogBytes != null) {

View File

@@ -47,7 +47,6 @@ public class DirectLogFetcherTest {
protected final Logger logger = LoggerFactory.getLogger(this.getClass()); protected final Logger logger = LoggerFactory.getLogger(this.getClass());
protected String binlogFileName = "mysql-bin.000001"; protected String binlogFileName = "mysql-bin.000001";
protected Charset charset = Charset.forName("utf-8"); protected Charset charset = Charset.forName("utf-8");
private boolean isMariaDB;
private int binlogChecksum; private int binlogChecksum;
@Test @Test
@@ -193,7 +192,7 @@ public class DirectLogFetcherTest {
// 如果不设置会出现错误: 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会出现乱码
update("set @master_binlog_checksum= '@@global.binlog_checksum'", connector); update("set @master_binlog_checksum= @@global.binlog_checksum", connector);
} catch (Exception e) { } catch (Exception e) {
logger.warn("update master_binlog_checksum failed", e); logger.warn("update master_binlog_checksum failed", e);
} }
@@ -217,8 +216,6 @@ public class DirectLogFetcherTest {
} }
private void loadBinlogChecksum(MysqlConnector connector) { private void loadBinlogChecksum(MysqlConnector connector) {
checkMariaDB(connector);
if (isMariaDB) {
ResultSetPacket rs = null; ResultSetPacket rs = null;
try { try {
rs = query("select @@global.binlog_checksum", connector); rs = query("select @@global.binlog_checksum", connector);
@@ -233,21 +230,6 @@ public class DirectLogFetcherTest {
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF; binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
} }
} }
}
private void checkMariaDB(MysqlConnector connector) {
ResultSetPacket rs = null;
try {
rs = query("SELECT @@version", connector);
} catch (IOException e) {
throw new CanalParseException(e);
}
List<String> columnValues = rs.getFieldValues();
if (columnValues != null && columnValues.size() >= 1) {
isMariaDB = StringUtils.containsIgnoreCase(columnValues.get(0), "MariaDB");
}
}
public ResultSetPacket query(String cmd, MysqlConnector connector) throws IOException { public ResultSetPacket query(String cmd, MysqlConnector connector) throws IOException {
MysqlQueryExecutor exector = new MysqlQueryExecutor(connector); MysqlQueryExecutor exector = new MysqlQueryExecutor(connector);

View File

@@ -29,12 +29,12 @@ public class MysqlDumpTest {
@Test @Test
public void testSimple() { public void testSimple() {
final MysqlEventParser controller = new MysqlEventParser(); final MysqlEventParser controller = new MysqlEventParser();
final EntryPosition startPosition = new EntryPosition("mysql-bin.000012", 34051L, 100L); final EntryPosition startPosition = new EntryPosition("mysql-bin.000001", 4L);
// startPosition.setGtid("f1ceb61a-a5d5-11e7-bdee-107c3dbcf8a7:1-17"); // startPosition.setGtid("f1ceb61a-a5d5-11e7-bdee-107c3dbcf8a7:1-17");
controller.setConnectionCharset(Charset.forName("UTF-8")); controller.setConnectionCharset(Charset.forName("UTF-8"));
controller.setSlaveId(3344L); controller.setSlaveId(3344L);
controller.setDetectingEnable(false); controller.setDetectingEnable(false);
controller.setMasterInfo(new AuthenticationInfo(new InetSocketAddress("127.0.0.1", 3306), "canal", "canal")); controller.setMasterInfo(new AuthenticationInfo(new InetSocketAddress("127.0.0.1", 3306), "root", "hello"));
controller.setMasterPosition(startPosition); controller.setMasterPosition(startPosition);
controller.setEnableTsdb(true); controller.setEnableTsdb(true);
controller.setDestination("example"); controller.setDestination("example");