按主键散列,未设置主键时无限空指针异常 (#1889)

当按注解散列时,如果监控的表未显示设置主键,将会导致flatMessage.getPkNames()为空,导致无限空指针异常
This commit is contained in:
Z6N
2019-06-18 15:01:00 +08:00
committed by agapple
parent 75b4911caf
commit 5ac0f7b710

View File

@@ -446,6 +446,7 @@ public class MQMessageUtils {
int idx = 0;
for (Map<String, String> row : flatMessage.getData()) {
int hashCode = database.hashCode();
if (pkNames != null) {
for (String pkName : pkNames) {
String value = row.get(pkName);
if (value == null) {
@@ -453,6 +454,7 @@ public class MQMessageUtils {
}
hashCode = hashCode ^ value.hashCode();
}
}
int pkHash = Math.abs(hashCode) % partitionsNum;
// math.abs可能返回负值,这里再取反,把出现负值的数据还是写到固定的分区,仍然可以保证消费顺序