Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mysql-status): Refined compatibility checks for MySQL and Ma… #2132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.getDatabaseProductVersion();

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

boolean isMariaDB = productName.toLowerCase().contains("mariadb");
boolean isMySQL = !isMariaDB;

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