<p dir="auto">For English only, other languages we will close it directly.</p>
<p dir="auto">Please answer these questions before submitting your issue. Thanks!</p>
<p dir="auto">Before submit a new issue, please check existed issue first, to make sure your issue is not a duplicated one.</p>
<h3 dir="auto">Which version of Sharding-Sphere do you using?</h3>
<p dir="auto">3.0.0.M3</p>
<h3 dir="auto">Which project do you using? Sharding-JDBC or Sharding-Proxy?</h3>
<p dir="auto">Sharding-JDBC</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">RoundRobinMasterSlaveLoadBalance always be OK</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">after roundrobin Integer.MAX_VALUE times,  will  throw an ArrayIndexOutOfBoundsException.</p>
<h3 dir="auto">Reason analyze</h3>
<p dir="auto">the AtomicInteger's getAndIncrement() may produce an negative numbers.</p>
<h3 dir="auto">Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc</h3>
<h3 dir="auto">For bug report, please <em>MUST</em> provide the reproduce example codes (such as a github link).</h3>
<p dir="auto">version:lastest</p>
<p dir="auto">config:<br>
server.yaml:<br>
rule:<br>
- !TRANSACTION<br>
defaultType: XA<br>
providerType: Atomikos<br>
I have two logical databases,  sharding_db and sharding_db2;<br>
sharding_db =&gt; actual databases   ds_0, ds_1<br>
sharding_db2 =&gt; actual databases   ds_0, ds_1<br>
sharding_sames as sharding_db2</p>
<p dir="auto">connection2:<br>
mysql&gt; use sharding_db;<br>
Database changed<br>
mysql&gt; begin;<br>
Query OK, 0 rows affected (0.01 sec)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="      mysql&gt; 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]？？？？**"><pre class="notranslate"><code class="notranslate">      mysql&gt; 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]？？？？**
</code></pre></div>
<p dir="auto">connection1:<br>
mysql&gt; use sharding_db2;                                                        Reading table information for completion of table and column names<br>
Database changed<br>
mysql&gt; begin;                                                                   Query OK, 0 rows affected (0.06 sec)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="      mysql&gt; 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&gt; rollback;
      Query OK, 0 rows affected (0.21 sec)"><pre class="notranslate"><code class="notranslate">      mysql&gt; 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&gt; rollback;
      Query OK, 0 rows affected (0.21 sec)
</code></pre></div>
<p dir="auto">Connect1 execute first</p>
<p dir="auto">[ERROR] 2022-05-09 17:29:42.689 [Connection-2-ThreadExecutor] o.a.s.p.f.c.CommandExecutorTask - Exception occur:<br>
java.lang.NullPointerException: null<br>
at org.apache.shardingsphere.transaction.xa.XAShardingSphereTransactionManager.getConnection(XAShardingSphereTransactionManager.java:80)<br>
at org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.createConnection(JDBCBackendDataSource.java:114)<br>
at org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:81)<br>
at org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:55)<br>
at org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.createNewConnections(JDBCBackendConnection.java:101)<br>
at org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.getConnections(JDBCBackendConnection.java:91)<br>
at org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine.group(DriverExecutionPrepareEngine.java:88)<br>
at org.apache.shardingsphere.infra.executor.sql.prepare.AbstractExecutionPrepareEngine.prepare(AbstractExecutionPrepareEngine.java:68)<br>
at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.useDriverToExecute(ProxySQLExecutor.java:158)<br>
at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:125)<br>
at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:119)<br>
at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:144)<br>
at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:74)<br>
at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:56)<br>
at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:97)<br>
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:107)<br>
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:77)<br>
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)<br>
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)<br>
at java.lang.Thread.run(Thread.java:748)</p>