From a29dccb440c418a9c2f3d0a206b569bc282e2665 Mon Sep 17 00:00:00 2001 From: xiaoma20082008 Date: Tue, 21 Dec 2021 14:36:28 +0800 Subject: [PATCH] : support visibility columns --- .../dbsync/binlog/event/TableMapLogEvent.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/TableMapLogEvent.java b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/TableMapLogEvent.java index 27651c6e6c..779fdf9f1a 100644 --- a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/TableMapLogEvent.java +++ b/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/TableMapLogEvent.java @@ -1,12 +1,11 @@ package com.taobao.tddl.dbsync.binlog.event; +import com.taobao.tddl.dbsync.binlog.LogBuffer; +import com.taobao.tddl.dbsync.binlog.LogEvent; import java.util.ArrayList; import java.util.BitSet; import java.util.List; -import com.taobao.tddl.dbsync.binlog.LogBuffer; -import com.taobao.tddl.dbsync.binlog.LogEvent; - /** * In row-based mode, every row operation event is preceded by a * Table_map_log_event which maps a table definition to a number. The table @@ -343,6 +342,7 @@ public static final class ColumnInfo { public int charset; // 可以通过CharsetUtil进行转化 public int geoType; public boolean nullable; + public boolean visibility; @Override public String toString() { @@ -382,6 +382,12 @@ public String toString() { public static final int SIMPLE_PRIMARY_KEY = 8; // Primary key with prefix public static final int PRIMARY_KEY_WITH_PREFIX = 9; + // Character set of enum and set columns, optimized to minimize space when many columns have the same charset. + public static final int ENUM_AND_SET_DEFAULT_CHARSET = 10; + // Character set of enum and set columns, optimized to minimize space when many columns have the same charset. + public static final int ENUM_AND_SET_COLUMN_CHARSET = 11; + // Flag to indicate column visibility attribute + public static final int COLUMN_VISIBILITY = 12; private int default_charset; private boolean existOptionalMetaData = false; @@ -484,6 +490,15 @@ public TableMapLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLog case PRIMARY_KEY_WITH_PREFIX: parse_pk_with_prefix(buffer, len); break; + case ENUM_AND_SET_DEFAULT_CHARSET: + parse_default_charset(buffer, len); + break; + case ENUM_AND_SET_COLUMN_CHARSET: + parse_column_charset(buffer, len); + break; + case COLUMN_VISIBILITY: + parse_column_visibility(buffer, len); + break; default: throw new IllegalArgumentException("unknow type : " + type); } @@ -648,6 +663,20 @@ private List parse_column_charset(LogBuffer buffer, int length) { return datas; } + + private void parse_column_visibility(LogBuffer buffer, int length) { + List data = new ArrayList<>(columnInfo.length); + for (int i = 0; i < length; i++) { + int ut = buffer.getUint8(); + for (int c = 0x80; c != 0; c >>= 1) { + data.add((ut & c) > 0); + } + } + for (int i = 0; i < columnCnt; i++) { + columnInfo[i].visibility = data.get(i); + } + } + private void parse_column_name(LogBuffer buffer, int length) { // stores column names extracted from field int limit = buffer.position() + length;