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

不支持Mysql8.0.11的XA #2512

Closed
edeye opened this issue Apr 20, 2018 · 5 comments
Closed

不支持Mysql8.0.11的XA #2512

edeye opened this issue Apr 20, 2018 · 5 comments
Labels
Milestone

Comments

@edeye
Copy link

edeye commented Apr 20, 2018

`Caused by: java.sql.SQLFeatureNotSupportedException: null

at com.alibaba.druid.util.MySqlUtils.createXAConnection(MySqlUtils.java:165)
at com.alibaba.druid.pool.xa.DruidXADataSource.createPhysicalXAConnection(DruidXADataSource.java:72)
at com.alibaba.druid.pool.xa.DruidXADataSource.getXAConnection(DruidXADataSource.java:48)
at com.atomikos.jdbc.AtomikosXAConnectionFactory.createPooledConnection(AtomikosXAConnectionFactory.java:43)`

@edeye
Copy link
Author

edeye commented Apr 20, 2018

查看driver.getMajorVersion后发现值为8,而MySqlUtils.java的判断最大为major == 6
@wenshao

@wenshao wenshao added the Bug label Apr 20, 2018
@wenshao
Copy link
Member

wenshao commented Apr 20, 2018

druid什么版本?

@edeye
Copy link
Author

edeye commented Apr 21, 2018

com.alibaba druid 1.1.9 最新的版本

@wenshao wenshao added this to the 1.1.10 milestone Apr 21, 2018
@edeye
Copy link
Author

edeye commented Apr 23, 2018

@wenshao
com.alibaba.druid.util.MySqlUtils中的createXAConnection方法添加一个分支判断(直接拷贝==6的情况,并稍作修改),暂时可以解决报错,并且XA事务也可正常使用了:

`
if (major == 6) {
....
}else if (major == 8) {
if (method_6_getValue == null && !method_6_getValue_error) {
try {
class_6_connection = Class.forName("com.mysql.cj.jdbc.JdbcConnection");
method_6_getPropertySet = class_6_connection.getMethod("getPropertySet");
method_6_getBooleanReadableProperty = Class.forName("com.mysql.cj.conf.PropertySet").getMethod("getBooleanReadableProperty", String.class);
method_6_getValue = Class.forName("com.mysql.cj.conf.ReadableProperty").getMethod("getValue");
} catch (Exception ex) {
ex.printStackTrace();
method_6_getValue_error = true;
}
}

        try {
            // pinGlobalTxToPhysicalConnection
            boolean pinGlobTx = (Boolean) method_6_getValue.invoke(
                    method_6_getBooleanReadableProperty.invoke(
                            method_6_getPropertySet.invoke(physicalConn)
                            , "pinGlobalTxToPhysicalConnection"
                    )
            );

            if (pinGlobTx) {
                try {
                    if (method_6_getInstance == null && !method_6_getInstance_error) {
                        class_6_suspendableXAConnection = Class.forName("com.mysql.cj.jdbc.SuspendableXAConnection");
                        method_6_getInstance = class_6_suspendableXAConnection.getDeclaredMethod("getInstance", class_6_connection);
                        method_6_getInstance.setAccessible(true);
                    }
                } catch (Throwable ex) {
                    ex.printStackTrace();
                    method_6_getInstance_error = true;
                }
                return (XAConnection) method_6_getInstance.invoke(null, physicalConn);
            } else {
                try {
                    if (method_6_getInstanceXA == null && !method_6_getInstanceXA_error) {
                        class_6_JDBC4SuspendableXAConnection = Class.forName("com.mysql.cj.jdbc.MysqlXAConnection");
                        method_6_getInstanceXA = class_6_JDBC4SuspendableXAConnection.getDeclaredMethod("getInstance", class_6_connection, boolean.class);
                        method_6_getInstanceXA.setAccessible(true);
                    }
                } catch (Throwable ex) {
                    ex.printStackTrace();
                    method_6_getInstanceXA_error = true;
                }
                return (XAConnection) method_6_getInstanceXA.invoke(null, physicalConn, Boolean.FALSE);
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            }
        } catch (Exception e) {
            e.printStackTrace();
            method_6_getInstance_error = true;
        }
    }

`

@edeye edeye closed this as completed Apr 23, 2018
@aboutdever
Copy link

同样的问题 mysql 8.0.18、无法连接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants