mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
按主键散列,未设置主键时无限空指针异常 (#1889)
当按注解散列时,如果监控的表未显示设置主键,将会导致flatMessage.getPkNames()为空,导致无限空指针异常
This commit is contained in:
@@ -446,6 +446,7 @@ public class MQMessageUtils {
|
|||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (Map<String, String> row : flatMessage.getData()) {
|
for (Map<String, String> row : flatMessage.getData()) {
|
||||||
int hashCode = database.hashCode();
|
int hashCode = database.hashCode();
|
||||||
|
if (pkNames != null) {
|
||||||
for (String pkName : pkNames) {
|
for (String pkName : pkNames) {
|
||||||
String value = row.get(pkName);
|
String value = row.get(pkName);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@@ -453,6 +454,7 @@ public class MQMessageUtils {
|
|||||||
}
|
}
|
||||||
hashCode = hashCode ^ value.hashCode();
|
hashCode = hashCode ^ value.hashCode();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int pkHash = Math.abs(hashCode) % partitionsNum;
|
int pkHash = Math.abs(hashCode) % partitionsNum;
|
||||||
// math.abs可能返回负值,这里再取反,把出现负值的数据还是写到固定的分区,仍然可以保证消费顺序
|
// math.abs可能返回负值,这里再取反,把出现负值的数据还是写到固定的分区,仍然可以保证消费顺序
|
||||||
|
|||||||
Reference in New Issue
Block a user