DBZ-1005 Detect GTID by database setting not GTID set

This commit is contained in:
Jiri Pechanec 2018-11-26 15:20:23 +01:00 committed by Gunnar Morling
parent 415830003a
commit c5ecff4be6
3 changed files with 22 additions and 22 deletions

View File

@ -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);

View File

@ -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<String> mode = new AtomicReference<String>("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.
*

View File

@ -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<String> mode = new AtomicReference<String>("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.
*