fixed issue #1019 , support canal embedded with Entry

This commit is contained in:
七锋
2018-10-24 13:45:58 +08:00
parent 2202ec451a
commit c75c248086
6 changed files with 116 additions and 33 deletions

View File

@@ -70,6 +70,7 @@ public class MemoryEventStoreWithBuffer extends AbstractCanalStoreScavenge imple
private BatchMode batchMode = BatchMode.ITEMSIZE; // 默认为内存大小模式
private boolean ddlIsolation = false;
private boolean raw = true; // 针对entry是否开启raw模式
public MemoryEventStoreWithBuffer(){
@@ -628,6 +629,14 @@ public class MemoryEventStoreWithBuffer extends AbstractCanalStoreScavenge imple
this.ddlIsolation = ddlIsolation;
}
public boolean isRaw() {
return raw;
}
public void setRaw(boolean raw) {
this.raw = raw;
}
public AtomicLong getPutSequence() {
return putSequence;
}
@@ -671,4 +680,6 @@ public class MemoryEventStoreWithBuffer extends AbstractCanalStoreScavenge imple
public AtomicLong getAckTableRows() {
return ackTableRows;
}
}

View File

@@ -34,10 +34,17 @@ public class Event implements Serializable {
private long rawLength;
private int rowsCount;
// ==== https://github.com/alibaba/canal/issues/1019
private CanalEntry.Entry entry;
public Event(){
}
public Event(LogIdentity logIdentity, CanalEntry.Entry entry){
this(logIdentity, entry, true);
}
public Event(LogIdentity logIdentity, CanalEntry.Entry entry, boolean raw){
this.logIdentity = logIdentity;
this.entryType = entry.getEntryType();
this.executeTime = entry.getHeader().getExecuteTime();
@@ -46,9 +53,6 @@ public class Event implements Serializable {
this.serverId = entry.getHeader().getServerId();
this.gtid = entry.getHeader().getGtid();
this.eventType = entry.getHeader().getEventType();
// build raw
this.rawEntry = entry.toByteString();
this.rawLength = rawEntry.size();
if (entryType == EntryType.ROWDATA) {
List<CanalEntry.Pair> props = entry.getHeader().getPropsList();
if (props != null) {
@@ -60,6 +64,16 @@ public class Event implements Serializable {
}
}
}
if (raw) {
// build raw
this.rawEntry = entry.toByteString();
this.rawLength = rawEntry.size();
} else {
this.entry = entry;
// 按照3倍的event length预估
this.rawLength = entry.getHeader().getEventLength() * 3;
}
}
public LogIdentity getLogIdentity() {
@@ -150,6 +164,14 @@ public class Event implements Serializable {
this.rowsCount = rowsCount;
}
public CanalEntry.Entry getEntry() {
return entry;
}
public void setEntry(CanalEntry.Entry entry) {
this.entry = entry;
}
public String toString() {
return ToStringBuilder.reflectionToString(this, CanalToStringStyle.DEFAULT_STYLE);
}