NSAmelchev commented on code in PR #12271:
URL: https://github.com/apache/ignite/pull/12271#discussion_r2426614543
##########
modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/internal/RoundRobinConnectionPolicy.java:
##########
@@ -17,24 +17,32 @@
package org.apache.ignite.spi.communication.tcp.internal;
-import org.apache.ignite.internal.util.typedef.internal.U;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* Round robin connection policy.
*/
public class RoundRobinConnectionPolicy implements ConnectionPolicy {
- /** Config. */
- private final TcpCommunicationConfiguration cfg;
+ /** Maximal connections number. */
+ private final int cnt;
+
+ /** */
+ private final AtomicInteger counter = new AtomicInteger();
/**
- * @param cfg Config.
+ * @param cnt Maximal connections number.
*/
- public RoundRobinConnectionPolicy(TcpCommunicationConfiguration cfg) {
- this.cfg = cfg;
+ public RoundRobinConnectionPolicy(int cnt) {
+ this.cnt = cnt;
}
/** {@inheritDoc} */
@Override public int connectionIndex() {
- return (int)(U.safeAbs(Thread.currentThread().getId()) %
cfg.connectionsPerNode());
+ int idx = counter.getAndIncrement() % cnt;
+
+ if (idx < 0)
+ idx += cnt;
Review Comment:
Can be negative.
--
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]