mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #1100 , fix type compare
This commit is contained in:
@@ -52,9 +52,11 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
|||||||
private static Pattern pattern = Pattern.compile("Duplicate entry '.*' for key '*'");
|
private static Pattern pattern = Pattern.compile("Duplicate entry '.*' for key '*'");
|
||||||
private static Pattern h2Pattern = Pattern.compile("Unique index or primary key violation");
|
private static Pattern h2Pattern = Pattern.compile("Unique index or primary key violation");
|
||||||
private static ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
private static ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
Thread thread = new Thread(r, "[scheduler-table-meta-snapshot]");
|
Thread thread = new Thread(r,
|
||||||
|
"[scheduler-table-meta-snapshot]");
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
@@ -133,9 +135,9 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
|||||||
@Override
|
@Override
|
||||||
public TableMeta find(String schema, String table) {
|
public TableMeta find(String schema, String table) {
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
try{
|
try {
|
||||||
return memoryTableMeta.find(schema, table);
|
return memoryTableMeta.find(schema, table);
|
||||||
}finally {
|
} finally {
|
||||||
lock.readLock().unlock();
|
lock.readLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,7 +146,7 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
|||||||
public boolean apply(EntryPosition position, String schema, String ddl, String extra) {
|
public boolean apply(EntryPosition position, String schema, String ddl, String extra) {
|
||||||
// 首先记录到内存结构
|
// 首先记录到内存结构
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try{
|
try {
|
||||||
if (memoryTableMeta.apply(position, schema, ddl, extra)) {
|
if (memoryTableMeta.apply(position, schema, ddl, extra)) {
|
||||||
this.lastPosition = position;
|
this.lastPosition = position;
|
||||||
this.hasNewDdl = true;
|
this.hasNewDdl = true;
|
||||||
@@ -153,7 +155,7 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
|||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("apply to memory is failed");
|
throw new RuntimeException("apply to memory is failed");
|
||||||
}
|
}
|
||||||
}finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,14 +282,14 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
|||||||
// 获取一份快照
|
// 获取一份快照
|
||||||
Map<String, String> schemaDdls = null;
|
Map<String, String> schemaDdls = null;
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
try{
|
try {
|
||||||
if (!init && !hasNewDdl) {
|
if (!init && !hasNewDdl) {
|
||||||
// 如果是持续构建,则识别一下是否有DDL变更过,如果没有就忽略了
|
// 如果是持续构建,则识别一下是否有DDL变更过,如果没有就忽略了
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.hasNewDdl = false;
|
this.hasNewDdl = false;
|
||||||
schemaDdls = memoryTableMeta.snapshot();
|
schemaDdls = memoryTableMeta.snapshot();
|
||||||
}finally{
|
} finally {
|
||||||
lock.readLock().unlock();
|
lock.readLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,7 +490,24 @@ public class DatabaseTableMeta implements TableMetaTSDB {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StringUtils.equalsIgnoreCase(sourceField.getColumnType(), targetField.getColumnType())) {
|
// if (!StringUtils.equalsIgnoreCase(sourceField.getColumnType(),
|
||||||
|
// targetField.getColumnType())) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// https://github.com/alibaba/canal/issues/1100
|
||||||
|
// 支持一下 int vs int(10)
|
||||||
|
if ((sourceField.isUnsigned() && !targetField.isUnsigned())
|
||||||
|
|| (!sourceField.isUnsigned() && targetField.isUnsigned())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean columnTypeCompare = false;
|
||||||
|
columnTypeCompare |= StringUtils.containsIgnoreCase(sourceField.getColumnType(),
|
||||||
|
targetField.getColumnType());
|
||||||
|
columnTypeCompare |= StringUtils.containsIgnoreCase(targetField.getColumnType(),
|
||||||
|
sourceField.getColumnType());
|
||||||
|
if (!columnTypeCompare) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user