Issue 1:
For English only, other languages we will close it directly.

Please answer these questions before submitting your issue. Thanks!

Before submit a new issue, please check existed issue first, to make sure your issue is not a duplicated one.

Which version of Sharding-Sphere do you using?

3.0.0.M3

Which project do you using? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

RoundRobinMasterSlaveLoadBalance always be OK

Actual behavior

after roundrobin Integer.MAX_VALUE times, will throw an ArrayIndexOutOfBoundsException.

Reason analyze

the AtomicInteger's getAndIncrement() may produce an negative numbers.

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc

For bug report, please MUST provide the reproduce example codes (such as a github link).

Issue 2:
version:lastest

config:

server.yaml:

rule:

- !TRANSACTION

defaultType: XA

providerType: Atomikos

I have two logical databases, sharding_db and sharding_db2;

sharding_db => actual databases ds_0, ds_1

sharding_db2 => actual databases ds_0, ds_1

sharding_sames as sharding_db2

connection2:

mysql> use sharding_db;

Database changed

mysql> begin;

Query OK, 0 rows affected (0.01 sec)

mysql> Insert into tbl_db_migrate_record(id, msg3, msg, record) values (146, '146', 'test', '[1,2,3]'),(139, '139', 'test', '[1,2,3]');

**### ？？？？ ERROR 1997 (C1997): Runtime exception: [null]？？？？**

connection1:

mysql> use sharding_db2; Reading table information for completion of table and column names

Database changed

mysql> begin; Query OK, 0 rows affected (0.06 sec)

mysql> Insert into tbl_db_migrate_record(id, msg3, msg, record) values (146, '146', 'test', '[1,2,3]'),(139, '139', 'test', '[1,2,3]');
ERROR 1062 (23000): Duplicate entry '146' for key 'PRIMARY'
mysql> rollback;
Query OK, 0 rows affected (0.21 sec)

Connect1 execute first

[ERROR] 2022-05-09 17:29:42.689 [Connection-2-ThreadExecutor] o.a.s.p.f.c.CommandExecutorTask - Exception occur:

java.lang.NullPointerException: null

at org.apache.shardingsphere.transaction.xa.XAShardingSphereTransactionManager.getConnection(XAShardingSphereTransactionManager.java:80)

at org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.createConnection(JDBCBackendDataSource.java:114)

at org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:81)

at org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:55)

at org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.createNewConnections(JDBCBackendConnection.java:101)

at org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.getConnections(JDBCBackendConnection.java:91)

at org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine.group(DriverExecutionPrepareEngine.java:88)

at org.apache.shardingsphere.infra.executor.sql.prepare.AbstractExecutionPrepareEngine.prepare(AbstractExecutionPrepareEngine.java:68)

at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.useDriverToExecute(ProxySQLExecutor.java:158)

at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:125)

at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:119)

at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:144)

at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:74)

at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:56)

at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:97)

at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:107)

at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:77)

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)