Skip to content

Commit 3087c70

Browse files
committed
fix: cache showBinaryLogStatement in each MySqlConnection object
Signed-off-by: yuxiqian <34335406+yuxiqian@users.noreply.github.com>
1 parent 6da21ee commit 3087c70

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/io/debezium/connector/mysql/MySqlConnection.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public class MySqlConnection extends JdbcConnection {
7676

7777
private static String MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT = "SHOW MASTER STATUS";
7878
private static String MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT = "SHOW BINARY LOG STATUS";
79-
private static boolean isBinaryLogStatementUndetermined = true;
80-
private static String showBinaryLogStatement;
79+
private String showBinaryLogStatement;
8180

8281
/**
8382
* Creates a new connection using the supplied configuration.
@@ -100,36 +99,35 @@ public MySqlConnection(
10099
}
101100

102101
public String probeShowBinaryLogStatement() {
103-
if (isBinaryLogStatementUndetermined) {
102+
if (showBinaryLogStatement != null) {
103+
return showBinaryLogStatement;
104+
}
105+
try {
106+
LOGGER.info("Probing binary log statement.");
104107
try {
105-
LOGGER.info("Probing binary log statement.");
106-
try {
107-
// Attempt to query
108-
query(MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT, rs -> {});
109-
showBinaryLogStatement = MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT;
110-
} catch (SQLException e) {
111-
LOGGER.info(
112-
"Probing with {} failed, try {}. Caused by: {}",
113-
MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT,
114-
MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT,
115-
e);
116-
query(MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT, rs -> {});
117-
showBinaryLogStatement = MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT;
118-
}
108+
// Attempt to query
109+
query(MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT, rs -> {});
110+
showBinaryLogStatement = MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT;
111+
} catch (SQLException e) {
119112
LOGGER.info(
120-
"Successfully found show binary log statement with `{}`.",
121-
showBinaryLogStatement);
122-
// Make sure this check only happens once
123-
isBinaryLogStatementUndetermined = false;
124-
} catch (Exception e) {
125-
showBinaryLogStatement = MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT;
126-
LOGGER.warn(
127-
"Failed to probe binary log statement version. Fallback to `{}`.",
128-
showBinaryLogStatement,
113+
"Probing with {} failed, try {}. Caused by: {}",
114+
MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT,
115+
MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT,
129116
e);
117+
query(MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT, rs -> {});
118+
showBinaryLogStatement = MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT;
130119
}
120+
LOGGER.info(
121+
"Successfully found show binary log statement with `{}`.",
122+
showBinaryLogStatement);
123+
return showBinaryLogStatement;
124+
} catch (Exception e) {
125+
LOGGER.warn(
126+
"Failed to probe binary log statement version. Fallback to `{}`.",
127+
MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT,
128+
e);
129+
return MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT;
131130
}
132-
return showBinaryLogStatement;
133131
}
134132

135133
/**

0 commit comments

Comments
 (0)