sandynz opened a new issue, #20881:
URL: https://github.com/apache/shardingsphere/issues/20881
## Bug Report
### Which version of ShardingSphere did you use?
master branch, commit 23c502ccb4b8b207c1fa31b1644da6d3520f2c5e
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
proxy
### Expected behavior
Following query works:
```
/* mysql-connector-java-5.1.47 ( Revision:
fe1903b1ecb4a96a917f7ed3190d80c049b1de29 ) */SELECT
@@session.auto_increment_increment AS auto_increment_increment,
@@character_set_client AS character_set_client, @@character_set_connection AS
character_set_connection, @@character_set_results AS character_set_results,
@@character_set_server AS character_set_server, @@collation_server AS
collation_server, @@collation_connection AS collation_connection,
@@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout,
@@license AS license, @@lower_case_table_names AS lower_case_table_names,
@@max_allowed_packet AS max_allowed_packet, @@net_buffer_length AS
net_buffer_length, @@net_write_timeout AS net_write_timeout, @@query_cache_size
AS query_cache_size, @@query_cache_type AS query_cache_type, @@sql_mode AS
sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone,
@@transaction_isolation AS transaction_isolation, @@wait_timeout AS
wait_timeout;
```
Simplied one:
```
SELECT @@session.auto_increment_increment;
```
### Actual behavior
There're 2 databases:
- scaling_nomig : with full data source and rules configured
- sharding_db : empty
1. No database is selected, it works
2. If there's only empty database and selected, it works
3. Select empty database, it does NOT work
```
mysql> SELECT @@session.auto_increment_increment;
+------------------------------------+
| @@session.auto_increment_increment |
+------------------------------------+
| 1 |
+------------------------------------+
1 row in set (0.01 sec)
mysql> use sharding_db
Database changed
mysql> show sharding table rules;
Empty set (0.95 sec)
mysql> SELECT @@session.auto_increment_increment;
ERROR 11003 (42000): Rule does not exist
```
`Rule does not exist` is from RuleNotExistedException, related code:
UnicastDatabaseBackendHandler.execute
```
public ResponseHeader execute() throws SQLException {
String originDatabase = connectionSession.getDefaultDatabaseName();
String databaseName = null == originDatabase ?
getFirstDatabaseName() : originDatabase;
if
(!ProxyContext.getInstance().getDatabase(databaseName).containsDataSource()) {
throw new RuleNotExistedException();
}
...
```
### Reason analyze (If you can)
It might be affected by MySQLAdminExecutorCreator.hasNoResource():
```
private boolean hasNoResource() {
Collection<String> databaseNames =
ProxyContext.getInstance().getAllDatabaseNames();
if (databaseNames.isEmpty()) {
return true;
}
for (String each : databaseNames) {
if
(ProxyContext.getInstance().getDatabase(each).containsDataSource()) {
return false;
}
}
return true;
}
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
SQL log:
```
mysql> show databases;
+--------------------+
| schema_name |
+--------------------+
| information_schema |
| performance_schema |
| sys |
| mysql |
+--------------------+
4 rows in set (0.02 sec)
mysql> SELECT @@session.auto_increment_increment;
+------------------------------------+
| @@session.auto_increment_increment |
+------------------------------------+
| |
+------------------------------------+
1 row in set (0.06 sec)
mysql> create database sharding_db;
Query OK, 0 rows affected (0.09 sec)
mysql> use sharding_db
Database changed
mysql> SELECT @@session.auto_increment_increment;
+------------------------------------+
| @@session.auto_increment_increment |
+------------------------------------+
| |
+------------------------------------+
1 row in set (0.00 sec)
mysql> create database scaling_nomig;
Query OK, 0 rows affected (0.01 sec)
mysql> use scaling_nomig
Database changed
mysql> ADD RESOURCE ds_2 (
->
URL="jdbc:mysql://127.0.0.1:3306/migration_ds_10?serverTimezone=UTC&useSSL=false",
-> USER="root",
PASSWORD="root",
PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
), ds_3 (
URL="jdbc:mysql://127.0.0.1:3306/migration_ds_11?serverTimezone=UTC&useSSL=false",
USER="root",
PASSWORD="root",
PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
), ds_4 (
URL="jdbc:mysql://127.0.0.1:3306/migration_ds_12?serverTimezone=UTC&useSSL=false",
USER="root",
PASSWORD="root",
PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
); USER="root",
-> PASSWORD="root",
->
PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
-> ), ds_3 (
->
URL="jdbc:mysql://127.0.0.1:3306/migration_ds_11?serverTimezone=UTC&useSSL=false",
-> USER="root",
-> PASSWORD="root",
->
PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
-> ), ds_4 (
->
URL="jdbc:mysql://127.0.0.1:3306/migration_ds_12?serverTimezone=UTC&useSSL=false",
-> USER="root",
-> PASSWORD="root",
->
PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
-> );
Query OK, 0 rows affected (1.37 sec)
mysql> CREATE SHARDING TABLE RULE t_order(
-> RESOURCES(ds_2,ds_3,ds_4),
-> SHARDING_COLUMN=order_id,
-> TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="6")),
-> KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
-> );
Query OK, 0 rows affected (0.50 sec)
mysql> SELECT @@session.auto_increment_increment;
+------------------------------------+
| @@session.auto_increment_increment |
+------------------------------------+
| 1 |
+------------------------------------+
1 row in set (0.02 sec)
mysql> use sharding_db
Database changed
mysql> SELECT @@session.auto_increment_increment;
ERROR 11003 (42000): Rule does not exist
```
### Example codes for reproduce this issue (such as a github link).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]