Skip to content

use reflection to check for mysql transient exception type#12205

Merged
clintropolis merged 3 commits intoapache:masterfrom
clintropolis:mysql-mariadb-oops
Jan 27, 2022
Merged

use reflection to check for mysql transient exception type#12205
clintropolis merged 3 commits intoapache:masterfrom
clintropolis:mysql-mariadb-oops

Conversation

@clintropolis
Copy link
Copy Markdown
Member

Missed this in #11402, this change will make the MySQLConnector implementation of SQLMetadataConnector.connectorIsTransientException not explode when using MariaDB driver (and added javadocs that only vendor specific errors need handled here). I poked around the MariaDB connector and didn't find any obvious custom transient exceptions to add here for it.

if (driverName.contains("mysql")) {
try {
Class<?> clazz = Class.forName(MYSQL_TRANSIENT_EXCEPTION_CLASS_NAME, false, classLoader);
return e.getClass().equals(clazz)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return e.getClass().equals(clazz)
return clazz.isAssignableFrom(e.getClass())

{
if (driverName.contains("mysql")) {
try {
Class<?> clazz = Class.forName(MYSQL_TRANSIENT_EXCEPTION_CLASS_NAME, false, classLoader);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can do this just once in the constructor? what do you think

{
final String driver = "com.mysql.jdbc.Driver";
final ClassLoader loader = getClass().getClassLoader();
Assert.assertTrue(MySQLConnector.isTransientException(loader, driver, new MySQLTransientException()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add a test case for MySQLTransactionRollbackException (a subclass of MysqlTransientException)?

Copy link
Copy Markdown
Contributor

@abhishekagarwal87 abhishekagarwal87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you @clintropolis for the fix.

@clintropolis
Copy link
Copy Markdown
Member Author

ci failures are for code coverage, but integration tests are passing (except for known flake #12171) merging anyway, going to merge anyway

@clintropolis clintropolis merged commit 5d22919 into apache:master Jan 27, 2022
@clintropolis clintropolis deleted the mysql-mariadb-oops branch January 27, 2022 21:13
abhishekagarwal87 pushed a commit that referenced this pull request Feb 1, 2022
)

Follow up to #12205 to allow druid-mysql-extensions to work with mysql connector/j 8.x again, which does not contain MySQLTransientException, and while would have had the same problem as mariadb if a transient exception was checked, the new check eagerly loads the class when starting up, causing immediate failure.
@abhishekagarwal87 abhishekagarwal87 added this to the 0.23.0 milestone May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants