diff --git a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/BinlogReader.java b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/BinlogReader.java index 7bb93b703..417af587b 100644 --- a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/BinlogReader.java +++ b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/BinlogReader.java @@ -274,7 +274,7 @@ protected void doStart() { // Get the current GtidSet from MySQL so we can get a filtered/merged GtidSet based off of the last Debezium checkpoint. String availableServerGtidStr = connectionContext.knownGtidSet(); - if (availableServerGtidStr != null && !availableServerGtidStr.trim().isEmpty()) { + if (connectionContext.isGtidModeEnabled()) { // The server is using GTIDs, so enable the handler ... eventHandlers.put(EventType.GTID, this::handleGtidEvent); diff --git a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlConnectorTask.java b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlConnectorTask.java index 8f057d407..0e972753c 100644 --- a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlConnectorTask.java +++ b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlConnectorTask.java @@ -149,7 +149,7 @@ public synchronized void start(Configuration config) { } } - if (!startWithSnapshot && source.gtidSet() == null && isGtidModeEnabled()) { + if (!startWithSnapshot && source.gtidSet() == null && connectionContext.isGtidModeEnabled()) { // The snapshot will properly determine the GTID set, but we're not starting with a snapshot and GTIDs were not // previously used but the MySQL server has them enabled ... source.setCompletedGtidSet(""); @@ -364,26 +364,6 @@ protected String earliestBinlogFilename() { return logNames.get(0); } - /** - * Determine whether the MySQL server has GTIDs enabled. - * - * @return {@code false} if the server's {@code gtid_mode} is set and is {@code OFF}, or {@code true} otherwise - */ - protected boolean isGtidModeEnabled() { - AtomicReference mode = new AtomicReference("off"); - try { - connectionContext.jdbc().query("SHOW GLOBAL VARIABLES LIKE 'GTID_MODE'", rs -> { - if (rs.next()) { - mode.set(rs.getString(2)); - } - }); - } catch (SQLException e) { - throw new ConnectException("Unexpected error while connecting to MySQL and looking at GTID mode: ", e); - } - - return !"OFF".equalsIgnoreCase(mode.get()); - } - /** * Determine whether the MySQL server has the row-level binlog enabled. * diff --git a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlJdbcContext.java b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlJdbcContext.java index 382c77cb5..6ad812998 100644 --- a/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlJdbcContext.java +++ b/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/MySqlJdbcContext.java @@ -156,6 +156,26 @@ public void close() { shutdown(); } + /** + * Determine whether the MySQL server has GTIDs enabled. + * + * @return {@code false} if the server's {@code gtid_mode} is set and is {@code OFF}, or {@code true} otherwise + */ + public boolean isGtidModeEnabled() { + AtomicReference mode = new AtomicReference("off"); + try { + jdbc().query("SHOW GLOBAL VARIABLES LIKE 'GTID_MODE'", rs -> { + if (rs.next()) { + mode.set(rs.getString(2)); + } + }); + } catch (SQLException e) { + throw new ConnectException("Unexpected error while connecting to MySQL and looking at GTID mode: ", e); + } + + return !"OFF".equalsIgnoreCase(mode.get()); + } + /** * Determine the available GTID set for MySQL. *