JDBC Thin Driver: Randomize the first server address to connect to. This closes
@@ -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);
}
}
