From 4f5f72500c43313d34e0e340c31005a34c67e055 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Thu, 13 Jan 2022 00:46:03 -0500 Subject: [PATCH] DBZ-4371 Add hint on how to log problematic values --- .../mysql/MysqlBinaryProtocolFieldReader.java | 11 +++++++---- .../connector/mysql/MysqlTextProtocolFieldReader.java | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlBinaryProtocolFieldReader.java b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlBinaryProtocolFieldReader.java index 7a246dd34..b2bf1ec22 100644 --- a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlBinaryProtocolFieldReader.java +++ b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlBinaryProtocolFieldReader.java @@ -46,7 +46,8 @@ else if (b.length() == 0) { // if micro_seconds is 0, length is 8; otherwise length is 12 if (b.length() != NativeConstants.BIN_LEN_TIME_NO_FRAC && b.length() != NativeConstants.BIN_LEN_TIME_WITH_MICROS) { logInvalidValue(rs, columnIndex, b); - throw new RuntimeException(String.format("Invalid length when read MySQL TIME value. BIN_LEN_TIME is %d", b.length())); + throw new RuntimeException(String.format("Invalid length when read MySQL TIME value. BIN_LEN_TIME is %d. " + + "Enable TRACE logging to log the problematic column and its value.", b.length())); } final byte[] bytes = b.getBytes(1, (int) (b.length())); @@ -72,7 +73,8 @@ protected Object readDateField(ResultSet rs, int columnIndex, Column column, Tab // length is 4 if (b.length() != NativeConstants.BIN_LEN_DATE) { logInvalidValue(rs, columnIndex, b); - throw new RuntimeException(String.format("Invalid length when read MySQL DATE value. BIN_LEN_DATE is %d", b.length())); + throw new RuntimeException(String.format("Invalid length when read MySQL DATE value. BIN_LEN_DATE is %d. " + + "Enable TRACE logging to log the problematic column and its value.", b.length())); } final byte[] bytes = b.getBytes(1L, (int) b.length()); @@ -93,7 +95,6 @@ protected Object readTimestampField(ResultSet rs, int columnIndex, Column column return null; // Don't continue parsing timestamp field if it is null } else if (b.length() == 0) { - logInvalidValue(rs, columnIndex, b); LOGGER.warn("Encountered a zero length blob for column index {}", columnIndex); return null; } @@ -101,7 +102,9 @@ else if (b.length() == 0) { // if hour, minutes, seconds and micro_seconds are all 0, length is 4; if micro_seconds is 0, length is 7; otherwise length is 11 if (b.length() != NativeConstants.BIN_LEN_DATE && b.length() != NativeConstants.BIN_LEN_TIMESTAMP_NO_FRAC && b.length() != NativeConstants.BIN_LEN_TIMESTAMP_WITH_MICROS) { - throw new RuntimeException(String.format("Invalid length when read MySQL DATETIME value. BIN_LEN_DATETIME is %d", b.length())); + logInvalidValue(rs, columnIndex, b); + throw new RuntimeException(String.format("Invalid length when read MySQL DATETIME value. BIN_LEN_DATETIME is %d. " + + "Enable TRACE logging to log the problematic column and its value.", b.length())); } final byte[] bytes = b.getBytes(1, (int) (b.length())); diff --git a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlTextProtocolFieldReader.java b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlTextProtocolFieldReader.java index 214b6f305..69fe07f3c 100644 --- a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlTextProtocolFieldReader.java +++ b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MysqlTextProtocolFieldReader.java @@ -47,7 +47,8 @@ else if (b.length() == 0) { } catch (UnsupportedEncodingException e) { logInvalidValue(rs, columnIndex, b); - logger.error("Could not read MySQL TIME value as UTF-8"); + logger.error("Could not read MySQL TIME value as UTF-8. " + + "Enable TRACE logging to log the problematic column and its value."); throw new RuntimeException(e); } } @@ -68,7 +69,8 @@ protected Object readDateField(ResultSet rs, int columnIndex, Column column, Tab } catch (UnsupportedEncodingException e) { logInvalidValue(rs, columnIndex, b); - logger.error("Could not read MySQL DATE value as UTF-8"); + logger.error("Could not read MySQL DATE value as UTF-8. " + + "Enable TRACE logging to log the problematic column and its value."); throw new RuntimeException(e); } } @@ -94,7 +96,8 @@ else if (b.length() == 0) { } catch (UnsupportedEncodingException e) { logInvalidValue(rs, columnIndex, b); - logger.error("Could not read MySQL DATETIME value as UTF-8"); + logger.error("Could not read MySQL DATETIME value as UTF-8. " + + "Enable TRACE logging to log the problematic column and its value."); throw new RuntimeException(e); } }