Vladsz83 commented on code in PR #12271:
URL: https://github.com/apache/ignite/pull/12271#discussion_r2431708352
##########
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:
Shouldn't be. I tested with
`private final AtomicInteger counter = new AtomicInteger(Integer.MAX_VALUE -
1);`
check
` % cnt`
It keeps theranges within `cnt`. And we do `+= cnt`. That turns a limited
negative value to 0+.
--
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]