Skip to content

Commit

Permalink
refactor(mysql-status): Refined compatibility checks for MySQL and Ma…
Browse files Browse the repository at this point in the history
…riaDB versions
  • Loading branch information
CoreyWinkelmannPP committed Nov 14, 2024
1 parent d498902 commit 2742e7d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/java/com/zendesk/maxwell/MaxwellMysqlStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,40 @@ public boolean isMaria() {
}
}

/**
* Generates the appropriate SQL command to retrieve binary log status based on
* the database type and version.
*
* This method checks the database product name and version to determine
* the most suitable SQL command for retrieving binary log status information.
* It supports MySQL and MariaDB, with compatibility for recent version
* requirements:
* <ul>
* <li>MySQL 8.2 and above: uses "SHOW BINARY LOG STATUS"</li>
* <li>MariaDB 10.5 and above: uses "SHOW BINLOG STATUS"</li>
* <li>All other versions default to "SHOW MASTER STATUS"</li>
* </ul>
* If an error occurs during metadata retrieval, the method defaults to "SHOW
* MASTER STATUS".
*
* @return a SQL command string to check binary log status
*/
public String getShowBinlogSQL() {
try {
DatabaseMetaData md = connection.getMetaData();
if ( md.getDatabaseMajorVersion() >= 8 ) {

String productName = md.getDatabaseProductName();

int majorVersion = md.getDatabaseMajorVersion();
int minorVersion = md.getDatabaseMinorVersion();

boolean isMySQL = "MySQL".equalsIgnoreCase(productName);
boolean isMariaDB = "MariaDB".equalsIgnoreCase(productName);

if (isMySQL && (majorVersion > 8 || (majorVersion == 8 && minorVersion >= 2))) {
return "SHOW BINARY LOG STATUS";
} else if (isMariaDB && (majorVersion > 10 || (majorVersion == 10 && minorVersion >= 5))) {
return "SHOW BINLOG STATUS";
}
} catch ( SQLException e ) {
}
Expand Down

0 comments on commit 2742e7d

Please sign in to comment.