Revert "修复测试类报错 (#4516)"

This reverts commit d899981354.
This commit is contained in:
rewerma
2022-12-06 16:41:17 +08:00
committed by GitHub
parent d899981354
commit f3bb0dd18d
89 changed files with 4470 additions and 1105 deletions

View File

@@ -21,7 +21,6 @@ public final class CharsetConversion {
protected final String mysqlCharset;
protected final String mysqlCollation;
protected final String javaCharset;
protected final Charset charset;
Entry(final int id, String mysqlCharset, // NL
String mysqlCollation, String javaCharset){
@@ -29,7 +28,6 @@ public final class CharsetConversion {
this.mysqlCharset = mysqlCharset;
this.mysqlCollation = mysqlCollation;
this.javaCharset = javaCharset;
this.charset = Charset.isSupported(javaCharset) ? Charset.forName(javaCharset) : null;
}
}
@@ -392,23 +390,6 @@ public final class CharsetConversion {
}
}
public static Charset getNioCharset(final int id) {
Entry entry = getEntry(id);
if (entry != null) {
if (entry.charset != null) {
return entry.charset;
} else {
logger.warn("Unknown java charset for: id = " + id + ", name = " + entry.mysqlCharset + ", coll = "
+ entry.mysqlCollation);
return null;
}
} else {
logger.warn("Unexpect mysql charset: " + id);
return null;
}
}
public static void main(String[] args) {
for (int i = 0; i < entries.length; i++) {
Entry entry = entries[i];

View File

@@ -1,7 +1,5 @@
package com.taobao.tddl.dbsync.binlog;
import java.nio.charset.Charset;
import static com.taobao.tddl.dbsync.binlog.event.RowsLogBuffer.appendNumber2;
import static com.taobao.tddl.dbsync.binlog.event.RowsLogBuffer.appendNumber4;
import static com.taobao.tddl.dbsync.binlog.event.RowsLogBuffer.usecondsToStr;
@@ -59,27 +57,23 @@ public class JsonConversion {
public static final int VALUE_ENTRY_SIZE_LARGE = (1 + LARGE_OFFSET_SIZE);
public static Json_Value parse_value(int type, LogBuffer buffer, long len, String charsetName) {
return parse_value(type, buffer, len, Charset.forName(charsetName));
}
public static Json_Value parse_value(int type, LogBuffer buffer, long len, Charset charset) {
buffer = buffer.duplicate(buffer.position(), (int) len);
switch (type) {
case JSONB_TYPE_SMALL_OBJECT:
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, false, charset);
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, false, charsetName);
case JSONB_TYPE_LARGE_OBJECT:
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, true, charset);
return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, true, charsetName);
case JSONB_TYPE_SMALL_ARRAY:
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, false, charset);
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, false, charsetName);
case JSONB_TYPE_LARGE_ARRAY:
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, true, charset);
return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, true, charsetName);
default:
return parse_scalar(type, buffer, len, charset);
return parse_scalar(type, buffer, len, charsetName);
}
}
private static Json_Value parse_array_or_object(Json_enum_type type, LogBuffer buffer, long len, boolean large,
Charset charset) {
String charsetName) {
long offset_size = large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
if (len < 2 * offset_size) {
throw new IllegalArgumentException("illegal json data");
@@ -106,7 +100,7 @@ public class JsonConversion {
return large ? buffer.getUint32() : buffer.getUint16();
}
private static Json_Value parse_scalar(int type, LogBuffer buffer, long len, Charset charset) {
private static Json_Value parse_scalar(int type, LogBuffer buffer, long len, String charsetName) {
switch (type) {
case JSONB_TYPE_LITERAL:
/* purecov: inspected */
@@ -162,7 +156,7 @@ public class JsonConversion {
}
return new Json_Value(Json_enum_type.STRING, buffer.rewind()
.forward((int) n)
.getFixString((int) str_len, charset));
.getFixString((int) str_len, charsetName));
case JSONB_TYPE_OPAQUE:
/*
* There should always be at least one byte, which tells the
@@ -248,7 +242,7 @@ public class JsonConversion {
this.m_large = large;
}
public String key(int i, Charset charset) {
public String key(int i, String charsetName) {
m_data.rewind();
int offset_size = m_large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
int key_entry_size = m_large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL;
@@ -261,10 +255,10 @@ public class JsonConversion {
// entry, always two
// bytes.
long key_length = m_data.getUint16();
return m_data.rewind().forward((int) key_offset).getFixString((int) key_length, charset);
return m_data.rewind().forward((int) key_offset).getFixString((int) key_length, charsetName);
}
public Json_Value element(int i, Charset charset) {
public Json_Value element(int i, String charsetName) {
m_data.rewind();
int offset_size = m_large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;
int key_entry_size = m_large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL;
@@ -277,13 +271,13 @@ public class JsonConversion {
int type = m_data.forward(entry_offset).getUint8();
if (type == JSONB_TYPE_INT16 || type == JSONB_TYPE_UINT16 || type == JSONB_TYPE_LITERAL
|| (m_large && (type == JSONB_TYPE_INT32 || type == JSONB_TYPE_UINT32))) {
return parse_scalar(type, m_data, value_entry_size - 1, charset);
return parse_scalar(type, m_data, value_entry_size - 1, charsetName);
}
int value_offset = (int) read_offset_or_size(m_data, m_large);
return parse_value(type, m_data.rewind().forward(value_offset), (int) m_length - value_offset, charset);
return parse_value(type, m_data.rewind().forward(value_offset), (int) m_length - value_offset, charsetName);
}
public StringBuilder toJsonString(StringBuilder buf, Charset charset) {
public StringBuilder toJsonString(StringBuilder buf, String charsetName) {
switch (m_type) {
case OBJECT:
buf.append("{");
@@ -291,9 +285,9 @@ public class JsonConversion {
if (i > 0) {
buf.append(", ");
}
buf.append('"').append(key(i, charset)).append('"');
buf.append('"').append(key(i, charsetName)).append('"');
buf.append(": ");
element(i, charset).toJsonString(buf, charset);
element(i, charsetName).toJsonString(buf, charsetName);
}
buf.append("}");
break;
@@ -303,7 +297,7 @@ public class JsonConversion {
if (i > 0) {
buf.append(", ");
}
element(i, charset).toJsonString(buf, charset);
element(i, charsetName).toJsonString(buf, charsetName);
}
buf.append("]");
break;
@@ -404,7 +398,7 @@ public class JsonConversion {
}
buf.append('"').append(text).append('"');
} else {
text = m_data.getFixString((int) m_length, charset);
text = m_data.getFixString((int) m_length, charsetName);
buf.append('"').append(escapse(text)).append('"');
}

View File

@@ -1,6 +1,5 @@
package com.taobao.tddl.dbsync.binlog;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -37,11 +36,6 @@ public class JsonDiffConversion {
public static StringBuilder print_json_diff(LogBuffer buffer, long len, String columnName, int columnIndex,
String charsetName) {
return print_json_diff(buffer, len, columnName, columnIndex, Charset.forName(charsetName));
}
public static StringBuilder print_json_diff(LogBuffer buffer, long len, String columnName, int columnIndex,
Charset charset) {
int position = buffer.position();
List<String> operation_names = new ArrayList<>();
while (buffer.hasRemaining()) {
@@ -117,14 +111,14 @@ public class JsonDiffConversion {
Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(),
buffer,
value_length - 1,
charset);
charsetName);
buffer.forward((int) value_length - 1);
// Read value
if (jsonValue.m_type == Json_enum_type.ERROR) {
throw new IllegalArgumentException("parsing json value");
}
StringBuilder jsonBuilder = new StringBuilder();
jsonValue.toJsonString(jsonBuilder, charset);
jsonValue.toJsonString(jsonBuilder, charsetName);
builder.append(jsonBuilder);
}

View File

@@ -5,8 +5,6 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.BitSet;
@@ -18,8 +16,6 @@ import java.util.BitSet;
*/
public class LogBuffer {
static final BigDecimal DECIMAL_ZERO_1_SCALE = BigDecimal.valueOf(0, 1);
static final BigDecimal DECIMAL_ONE_1_SCALE = BigDecimal.valueOf(10, 1);
protected byte[] buffer;
protected int origin, limit;
@@ -1042,27 +1038,29 @@ public class LogBuffer {
}
}
/* default ANSI charset */
public static final String ISO_8859_1 = "ISO-8859-1";
/**
* Return fix length string from buffer.
*/
public final String getFixString(final int pos, final int len) {
return getFixString(pos, len, StandardCharsets.ISO_8859_1);
return getFixString(pos, len, ISO_8859_1);
}
/**
* Return next fix length string from buffer.
*/
public final String getFixString(final int len) {
return getFixString(len, StandardCharsets.ISO_8859_1);
return getFixString(len, ISO_8859_1);
}
/**
* Return fix length string from buffer.
*/
public final String getFixString(final int pos, final int len, Charset charset) {
if (pos + len > limit || pos < 0) {
throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + len)));
}
public final String getFixString(final int pos, final int len, String charsetName) {
if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ (pos < 0 ? pos : (pos + len)));
final int from = origin + pos;
final int end = from + len;
@@ -1071,16 +1069,19 @@ public class LogBuffer {
for (; (found < end) && buf[found] != '\0'; found++)
/* empty loop */;
return new String(buf, from, found - from, charset);
try {
return new String(buf, from, found - from, charsetName);
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
* Return next fix length string from buffer.
*/
public final String getFixString(final int len, Charset charset) {
if (position + len > origin + limit) {
throw new IllegalArgumentException("limit excceed: " + (position + len - origin));
}
public final String getFixString(final int len, String charsetName) {
if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ (position + len - origin));
final int from = position;
final int end = from + len;
@@ -1089,141 +1090,97 @@ public class LogBuffer {
for (; (found < end) && buf[found] != '\0'; found++)
/* empty loop */;
String string = new String(buf, from, found - from, charset);
position += len;
return string;
}
public final String getFixName(final int len, Charset charset) {
if (position + len > origin + limit) {
throw new IllegalArgumentException("limit excceed: " + (position + len - origin));
try {
String string = new String(buf, from, found - from, charsetName);
position += len;
return string;
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
final int from = position;
final int end = from + len;
byte[] buf = buffer;
int found = from;
for (; (found < end) && buf[found] != '\0'; found++)
/* empty loop */;
int length = found - from;
String string = null;
if (length <= 16) {
string = NameCache.name(buf, from, length, charset);
}
if (string == null) {
string = new String(buf, from, length, charset);
}
position += len;
return string;
}
public final String getFixName(final int len) {
if (position + len > origin + limit) {
throw new IllegalArgumentException("limit excceed: " + (position + len - origin));
}
final int from = position;
final int end = from + len;
byte[] buf = buffer;
int found = from;
for (; (found < end) && buf[found] != '\0'; found++)
/* empty loop */;
int length = found - from;
String string = null;
if (length <= 16) {
string = NameCache.name(buf, from, length, StandardCharsets.ISO_8859_1);
}
if (string == null) {
string = new String(buf, from, length, StandardCharsets.ISO_8859_1);
}
position += len;
return string;
}
/**
* Return fix-length string from buffer without null-terminate checking.
* Fix bug #17 {@link https://github.com/AlibabaTech/canal/issues/17 }
* Return fix-length string from buffer without null-terminate checking. Fix
* bug #17 {@link https://github.com/AlibabaTech/canal/issues/17 }
*/
public final String getFullString(final int pos, final int len, Charset charset) {
if (pos + len > limit || pos < 0) {
throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + len)));
}
public final String getFullString(final int pos, final int len, String charsetName) {
if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
+ (pos < 0 ? pos : (pos + len)));
return new String(buffer, origin + pos, len, charset);
try {
return new String(buffer, origin + pos, len, charsetName);
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
* Return next fix-length string from buffer without null-terminate
* checking.
* Fix bug #17 {@link https://github.com/AlibabaTech/canal/issues/17 }
* checking. Fix bug #17 {@link https
* ://github.com/AlibabaTech/canal/issues/17 }
*/
public final String getFullString(final int len, Charset charset) {
if (position + len > origin + limit) {
throw new IllegalArgumentException("limit excceed: " + (position + len - origin));
public final String getFullString(final int len, String charsetName) {
if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ (position + len - origin));
try {
String string = new String(buffer, position, len, charsetName);
position += len;
return string;
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
String string = new String(buffer, position, len, charset);
position += len;
return string;
}
/**
* Return dynamic length string from buffer.
*/
public final String getString(final int pos) {
if (pos >= limit || pos < 0) {
throw new IllegalArgumentException("limit excceed: " + pos);
}
byte[] buf = buffer;
final int len = (0xff & buf[origin + pos]);
if (pos + len + 1 > limit) {
throw new IllegalArgumentException("limit excceed: " + (pos + len + 1));
}
return new String(buf, origin + pos + 1, len, StandardCharsets.ISO_8859_1);
return getString(pos, ISO_8859_1);
}
/**
* Return next dynamic length string from buffer.
*/
public final String getString() {
if (position >= origin + limit) {
throw new IllegalArgumentException("limit excceed: " + position);
}
byte[] buf = buffer;
final int len = (0xff & buf[position]);
if (position + len + 1 > origin + limit) {
throw new IllegalArgumentException("limit excceed: "
+ (position + len + 1 - origin));
}
String string = new String(buf, position + 1, len, StandardCharsets.ISO_8859_1);
position += len + 1;
return string;
return getString(ISO_8859_1);
}
public final String getName() {
if (position >= origin + limit) {
throw new IllegalArgumentException("limit excceed: " + position);
/**
* Return dynamic length string from buffer.
*/
public final String getString(final int pos, String charsetName) {
if (pos >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + pos);
byte[] buf = buffer;
final int len = (0xff & buf[origin + pos]);
if (pos + len + 1 > limit) throw new IllegalArgumentException("limit excceed: " + (pos + len + 1));
try {
return new String(buf, origin + pos + 1, len, charsetName);
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
}
/**
* Return next dynamic length string from buffer.
*/
public final String getString(String charsetName) {
if (position >= origin + limit) throw new IllegalArgumentException("limit excceed: " + position);
byte[] buf = buffer;
final int len = (0xff & buf[position]);
if (position + len + 1 > origin + limit) {
throw new IllegalArgumentException("limit excceed: " + (position + len + 1 - origin));
}
if (position + len + 1 > origin + limit) throw new IllegalArgumentException("limit excceed: "
+ (position + len + 1 - origin));
String string = NameCache.name(buf, position + 1, len, StandardCharsets.ISO_8859_1);
if (string == null) {
string = new String(buf, position + 1, len, StandardCharsets.ISO_8859_1);
try {
String string = new String(buf, position + 1, len, charsetName);
position += len + 1;
return string;
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
}
position += len + 1;
return string;
}
/**
@@ -1306,15 +1263,6 @@ public class LogBuffer {
throw new IllegalArgumentException("limit excceed: " + (position + binSize - origin));
}
if (precision <= 20 && intg <= 18 && frac <= 9) {
// use compact BigDecimal
BigDecimal compactDecimal = getBigDecimalCompact(precision, scale, intg, frac, intg0x);
if (compactDecimal != null) {
position += binSize;
return compactDecimal;
}
}
BigDecimal decimal = getDecimal0(position, intg, frac, // NL
intg0,
frac0,
@@ -1324,162 +1272,6 @@ public class LogBuffer {
return decimal;
}
/**
* use compact BigDecimal
*/
private BigDecimal getBigDecimalCompact(int precision, int scale, int intg, int frac, int intg0x) {
if (precision > 20 || intg > 18 && frac > 9) {
return null;
}
BigDecimal compactDecimal = null;
long longValue = 0;
int small = 0;
int pos = position;
byte b0 = buffer[position];
final int mask = ((b0 & 0x80) == 0x80) ? 0 : -1;
b0 ^= 0x80;
switch (intg0x) {
case 0:
if (intg == 0) {
longValue = 0;
} else {
longValue = (b0 << 24)
| ((0xff & buffer[pos + 1]) << 16)
| ((0xff & buffer[pos + 2]) << 8)
| (0xff & buffer[pos + 3]);
longValue ^= mask;
pos += 4;
}
break;
case 1:
case 2:
longValue = b0;
longValue ^= mask;
pos += 1;
break;
case 3:
case 4:
longValue = (b0 << 8) | (0xff & buffer[pos + 1]);
longValue ^= mask;
pos += 2;
break;
case 5:
case 6:
longValue = (b0 << 16) | ((0xff & buffer[pos + 1]) << 8) | (0xff & buffer[pos + 2]);
longValue ^= mask;
pos += 3;
break;
case 7:
case 8:
longValue = (b0 << 24)
| ((0xff & buffer[pos + 1]) << 16)
| ((0xff & buffer[pos + 2]) << 8)
| (0xff & buffer[pos + 3]);
longValue ^= mask;
pos += 4;
break;
default:
break;
}
if (intg > 9) {
int value = getInt32BE(buffer, pos);
value ^= mask;
longValue *= 1_000_000_000;
longValue += value;
pos += 4;
}
int power = 1;
if (pos != position) {
b0 = buffer[pos];
}
switch (frac) {
case 0:
small = 0;
break;
case 1:
case 2:
power = frac == 1 ? 10 : 100;
small = b0;
small ^= mask;
break;
case 3:
case 4:
power = frac == 3 ? 1_000 : 10_000;
small = (b0 << 8) | (0xff & buffer[pos + 1]);
small ^= mask;
break;
case 5:
case 6:
power = frac == 5 ? 100_000 : 1_000_000;
small = (b0 << 16) | ((0xff & buffer[pos + 1]) << 8) | (0xff & buffer[pos + 2]);
small ^= mask;
break;
case 7:
case 8:
case 9:
power = frac == 7 ? 10_000_000 : frac == 8 ? 100_000_000 : 1_000_000_000;
small = (b0 << 24)
| ((0xff & buffer[pos + 1]) << 16)
| ((0xff & buffer[pos + 2]) << 8)
| (0xff & buffer[pos + 3]);
small ^= mask;
break;
default:
break;
}
if (small == 0) {
if (frac == 0) {
if (mask != 0) {
longValue = -longValue;
}
compactDecimal = BigDecimal.valueOf(longValue, 0);
} else if (longValue == 0) {
if (scale < 9) {
compactDecimal = DECIMAL_ZERO_1_SCALE;
} else {
compactDecimal = BigDecimal.valueOf(longValue, scale);
}
} else {
if (scale < 9) {
long unscaleValue = longValue * 10;
if (unscaleValue >= longValue) {
if (mask != 0) {
unscaleValue = -unscaleValue;
}
if (unscaleValue == 10) {
compactDecimal = DECIMAL_ONE_1_SCALE;
} else {
compactDecimal = BigDecimal.valueOf(unscaleValue, 1);
}
}
} else {
long unscaleValue = longValue * power;
if (unscaleValue >= longValue) {
if (mask != 0) {
unscaleValue = -unscaleValue;
}
compactDecimal = BigDecimal.valueOf(unscaleValue, scale);
}
}
}
} else {
long unscaleValue = longValue * power + small;
if (unscaleValue >= longValue) {
if (mask != 0) {
unscaleValue = -unscaleValue;
}
compactDecimal = BigDecimal.valueOf(unscaleValue, scale);
}
}
return compactDecimal;
}
/**
* Return big decimal from buffer.
*
@@ -1653,9 +1445,8 @@ public class LogBuffer {
}
d_copy[begin] ^= 0x80; /* restore sign */
// String decimal = String.valueOf(buf, 0, pos);
// return new BigDecimal(decimal);
return new BigDecimal(buf, 0, pos);
String decimal = String.valueOf(buf, 0, pos);
return new BigDecimal(decimal);
}
/**

View File

@@ -197,9 +197,8 @@ public final class LogDecoder {
}
case LogEvent.SLAVE_EVENT: /* can never happen (unused event) */
{
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported SLAVE_EVENT from: " + context.getLogPosition());
}
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported SLAVE_EVENT from: "
+ context.getLogPosition());
break;
}
case LogEvent.CREATE_FILE_EVENT: {
@@ -265,25 +264,22 @@ public final class LogDecoder {
return descriptionEvent;
}
case LogEvent.PRE_GA_WRITE_ROWS_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported PRE_GA_WRITE_ROWS_EVENT from: " + context.getLogPosition());
}
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_WRITE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Write_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.PRE_GA_UPDATE_ROWS_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported PRE_GA_UPDATE_ROWS_EVENT from: " + context.getLogPosition());
}
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_UPDATE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Update_rows_log_event_old(buf, event_len,
// description_event);
break;
}
case LogEvent.PRE_GA_DELETE_ROWS_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported PRE_GA_DELETE_ROWS_EVENT from: " + context.getLogPosition());
}
if (logger.isWarnEnabled()) logger.warn("Skipping unsupported PRE_GA_DELETE_ROWS_EVENT from: "
+ context.getLogPosition());
// ev = new Delete_rows_log_event_old(buf, event_len,
// description_event);
break;
@@ -360,16 +356,10 @@ public final class LogDecoder {
return event;
}
case LogEvent.TRANSACTION_PAYLOAD_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported MySQL TRANSACTION_PAYLOAD_EVENT from: " + context.getLogPosition());
}
break;
// TransactionPayloadLogEvent event = new TransactionPayloadLogEvent(header,
// buffer, descriptionEvent);
// /* updating position in context */
// logPosition.position = header.getLogPos();
// return event;
TransactionPayloadLogEvent event = new TransactionPayloadLogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.VIEW_CHANGE_EVENT: {
ViewChangeEvent event = new ViewChangeEvent(header, buffer, descriptionEvent);
@@ -428,39 +418,6 @@ public final class LogDecoder {
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.HEARTBEAT_LOG_EVENT_V2: {
HeartbeatV2LogEvent event = new HeartbeatV2LogEvent(header, buffer, descriptionEvent);
/* updating position in context */
logPosition.position = header.getLogPos();
return event;
}
case LogEvent.QUERY_COMPRESSED_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported MaraiDB QUERY_COMPRESSED_EVENT from: " + context.getLogPosition());
}
break;
}
case LogEvent.WRITE_ROWS_COMPRESSED_EVENT_V1:
case LogEvent.WRITE_ROWS_COMPRESSED_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported MaraiDB WRITE_ROWS_COMPRESSED_EVENT from: " + context.getLogPosition());
}
break;
}
case LogEvent.UPDATE_ROWS_COMPRESSED_EVENT_V1:
case LogEvent.UPDATE_ROWS_COMPRESSED_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported MaraiDB UPDATE_ROWS_COMPRESSED_EVENT from: " + context.getLogPosition());
}
break;
}
case LogEvent.DELETE_ROWS_COMPRESSED_EVENT_V1:
case LogEvent.DELETE_ROWS_COMPRESSED_EVENT: {
if (logger.isWarnEnabled()) {
logger.warn("Skipping unsupported MaraiDB DELETE_ROWS_COMPRESSED_EVENT from: " + context.getLogPosition());
}
break;
}
default:
/*
* Create an object of Ignorable_log_event for unrecognized

View File

@@ -178,10 +178,7 @@ public abstract class LogEvent {
/* mysql 8.0.20 */
public static final int TRANSACTION_PAYLOAD_EVENT = 40;
/* mysql 8.0.26 */
public static final int HEARTBEAT_LOG_EVENT_V2 = 41;
public static final int MYSQL_ENUM_END_EVENT = 42;
public static final int MYSQL_ENUM_END_EVENT = 41;
// mariaDb 5.5.34
/* New MySQL/Sun events are to be added right above this comment */
@@ -213,23 +210,8 @@ public abstract class LogEvent {
public static final int START_ENCRYPTION_EVENT = 164;
// mariadb 10.10.1
/*
* Compressed binlog event. Note that the order between WRITE/UPDATE/DELETE
* events is significant; this is so that we can convert from the compressed to
* the uncompressed event type with (type-WRITE_ROWS_COMPRESSED_EVENT +
* WRITE_ROWS_EVENT) and similar for _V1.
*/
public static final int QUERY_COMPRESSED_EVENT = 165;
public static final int WRITE_ROWS_COMPRESSED_EVENT_V1 = 166;
public static final int UPDATE_ROWS_COMPRESSED_EVENT_V1 = 167;
public static final int DELETE_ROWS_COMPRESSED_EVENT_V1 = 168;
public static final int WRITE_ROWS_COMPRESSED_EVENT = 169;
public static final int UPDATE_ROWS_COMPRESSED_EVENT = 170;
public static final int DELETE_ROWS_COMPRESSED_EVENT = 171;
/** end marker */
public static final int ENUM_END_EVENT = 171;
public static final int ENUM_END_EVENT = 165;
/**
* 1 byte length, 1 byte format Length is total length in bytes, including 2
@@ -376,7 +358,6 @@ public abstract class LogEvent {
case INCIDENT_EVENT:
return "Incident";
case HEARTBEAT_LOG_EVENT:
case HEARTBEAT_LOG_EVENT_V2:
return "Heartbeat";
case IGNORABLE_LOG_EVENT:
return "Ignorable";

File diff suppressed because one or more lines are too long

View File

@@ -18,7 +18,6 @@ public class GtidLogEvent extends LogEvent {
// / Length of SID in event encoding
public static final int ENCODED_SID_LENGTH = 16;
public static final int LOGICAL_TIMESTAMP_TYPE_CODE = 2;
public static final UUID UUID_ZERO = new UUID(0, 0);
private boolean commitFlag;
private UUID sid;
@@ -36,13 +35,11 @@ public class GtidLogEvent extends LogEvent {
buffer.position(commonHeaderLen);
commitFlag = (buffer.getUint8() != 0); // ENCODED_FLAG_LENGTH
long high = buffer.getBeLong64();
long low = buffer.getBeLong64();
if (high == 0 && low == 0) {
sid = UUID_ZERO;
} else {
sid = new UUID(high, low);
}
byte[] bs = buffer.getData(ENCODED_SID_LENGTH);
ByteBuffer bb = ByteBuffer.wrap(bs);
long high = bb.getLong();
long low = bb.getLong();
sid = new UUID(high, low);
gno = buffer.getLong64();
@@ -76,11 +73,11 @@ public class GtidLogEvent extends LogEvent {
return gno;
}
public long getLastCommitted() {
public Long getLastCommitted() {
return lastCommitted;
}
public long getSequenceNumber() {
public Long getSequenceNumber() {
return sequenceNumber;
}

View File

@@ -3,8 +3,6 @@ package com.taobao.tddl.dbsync.binlog.event;
import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent;
import java.nio.charset.StandardCharsets;
/**
* <pre>
* Replication event to ensure to slave that master is alive.
@@ -37,7 +35,7 @@ public class HeartbeatLogEvent extends LogEvent {
identLen = FN_REFLEN - 1;
}
logIdent = buffer.getFullString(commonHeaderLen, identLen, StandardCharsets.ISO_8859_1);
logIdent = buffer.getFullString(commonHeaderLen, identLen, LogBuffer.ISO_8859_1);
}
public int getIdentLen() {

View File

@@ -1,40 +0,0 @@
package com.taobao.tddl.dbsync.binlog.event;
import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent;
/**
* <pre>
* Replication event to ensure to replica that source is alive.
* The event is originated by source's dump thread and sent straight to
* replica without being logged. Slave itself does not store it in relay log
* but rather uses a data for immediate checks and throws away the event.
* Two members of the class m_log_filename and m_log_position comprise
* @see the rpl_event_coordinates instance. The coordinates that a heartbeat
* instance carries correspond to the last event source has sent from
* its binlog.
* Also this event will be generated only for the source server with
* version > 8.0.26
* </pre>
*
* @author jianghang 2022-09-01 下午16:36:29
* @version 1.1.6
* @since mysql 8.0.26
*/
public class HeartbeatV2LogEvent extends LogEvent {
private byte[] payload;
public HeartbeatV2LogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){
super(header);
final int commonHeaderLen = descriptionEvent.commonHeaderLen;
int payloadLenth = buffer.limit() - commonHeaderLen;
// see : https://github.com/mysql/mysql-server/commit/59e590738a772b74ad50c4a57c86aaa1bc6501c7#diff-184e9a7d8a58f080974e475d4199fe5c6da5518c8a2811cc5df5988c8f9e9797
payload = buffer.getData(payloadLenth);
}
public byte[] getPayload() {
return payload;
}
}

View File

@@ -67,7 +67,7 @@ public final class IncidentLogEvent extends LogEvent {
incident = incidentNumber;
buffer.position(commonHeaderLen + postHeaderLen);
message = buffer.getName();
message = buffer.getString();
}
public final int getIncident() {

View File

@@ -433,7 +433,7 @@ public class QueryLogEvent extends LogEvent {
private int serverCollation = -1;
private int tvSec = -1;
private BigInteger ddlXid = BigInteger.valueOf(-1L);
private Charset charset;
private String charsetName;
private String timezone;
@@ -498,12 +498,12 @@ public class QueryLogEvent extends LogEvent {
/* A 2nd variable part; this is common to all versions */
final int queryLen = dataLen - dbLen - 1;
dbname = buffer.getFixName(dbLen + 1);
dbname = buffer.getFixString(dbLen + 1);
if (clientCharset >= 0) {
charset = CharsetConversion.getNioCharset(clientCharset);
charsetName = CharsetConversion.getJavaCharset(clientCharset);
if (charset != null) {
query = buffer.getFixString(queryLen, charset);
if ((charsetName != null) && (Charset.isSupported(charsetName))) {
query = buffer.getFixString(queryLen, charsetName);
} else {
logger.warn("unsupported character set in query log: " + "\n ID = " + clientCharset + ", Charset = "
+ CharsetConversion.getCharset(clientCharset) + ", Collation = "
@@ -603,13 +603,6 @@ public class QueryLogEvent extends LogEvent {
*/
public static final int Q_HRNOW = 128;
/**
* Support MariaDB 10.10.1
*/
public static final int Q_XID = 129;
public static final int Q_GTID_FLAGS3 = 130;
private final void unpackVariables(LogBuffer buffer, final int end) throws IOException {
int code = -1;
try {
@@ -620,10 +613,10 @@ public class QueryLogEvent extends LogEvent {
break;
case Q_SQL_MODE_CODE:
sql_mode = buffer.getLong64(); // QQ: Fix when sql_mode
// is ulonglong
// is ulonglong
break;
case Q_CATALOG_NZ_CODE:
catalog = buffer.getName();
catalog = buffer.getString();
break;
case Q_AUTO_INCREMENT:
autoIncrementIncrement = buffer.getUint16();
@@ -639,7 +632,7 @@ public class QueryLogEvent extends LogEvent {
serverCollation = buffer.getUint16();
break;
case Q_TIME_ZONE_CODE:
timezone = buffer.getName();
timezone = buffer.getString();
break;
case Q_CATALOG_CODE: /* for 5.0.x where 0<=x<=3 masters */
final int len = buffer.getUint8();
@@ -663,8 +656,8 @@ public class QueryLogEvent extends LogEvent {
buffer.forward(4);
break;
case Q_INVOKER:
user = buffer.getName();
host = buffer.getName();
user = buffer.getString();
host = buffer.getString();
break;
case Q_MICROSECONDS:
// when.tv_usec= uint3korr(pos);
@@ -685,7 +678,7 @@ public class QueryLogEvent extends LogEvent {
String mtsAccessedDbNames[] = new String[mtsAccessedDbs];
for (int i = 0; i < mtsAccessedDbs && buffer.position() < end; i++) {
int length = end - buffer.position();
mtsAccessedDbNames[i] = buffer.getFixName(length < NAME_LEN ? length : NAME_LEN);
mtsAccessedDbNames[i] = buffer.getFixString(length < NAME_LEN ? length : NAME_LEN);
}
break;
case Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP:
@@ -708,25 +701,6 @@ public class QueryLogEvent extends LogEvent {
// int when_sec_part = buffer.getUint24();
buffer.forward(3);
break;
case Q_XID:
// xid= uint8korr(pos);
buffer.forward(8);
break;
case Q_GTID_FLAGS3:
// gtid_flags_extra= *pos++;
// if (gtid_flags_extra & (Gtid_log_event::FL_COMMIT_ALTER_E1 |
// Gtid_log_event::FL_ROLLBACK_ALTER_E1)) {
// sa_seq_no = uint8korr(pos);
// pos+= 8;
// }
int gtid_flags_extra = buffer.getUint8();
final int FL_COMMIT_ALTER_E1= 4;
final int FL_ROLLBACK_ALTER_E1= 8;
if ((gtid_flags_extra & (FL_COMMIT_ALTER_E1 | FL_ROLLBACK_ALTER_E1))> 0) {
buffer.forward(8);
}
break;
default:
/*
* That's why you must write status vars in growing
@@ -766,22 +740,16 @@ public class QueryLogEvent extends LogEvent {
return "Q_TABLE_MAP_FOR_UPDATE_CODE";
case Q_MASTER_DATA_WRITTEN_CODE:
return "Q_MASTER_DATA_WRITTEN_CODE";
case Q_INVOKER:
return "case Q_INVOKER";
case Q_MICROSECONDS:
return "Q_MICROSECONDS";
case Q_UPDATED_DB_NAMES:
return "Q_UPDATED_DB_NAMES";
case Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP:
return "Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP";
case Q_MICROSECONDS:
return "Q_MICROSECONDS";
case Q_DDL_LOGGED_WITH_XID:
return "Q_DDL_LOGGED_WITH_XID";
case Q_DEFAULT_COLLATION_FOR_UTF8MB4:
return "Q_DEFAULT_COLLATION_FOR_UTF8MB4";
case Q_SQL_REQUIRE_PRIMARY_KEY:
return "Q_SQL_REQUIRE_PRIMARY_KEY";
case Q_HRNOW:
return "Q_HRNOW";
}
return "CODE#" + code;
}
@@ -829,8 +797,8 @@ public class QueryLogEvent extends LogEvent {
return autoIncrementOffset;
}
public final Charset getCharset() {
return charset;
public final String getCharsetName() {
return charsetName;
}
public final String getTimezone() {

View File

@@ -1,11 +1,8 @@
package com.taobao.tddl.dbsync.binlog.event;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.ZoneId;
import java.time.zone.ZoneRules;
import java.util.BitSet;
import org.apache.commons.logging.Log;
@@ -26,11 +23,7 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
*/
public final class RowsLogBuffer {
protected static final Log logger = LogFactory.getLog(RowsLogBuffer.class);
public static final Long[] longCache = new Long[1024 * 128];
public static final int longCacheLimit = longCache.length + 127;
public static final Integer[] integerCache = new Integer[1024 * 128];
public static final int integerCacheLimit = longCache.length + 127;
protected static final Log logger = LogFactory.getLog(RowsLogBuffer.class);
public static final long DATETIMEF_INT_OFS = 0x8000000000L;
public static final long TIMEF_INT_OFS = 0x800000L;
@@ -40,7 +33,7 @@ public final class RowsLogBuffer {
private final LogBuffer buffer;
private final int columnLen;
private final int jsonColumnCount;
private final Charset charset;
private final String charsetName;
private final BitSet nullBits;
private int nullBitIndex;
@@ -54,10 +47,10 @@ public final class RowsLogBuffer {
private int length;
private Serializable value;
public RowsLogBuffer(LogBuffer buffer, final int columnLen, Charset charset, int jsonColumnCount, boolean partial){
public RowsLogBuffer(LogBuffer buffer, final int columnLen, String charsetName, int jsonColumnCount, boolean partial){
this.buffer = buffer;
this.columnLen = columnLen;
this.charset = charset;
this.charsetName = charsetName;
this.partial = partial;
this.jsonColumnCount = jsonColumnCount;
this.nullBits = new BitSet(columnLen);
@@ -316,7 +309,7 @@ public final class RowsLogBuffer {
// XXX: How to check signed / unsigned?
// value = unsigned ? Long.valueOf(buffer.getUint32()) :
// Integer.valueOf(buffer.getInt32());
value = valueOf(buffer.getInt32());
value = Integer.valueOf(buffer.getInt32());
javaType = Types.INTEGER;
length = 4;
break;
@@ -325,7 +318,7 @@ public final class RowsLogBuffer {
// XXX: How to check signed / unsigned?
// value = Integer.valueOf(unsigned ? buffer.getUint8() :
// buffer.getInt8());
value = valueOf(buffer.getInt8());
value = Integer.valueOf(buffer.getInt8());
javaType = Types.TINYINT; // java.sql.Types.INTEGER;
length = 1;
break;
@@ -334,7 +327,7 @@ public final class RowsLogBuffer {
// XXX: How to check signed / unsigned?
// value = Integer.valueOf(unsigned ? buffer.getUint16() :
// buffer.getInt16());
value = valueOf((short) buffer.getInt16());
value = Integer.valueOf((short) buffer.getInt16());
javaType = Types.SMALLINT; // java.sql.Types.INTEGER;
length = 2;
break;
@@ -343,7 +336,7 @@ public final class RowsLogBuffer {
// XXX: How to check signed / unsigned?
// value = Integer.valueOf(unsigned ? buffer.getUint24() :
// buffer.getInt24());
value = valueOf(buffer.getInt24());
value = Integer.valueOf(buffer.getInt24());
javaType = Types.INTEGER;
length = 3;
break;
@@ -352,7 +345,7 @@ public final class RowsLogBuffer {
// XXX: How to check signed / unsigned?
// value = unsigned ? buffer.getUlong64()) :
// Long.valueOf(buffer.getLong64());
value = valueOf(buffer.getLong64());
value = Long.valueOf(buffer.getLong64());
javaType = Types.BIGINT; // Types.INTEGER;
length = 8;
break;
@@ -877,7 +870,7 @@ public final class RowsLogBuffer {
}
// logger.warn("MYSQL_TYPE_ENUM : This enumeration value is "
// + "only used internally and cannot exist in a binlog!");
value = valueOf(int32);
value = Integer.valueOf(int32);
javaType = Types.INTEGER;
length = len;
break;
@@ -1024,7 +1017,7 @@ public final class RowsLogBuffer {
javaType = Types.VARBINARY;
value = binary;
} else {
value = buffer.getFullString(len, charset);
value = buffer.getFullString(len, charsetName);
javaType = Types.VARCHAR;
}
@@ -1046,7 +1039,7 @@ public final class RowsLogBuffer {
javaType = Types.BINARY;
value = binary;
} else {
value = buffer.getFullString(len, charset);
value = buffer.getFullString(len, charsetName);
javaType = Types.CHAR; // Types.VARCHAR;
}
length = len;
@@ -1081,7 +1074,7 @@ public final class RowsLogBuffer {
len,
columnName,
columnIndex,
charset);
charsetName);
value = builder.toString();
buffer.position(position + len);
} else {
@@ -1095,9 +1088,9 @@ public final class RowsLogBuffer {
Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(),
buffer,
len - 1,
charset);
charsetName);
StringBuilder builder = new StringBuilder();
jsonValue.toJsonString(builder, charset);
jsonValue.toJsonString(builder, charsetName);
value = builder.toString();
buffer.position(position + len);
}
@@ -1218,38 +1211,4 @@ public final class RowsLogBuffer {
builder.append('0').append(digits[d]);
}
}
public static Long valueOf(long value) {
if (value >= -128 & value <= 127) {
// if (l >= -128 && l <= 127) {
return Long.valueOf(value);
}
if (value > 127 && value < longCacheLimit) {
int cacheIndex = (int) value - 127;
Long cacheValue = longCache[cacheIndex];
if (cacheValue == null) {
cacheValue = new Long(value);
longCache[cacheIndex] = cacheValue;
}
return cacheValue;
}
return new Long(value);
}
public static Integer valueOf(int value) {
if (value >= -128 & value <= 127) {
// if (l >= -128 && l <= 127) {
return Integer.valueOf(value);
}
if (value > 127 && value < integerCacheLimit) {
int cacheIndex = (int) value - 127;
Integer cacheValue = integerCache[cacheIndex];
if (cacheValue == null) {
cacheValue = new Integer(value);
integerCache[cacheIndex] = cacheValue;
}
return cacheValue;
}
return new Integer(value);
}
}

View File

@@ -1,6 +1,5 @@
package com.taobao.tddl.dbsync.binlog.event;
import java.nio.charset.Charset;
import java.util.BitSet;
import com.taobao.tddl.dbsync.binlog.exception.TableIdNotFoundException;
@@ -220,8 +219,8 @@ public abstract class RowsLogEvent extends LogEvent {
return changeColumns;
}
public final RowsLogBuffer getRowsBuf(Charset charset) {
return new RowsLogBuffer(rowsBuf, columnLen, charset, jsonColumnCount, partial);
public final RowsLogBuffer getRowsBuf(String charsetName) {
return new RowsLogBuffer(rowsBuf, columnLen, charsetName, jsonColumnCount, partial);
}
public final int getFlags(final int flags) {

View File

@@ -2,8 +2,6 @@ package com.taobao.tddl.dbsync.binlog.event;
import com.taobao.tddl.dbsync.binlog.LogBuffer;
import java.nio.charset.StandardCharsets;
/**
* @author jianghang 2013-4-8 上午12:36:29
* @version 1.0.3
@@ -25,7 +23,7 @@ public class RowsQueryLogEvent extends IgnorableLogEvent {
*/
int offset = commonHeaderLen + postHeaderLen + 1;
int len = buffer.limit() - offset;
rowsQuery = buffer.getFullString(offset, len, StandardCharsets.ISO_8859_1);
rowsQuery = buffer.getFullString(offset, len, LogBuffer.ISO_8859_1);
}
public String getRowsQuery() {

View File

@@ -36,7 +36,7 @@ public class StartLogEventV3 extends LogEvent {
buffer.position(descriptionEvent.commonHeaderLen);
binlogVersion = buffer.getUint16(); // ST_BINLOG_VER_OFFSET
serverVersion = buffer.getFixName(ST_SERVER_VER_LEN); // ST_SERVER_VER_OFFSET
serverVersion = buffer.getFixString(ST_SERVER_VER_LEN); // ST_SERVER_VER_OFFSET
}
public StartLogEventV3(){

View File

@@ -423,10 +423,10 @@ public final class TableMapLogEvent extends LogEvent {
/* Read the variable part of the event */
buffer.position(commonHeaderLen + postHeaderLen);
dbname = buffer.getName();
dbname = buffer.getString();
buffer.forward(1); /* termination null */
// fixed issue #2714
tblname = buffer.getName();
tblname = buffer.getString();
buffer.forward(1); /* termination null */
// Read column information from buffer

View File

@@ -2,7 +2,6 @@ package com.taobao.tddl.dbsync.binlog.event;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;
import com.taobao.tddl.dbsync.binlog.CharsetConversion;
import com.taobao.tddl.dbsync.binlog.LogBuffer;
@@ -101,8 +100,8 @@ public final class UserVarLogEvent extends LogEvent {
value = buffer.getDecimal(precision, scale); // bin2decimal
break;
case STRING_RESULT:
Charset charset = CharsetConversion.getNioCharset(charsetNumber);
value = buffer.getFixString(valueLen, charset);
String charsetName = CharsetConversion.getJavaCharset(charsetNumber);
value = buffer.getFixString(valueLen, charsetName);
break;
case ROW_RESULT:
// this seems to be banned in MySQL altogether

View File

@@ -5,8 +5,6 @@ import com.taobao.tddl.dbsync.binlog.event.FormatDescriptionLogEvent;
import com.taobao.tddl.dbsync.binlog.event.IgnorableLogEvent;
import com.taobao.tddl.dbsync.binlog.event.LogHeader;
import java.nio.charset.StandardCharsets;
/**
* mariadb的ANNOTATE_ROWS_EVENT类型
*
@@ -25,7 +23,7 @@ public class AnnotateRowsEvent extends IgnorableLogEvent {
int offset = commonHeaderLen + postHeaderLen;
int len = buffer.limit() - offset;
rowsQuery = buffer.getFullString(offset, len, StandardCharsets.ISO_8859_1);
rowsQuery = buffer.getFullString(offset, len, LogBuffer.ISO_8859_1);
}
public String getRowsQuery() {

View File

@@ -52,7 +52,7 @@ public class BaseLogFetcherTest {
event.getHeader().getLogPos() - event.getHeader().getEventLen(),
event.getTable().getDbName(),
event.getTable().getTableName()));
RowsLogBuffer buffer = event.getRowsBuf(charset);
RowsLogBuffer buffer = event.getRowsBuf(charset.name());
BitSet columns = event.getColumns();
BitSet changeColumns = event.getChangeColumns();
while (buffer.nextOneRow(columns)) {