You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2019/03/21 10:20:51 UTC

[ignite] branch master updated: IGNITE-11471: JDBC Thin Driver: Randomize the first server address to connect to. This closes #6260.

This is an automated email from the ASF dual-hosted git repository.

vozerov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new c69ff4a  IGNITE-11471: JDBC Thin Driver: Randomize the first server address to connect to. This closes #6260.
c69ff4a is described below

commit c69ff4ae96c412c31e29024a0ade37652e028bef
Author: Igor Belyakov <ig...@gmail.com>
AuthorDate: Thu Mar 21 13:20:38 2019 +0300

    IGNITE-11471: JDBC Thin Driver: Randomize the first server address to connect to. This closes #6260.
---
 .../java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java    | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java
index 2b8a0af..35f11f3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java
@@ -28,6 +28,7 @@ import java.net.UnknownHostException;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Random;
 import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.query.QueryCancelledException;
@@ -56,6 +57,7 @@ import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteProductVersion;
 
+import static java.lang.Math.abs;
 import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.nullableBooleanToByte;
 
 /**
@@ -105,7 +107,7 @@ public class JdbcThinTcpIo {
     private static final int QUERY_CLOSE_MSG_SIZE = 9;
 
     /** Random. */
-    private static final AtomicLong IDX_GEN = new AtomicLong();
+    private static final AtomicLong IDX_GEN = new AtomicLong(new Random(U.currentTimeMillis()).nextLong());
 
     /** Connection properties. */
     private final ConnectionProperties connProps;
@@ -736,7 +738,7 @@ public class JdbcThinTcpIo {
         else {
             long nextIdx = IDX_GEN.getAndIncrement();
 
-            return (int)(nextIdx % len);
+            return (int)(abs(nextIdx) % len);
         }
     }