fixed issue #1168, support filter with compareTableMetaDbAndMemory

This commit is contained in:
agapple
2018-11-25 21:01:19 +08:00
parent f7bf4ac6ff
commit cbab3fb561

View File

@@ -207,8 +207,8 @@ public class DatabaseTableMeta implements TableMetaTSDB {
packet = connection.query("show full tables from `" + schema + "` where Table_type = 'BASE TABLE'"); packet = connection.query("show full tables from `" + schema + "` where Table_type = 'BASE TABLE'");
List<String> tables = new ArrayList<String>(); List<String> tables = new ArrayList<String>();
for (String table : packet.getFieldValues()) { for (String table : packet.getFieldValues()) {
if("BASE TABLE".equalsIgnoreCase(table)){ if ("BASE TABLE".equalsIgnoreCase(table)) {
continue; continue;
} }
String fullName = schema + "." + table; String fullName = schema + "." + table;
if (blackFilter == null || !blackFilter.filter(fullName)) { if (blackFilter == null || !blackFilter.filter(fullName)) {
@@ -310,11 +310,19 @@ public class DatabaseTableMeta implements TableMetaTSDB {
boolean compareAll = true; boolean compareAll = true;
for (Schema schema : tmpMemoryTableMeta.getRepository().getSchemas()) { for (Schema schema : tmpMemoryTableMeta.getRepository().getSchemas()) {
for (String table : schema.showTables()) { for (String table : schema.showTables()) {
if (!compareTableMetaDbAndMemory(connection, tmpMemoryTableMeta, schema.getName(), table)) { String fullName = schema + "." + table;
compareAll = false; if (blackFilter == null || !blackFilter.filter(fullName)) {
if (filter == null || filter.filter(fullName)) {
// issue : https://github.com/alibaba/canal/issues/1168
// 在生成snapshot时重新过滤一遍
if (!compareTableMetaDbAndMemory(connection, tmpMemoryTableMeta, schema.getName(), table)) {
compareAll = false;
}
}
} }
} }
} }
if (compareAll) { if (compareAll) {
Map<String, String> content = new HashMap<String, String>(); Map<String, String> content = new HashMap<String, String>();
content.put("destination", destination); content.put("destination", destination);