fixed data

This commit is contained in:
agapple
2017-10-15 16:08:29 +08:00
parent 77342663e3
commit 1463463f1e
3 changed files with 22 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
################################################# #################################################
# rds openapi binlog
canal.instance.rds.open.url=https://rds.aliyuncs.com/ canal.instance.rds.open.url=https://rds.aliyuncs.com/
canal.instance.rds.open.accesskey= canal.instance.rds.open.accesskey=
canal.instance.rds.open.secretkey= canal.instance.rds.open.secretkey=

View File

@@ -285,6 +285,8 @@ public class DatabaseTableMeta implements TableMetaTSDB {
} }
private boolean compareTableMetaDbAndMemory(MysqlConnection connection, final String schema, final String table) { private boolean compareTableMetaDbAndMemory(MysqlConnection connection, final String schema, final String table) {
TableMeta tableMetaFromMem = memoryTableMeta.find(schema, table);
TableMeta tableMetaFromDB = new TableMeta(); TableMeta tableMetaFromDB = new TableMeta();
tableMetaFromDB.setSchema(schema); tableMetaFromDB.setSchema(schema);
tableMetaFromDB.setTable(table); tableMetaFromDB.setTable(table);
@@ -292,15 +294,29 @@ public class DatabaseTableMeta implements TableMetaTSDB {
ResultSetPacket packet = connection.query("desc " + getFullName(schema, table)); ResultSetPacket packet = connection.query("desc " + getFullName(schema, table));
tableMetaFromDB.setFields(TableMetaCache.parserTableMeta(packet)); tableMetaFromDB.setFields(TableMetaCache.parserTableMeta(packet));
} catch (IOException e) { } catch (IOException e) {
if (e.getMessage().contains("errorNumber=1146")) {
logger.error("table not exist in db , pls check :" + getFullName(schema, table) + " , mem : "
+ tableMetaFromMem);
return false;
}
throw new CanalParseException(e); throw new CanalParseException(e);
} }
TableMeta tableMetaFromMem = memoryTableMeta.find(schema, table);
boolean result = compareTableMeta(tableMetaFromMem, tableMetaFromDB); boolean result = compareTableMeta(tableMetaFromMem, tableMetaFromDB);
if (!result) { if (!result) {
logger.error("compare failed . \n db : " + tableMetaFromDB + " \n mem : " + tableMetaFromMem); String createDDL = null;
try {
ResultSetPacket packet = connection.query("show create table " + getFullName(schema, table));
if (packet.getFieldValues().size() > 1) {
createDDL = packet.getFieldValues().get(1);
}
} catch (IOException e) {
// ignore
} }
logger.error("pls submit github issue, show create table ddl:" + createDDL + " , compare failed . \n db : "
+ tableMetaFromDB + " \n mem : " + tableMetaFromMem);
}
return result; return result;
} }

View File

@@ -14,17 +14,14 @@ public class TableMetaCacheTest {
@Test @Test
public void testSimple() throws IOException { public void testSimple() throws IOException {
MysqlConnection connection = new MysqlConnection(new InetSocketAddress("127.0.0.1", 3306), "root", "hello");
MysqlConnection connection = new MysqlConnection(new InetSocketAddress("100.81.153.8", 3308),
"jingwei",
"jingwei");
try { try {
connection.connect(); connection.connect();
} catch (IOException e) { } catch (IOException e) {
Assert.fail(e.getMessage()); Assert.fail(e.getMessage());
} }
List<ResultSetPacket> packets = connection.queryMulti("show create table test.ljh_test; show create table test.user"); List<ResultSetPacket> packets = connection.queryMulti("show create table test.ljh_test");
String createDDL = null; String createDDL = null;
if (packets.get(0).getFieldValues().size() > 0) { if (packets.get(0).getFieldValues().size() > 0) {
createDDL = packets.get(0).getFieldValues().get(1); createDDL = packets.get(0).getFieldValues().get(1);