shardingsphere
shardingsphere copied to clipboard
binlog_row_image option should not be required for all MySQL versions in scaling, verify it and improve it if necessary
Bug Report
Which version of ShardingSphere did you use?
master branch
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy, scaling
Expected behavior
No exception thrown
Actual behavior
Not tested for now.
Reason analyze (If you can)
From MySQLDataSourceChecker.java source code, seems binlog_row_image is required, so it might throw exception in MySQL lower version, e.g. 5.5.
Code snippets:
static {
REQUIRED_VARIABLES.put("LOG_BIN", "ON");
REQUIRED_VARIABLES.put("BINLOG_FORMAT", "ROW");
REQUIRED_VARIABLES.put("BINLOG_ROW_IMAGE", "FULL");
}
private void checkVariable(final DataSource dataSource) {
try (Connection connection = dataSource.getConnection()) {
for (Entry<String, String> entry : REQUIRED_VARIABLES.entrySet()) {
checkVariable(connection, entry.getKey(), entry.getValue());
}
} catch (final SQLException ex) {
throw new PipelineJobPrepareFailedException("Source data source check variables failed.", ex);
}
}
private void checkVariable(final Connection connection, final String key, final String toBeCheckedValue) throws SQLException {
try (PreparedStatement preparedStatement = connection.prepareStatement(SHOW_VARIABLES_SQL)) {
preparedStatement.setString(1, key);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
resultSet.next();
String actualValue = resultSet.getString(2);
if (!toBeCheckedValue.equalsIgnoreCase(actualValue)) {
throw new PipelineJobPrepareFailedException(String.format("Source data source required `%s = %s`, now is `%s`", key, toBeCheckedValue, actualValue));
}
}
}
}
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
Example codes for reproduce this issue (such as a github link).
From MySQL doc:
Important Variables in MySQL 5.6. Features have been added to MySQL 5.6 which need to be disabled when replicating to earlier MySQL versions. To avoid incompatibilities, set the following variables on the MySQL 5.6 source:
binlog_checksum=NONE
binlog_row_image=FULL
binlog_rows_query_log_events=OFF
log_bin_use_v1_row_events=1 (NDB Cluster only)
gtid_mode=OFF
Please refer to these docs for more details:
The problems found after testing are as follows:
- Exception stack
org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException: Source data source check variables failed.
at org.apache.shardingsphere.data.pipeline.mysql.check.datasource.MySQLDataSourceChecker.checkVariable(MySQLDataSourceChecker.java:96)
at org.apache.shardingsphere.data.pipeline.mysql.check.datasource.MySQLDataSourceChecker.checkVariable(MySQLDataSourceChecker.java:86)
at org.apache.shardingsphere.data.pipeline.scenario.rulealtered.RuleAlteredJobPreparer.checkSourceDataSources(RuleAlteredJobPreparer.java:104)
at org.apache.shardingsphere.data.pipeline.scenario.rulealtered.RuleAlteredJobPreparer.checkDataSource(RuleAlteredJobPreparer.java:93)
at org.apache.shardingsphere.data.pipeline.scenario.rulealtered.RuleAlteredJobPreparer.prepare(RuleAlteredJobPreparer.java:63)
at org.apache.shardingsphere.data.pipeline.scenario.rulealtered.RuleAlteredJob.execute(RuleAlteredJob.java:48)
at org.apache.shardingsphere.elasticjob.simple.executor.SimpleJobExecutor.process(SimpleJobExecutor.java:33)
at org.apache.shardingsphere.elasticjob.simple.executor.SimpleJobExecutor.process(SimpleJobExecutor.java:29)
at org.apache.shardingsphere.elasticjob.executor.ElasticJobExecutor.process(ElasticJobExecutor.java:172)
at org.apache.shardingsphere.elasticjob.executor.ElasticJobExecutor.lambda$process$0(ElasticJobExecutor.java:153)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: Illegal operation on empty result set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:790)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5213)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5136)
at com.zaxxer.hikari.pool.HikariProxyResultSet.getString(HikariProxyResultSet.java)
at org.apache.shardingsphere.data.pipeline.mysql.check.datasource.MySQLDataSourceChecker.checkVariable(MySQLDataSourceChecker.java:105)
at org.apache.shardingsphere.data.pipeline.mysql.check.datasource.MySQLDataSourceChecker.checkVariable(MySQLDataSourceChecker.java:93)
... 16 common frames omitted
- Cause Analysis
In MySQL5.5, the "BINLOG_ROW_IMAGE" variable does not exist, so an exception is thrown in
resultSet.next()“BINLOG_ROW_IMAGE” default value is full. In MySQL 5.5 and earlier, full row images are always used for both before images and after images.