[FLINK-37217][mysql] Fix `MySqlErrorHandler` TableNotFoundException Unable to obtain table correctly

pull/3892/head
huyuanfeng 2 weeks ago
parent 3e16a66972
commit 99766c6e71

@ -32,6 +32,7 @@ import org.apache.kafka.connect.errors.ConnectException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Optional;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -60,12 +61,9 @@ public class MySqlErrorHandler extends ErrorHandler {
@Override @Override
public void setProducerThrowable(Throwable producerThrowable) { public void setProducerThrowable(Throwable producerThrowable) {
if (isTableNotFoundException(producerThrowable)) { Optional<TableId> notFoundTable = extractNotFoundTableId(producerThrowable);
Matcher matcher = if (notFoundTable.isPresent()) {
NOT_FOUND_TABLE_MSG_PATTERN.matcher(producerThrowable.getCause().getMessage()); TableId tableId = notFoundTable.get();
String databaseName = matcher.group(1);
String tableName = matcher.group(2);
TableId tableId = new TableId(databaseName, null, tableName);
if (context.getSchema().schemaFor(tableId) == null) { if (context.getSchema().schemaFor(tableId) == null) {
LOG.warn("Schema for table " + tableId + " is null"); LOG.warn("Schema for table " + tableId + " is null");
return; return;
@ -86,14 +84,20 @@ public class MySqlErrorHandler extends ErrorHandler {
super.setProducerThrowable(producerThrowable); super.setProducerThrowable(producerThrowable);
} }
private boolean isTableNotFoundException(Throwable t) { private Optional<TableId> extractNotFoundTableId(Throwable t) {
if (!(t.getCause() instanceof DebeziumException)) { if (!(t.getCause() instanceof DebeziumException)) {
return false; return Optional.empty();
} }
DebeziumException e = (DebeziumException) t.getCause(); DebeziumException e = (DebeziumException) t.getCause();
String detailMessage = e.getMessage(); String detailMessage = e.getMessage();
Matcher matcher = NOT_FOUND_TABLE_MSG_PATTERN.matcher(detailMessage); Matcher matcher = NOT_FOUND_TABLE_MSG_PATTERN.matcher(detailMessage);
return matcher.find(); if (matcher.find()) {
String databaseName = matcher.group(1);
String tableName = matcher.group(2);
return Optional.of(new TableId(databaseName, null, tableName));
} else {
return Optional.empty();
}
} }
private boolean isSchemaOutOfSyncException(Throwable t) { private boolean isSchemaOutOfSyncException(Throwable t) {

Loading…
Cancel
Save