From 37fc248ebfbe7352319c2fb67c42833e48a5d96e Mon Sep 17 00:00:00 2001 From: Marsss___ <31469905+yabola@users.noreply.github.com> Date: Mon, 27 May 2019 23:54:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=93=8D=E4=BD=9C=E8=AE=A1?= =?UTF-8?q?=E7=AE=97hash=E5=80=BC=E7=9A=84=E6=83=85=E5=86=B5=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=80=83=E8=99=91=EF=BC=8C=E5=AF=BC=E8=87=B4=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=97=B6=E7=9A=84=E5=88=86=E5=8C=BA=E5=92=8C=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E6=97=B6=E7=9A=84=E5=88=86=E5=8C=BA=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=20(#1848)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../otter/canal/common/MQMessageUtils.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/alibaba/otter/canal/common/MQMessageUtils.java b/server/src/main/java/com/alibaba/otter/canal/common/MQMessageUtils.java index fc27baca..d1598809 100644 --- a/server/src/main/java/com/alibaba/otter/canal/common/MQMessageUtils.java +++ b/server/src/main/java/com/alibaba/otter/canal/common/MQMessageUtils.java @@ -230,10 +230,25 @@ public class MQMessageUtils { } } } else { - for (CanalEntry.Column column : rowData.getAfterColumnsList()) { - if (checkPkNamesHasContain(hashMode.pkNames, column.getName())) { - hashCode = hashCode ^ column.getValue().hashCode(); + try { + CanalEntry.EventType eventType = RowChange.parseFrom(entry.getStoreValue()).getEventType(); + if(eventType == CanalEntry.EventType.DELETE){ + for (CanalEntry.Column column : rowData.getBeforeColumnsList()) { + if (checkPkNamesHasContain(hashMode.pkNames, column.getName())) { + hashCode = hashCode ^ column.getValue().hashCode(); + } + } } + else { + for (CanalEntry.Column column : rowData.getAfterColumnsList()) { + if (checkPkNamesHasContain(hashMode.pkNames, column.getName())) { + hashCode = hashCode ^ column.getValue().hashCode(); + } + } + } + } + catch (InvalidProtocolBufferException e) { + e.printStackTrace(); } }